gorm-opentracing [migrated]
opentracing support for gorm2.
Features
- Record
SQL
in span
logs.
- Record
Result
in span
logs.
- Record
Table
in span
tags.
- Record
Error
in span
tags and logs.
- Register
Create
Query
Delete
Update
Row
Raw
tracing callbacks.
Get Started
I assume that you already have an opentracing Tracer client started in your project.
func main() {
var db *gorm.DB
db.Use(gormopentracing.New())
}
Otherwise, you need to deploy distributed tracing server(jaeger, zipkin for example), then
you need to boot tracer client in yours project and set tracer to opentracing.
import (
"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/config"
jaegerlog "github.com/uber/jaeger-client-go/log"
)
func bootTracerBasedJaeger() {
// jaeger tracer configuration
cfg := &config.Configuration{
Sampler: &config.SamplerConfig{
Type: jaeger.SamplerTypeConst,
Param: 1,
},
ServiceName: "gormopentracing",
Reporter: &config.ReporterConfig{
LogSpans: true,
//LocalAgentHostPort: "127.0.0.1:6381",
BufferFlushInterval: 100 * time.Millisecond,
CollectorEndpoint: "http://127.0.0.1:14268/api/traces",
},
}
// jaeger tracer client
tracer, _, err := cfg.NewTracer(
config.Logger(jaegerlog.StdLogger),
config.ZipkinSharedRPCSpan(true),
)
if err != nil {
log.Printf("failed to use jaeger tracer plugin, got error %v", err)
os.Exit(1)
}
// set into opentracing
opentracing.SetGlobalTracer(tracer)
}
Plugin options
// WithLogResult log result into span log, default: disabled.
func WithLogResult(logResult bool)
Snapshots