Enabling tracing in Jaeger

Note

The article is being updated.

Below are examples of the code enabling Jaeger tracing in different YDB SDKs

Go

  1. package main
  2. import (
  3. "context"
  4. "time"
  5. "github.com/opentracing/opentracing-go"
  6. jaegerConfig "github.com/uber/jaeger-client-go/config"
  7. "github.com/ydb-platform/ydb-go-sdk/v3"
  8. "github.com/ydb-platform/ydb-go-sdk/v3/trace"
  9. tracing "github.com/ydb-platform/ydb-go-sdk-opentracing"
  10. )
  11. const (
  12. tracerURL = "localhost:5775"
  13. serviceName = "ydb-go-sdk"
  14. )
  15. func main() {
  16. tracer, closer, err := jaegerConfig.Configuration{
  17. ServiceName: serviceName,
  18. Sampler: &jaegerConfig.SamplerConfig{
  19. Type: "const",
  20. Param: 1,
  21. },
  22. Reporter: &jaegerConfig.ReporterConfig{
  23. LogSpans: true,
  24. BufferFlushInterval: 1 * time.Second,
  25. LocalAgentHostPort: tracerURL,
  26. },
  27. }.NewTracer()
  28. if err != nil {
  29. panic(err)
  30. }
  31. defer closer.Close()
  32. // set global tracer of this application
  33. opentracing.SetGlobalTracer(tracer)
  34. span, ctx := opentracing.StartSpanFromContext(context.Background(), "client")
  35. defer span.Finish()
  36. db, err := ydb.Open(
  37. ctx,
  38. os.Getenv("YDB_CONNECTION_STRING"),
  39. tracing.WithTraces(
  40. tracing.WithDetails(trace.DetailsAll),
  41. ),
  42. ydb.WithTraceTable(tracing.Table(
  43. tracing.WithDetails(trace.DetailsAll),
  44. )),
  45. )
  46. if err != nil {
  47. panic(err)
  48. }
  49. defer func() {
  50. _ = db.Close(ctx)
  51. }()
  52. }

Enable tracing in Jaeger - 图1