From 3fc922a2628d10e74d41ed132e6097bb8f97bbbd Mon Sep 17 00:00:00 2001 From: Afzal Ansari Date: Sun, 2 Jul 2023 11:19:45 +0000 Subject: [PATCH] adds otel instrumn to customer svc Signed-off-by: Afzal Ansari --- examples/hotrod/services/customer/database.go | 21 +++++++------------ examples/hotrod/services/customer/server.go | 2 +- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/examples/hotrod/services/customer/database.go b/examples/hotrod/services/customer/database.go index a89b01f1989..739285b570d 100644 --- a/examples/hotrod/services/customer/database.go +++ b/examples/hotrod/services/customer/database.go @@ -19,8 +19,8 @@ import ( "context" "errors" - "github.com/opentracing/opentracing-go" - tags "github.com/opentracing/opentracing-go/ext" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "github.com/jaegertracing/jaeger/examples/hotrod/pkg/delay" @@ -31,13 +31,13 @@ import ( // database simulates Customer repository implemented on top of an SQL database type database struct { - tracer opentracing.Tracer + tracer trace.Tracer logger log.Factory customers map[string]*Customer lock *tracing.Mutex } -func newDatabase(tracer opentracing.Tracer, logger log.Factory) *database { +func newDatabase(tracer trace.Tracer, logger log.Factory) *database { return &database{ tracer: tracer, logger: logger, @@ -73,15 +73,10 @@ func (d *database) Get(ctx context.Context, customerID string) (*Customer, error d.logger.For(ctx).Info("Loading customer", zap.String("customer_id", customerID)) // simulate opentracing instrumentation of an SQL query - if span := opentracing.SpanFromContext(ctx); span != nil { - span := d.tracer.StartSpan("SQL SELECT", opentracing.ChildOf(span.Context())) - tags.SpanKindRPCClient.Set(span) - tags.PeerService.Set(span, "mysql") - // #nosec - span.SetTag("sql.query", "SELECT * FROM customer WHERE customer_id="+customerID) - defer span.Finish() - ctx = opentracing.ContextWithSpan(ctx, span) - } + ctx, span := d.tracer.Start(ctx, "SQL SELECT", trace.WithSpanKind(trace.SpanKindClient)) + // #nosec + span.SetAttributes(attribute.Key("sql.query").String("SELECT * FROM customer WHERE customer_id=" + customerID)) + defer span.End() if !config.MySQLMutexDisabled { // simulate misconfigured connection pool that only gives one connection at a time diff --git a/examples/hotrod/services/customer/server.go b/examples/hotrod/services/customer/server.go index 7cbe0e6da4c..3143716e6f0 100644 --- a/examples/hotrod/services/customer/server.go +++ b/examples/hotrod/services/customer/server.go @@ -43,7 +43,7 @@ func NewServer(hostPort string, otelExporter string, metricsFactory metrics.Fact tracer: tracing.Init("customer", otelExporter, metricsFactory, logger), logger: logger, database: newDatabase( - tracing.Init("mysql", otelExporter, metricsFactory, logger), + tracing.InitOTEL("mysql", otelExporter, metricsFactory, logger), logger.With(zap.String("component", "mysql")), ), }