diff --git a/examples/hotrod/README.md b/examples/hotrod/README.md index 6982c75162a..5719260bb81 100644 --- a/examples/hotrod/README.md +++ b/examples/hotrod/README.md @@ -1,12 +1,12 @@ # Hot R.O.D. - Rides on Demand This is a demo application that consists of several microservices and illustrates -the use of the OpenTracing API. It can be run standalone, but requires Jaeger backend +the use of the OpenTelemetry API & SDK. It can be run standalone, but requires Jaeger backend to view the traces. A tutorial / walkthrough is available: * as a blog post [Take OpenTracing for a HotROD ride][hotrod-tutorial], * as a video [OpenShift Commons Briefing: Distributed Tracing with Jaeger & Prometheus on Kubernetes][hotrod-openshift]. -As of Jaeger v1.42.0 this application was upgraded to use OpenTelemetry SDK for traces. +As of Jaeger v1.42.0 this application was upgraded to use the OpenTelemetry SDK for traces. ## Features @@ -17,7 +17,7 @@ As of Jaeger v1.42.0 this application was upgraded to use OpenTelemetry SDK for * Use baggage propagation to * Diagnose inter-request contention (queueing) * Attribute time spent in a service -* Use open source libraries with OpenTracing integration to get vendor-neutral instrumentation for free +* Use [opentelemetry-go-contrib](https://github.com/open-telemetry/opentelemetry-go-contrib) open source libraries to instrument HTTP and gRPC requests with minimal code changes ## Running diff --git a/examples/hotrod/pkg/log/factory.go b/examples/hotrod/pkg/log/factory.go index 3da19424c52..7f777329766 100644 --- a/examples/hotrod/pkg/log/factory.go +++ b/examples/hotrod/pkg/log/factory.go @@ -40,14 +40,14 @@ func (b Factory) Bg() Logger { } // For returns a context-aware Logger. If the context -// contains an OpenTracing span, all logging calls are also +// contains a span, all logging calls are also // echo-ed into the span. func (b Factory) For(ctx context.Context) Logger { - if otelSpan := trace.SpanFromContext(ctx); otelSpan != nil { - logger := spanLogger{span: otelSpan, logger: b.logger} + if span := trace.SpanFromContext(ctx); span != nil { + logger := spanLogger{span: span, logger: b.logger} logger.spanFields = []zapcore.Field{ - zap.String("trace_id", otelSpan.SpanContext().TraceID().String()), - zap.String("span_id", otelSpan.SpanContext().SpanID().String()), + zap.String("trace_id", span.SpanContext().TraceID().String()), + zap.String("span_id", span.SpanContext().SpanID().String()), } return logger } diff --git a/examples/hotrod/pkg/tracing/baggage.go b/examples/hotrod/pkg/tracing/baggage.go index b1e13c059a4..416a33f9157 100644 --- a/examples/hotrod/pkg/tracing/baggage.go +++ b/examples/hotrod/pkg/tracing/baggage.go @@ -17,27 +17,10 @@ package tracing import ( "context" - "github.com/opentracing/opentracing-go" "go.opentelemetry.io/otel/baggage" ) func BaggageItem(ctx context.Context, key string) string { - val := opentracingBaggageItem(ctx, key) - if val != "" { - return val - } - return otelBaggageItem(ctx, key) -} - -func opentracingBaggageItem(ctx context.Context, key string) string { - span := opentracing.SpanFromContext(ctx) - if span == nil { - return "" - } - return span.BaggageItem(key) -} - -func otelBaggageItem(ctx context.Context, key string) string { b := baggage.FromContext(ctx) m := b.Member(key) return m.Value() diff --git a/examples/hotrod/pkg/tracing/init.go b/examples/hotrod/pkg/tracing/init.go index 82333540273..8ef811d46c6 100644 --- a/examples/hotrod/pkg/tracing/init.go +++ b/examples/hotrod/pkg/tracing/init.go @@ -23,9 +23,7 @@ import ( "sync" "time" - "github.com/opentracing/opentracing-go" "go.opentelemetry.io/otel" - otbridge "go.opentelemetry.io/otel/bridge/opentracing" "go.opentelemetry.io/otel/exporters/jaeger" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" @@ -46,22 +44,6 @@ var once sync.Once // InitOTEL initializes OpenTelemetry SDK. func InitOTEL(serviceName string, exporterType string, metricsFactory metrics.Factory, logger log.Factory) trace.TracerProvider { - _, oteltp := initBOTH(serviceName, exporterType, metricsFactory, logger) - - logger.Bg().Debug("Created OTEL tracer", zap.String("service-name", serviceName)) - return oteltp -} - -// Init returns OTel-OpenTracing Bridge. -func Init(serviceName string, exporterType string, metricsFactory metrics.Factory, logger log.Factory) opentracing.Tracer { - otTracer, _ := initBOTH(serviceName, exporterType, metricsFactory, logger) - - logger.Bg().Debug("Created OTEL->OT bridge", zap.String("service-name", serviceName)) - return otTracer -} - -// initBOTH initializes OpenTelemetry SDK and uses OTel-OpenTracing Bridge -func initBOTH(serviceName string, exporterType string, metricsFactory metrics.Factory, logger log.Factory) (opentracing.Tracer, trace.TracerProvider) { once.Do(func() { otel.SetTextMapPropagator( propagation.NewCompositeTextMapPropagator( @@ -86,8 +68,8 @@ func initBOTH(serviceName string, exporterType string, metricsFactory metrics.Fa semconv.ServiceNameKey.String(serviceName), )), ) - otTracer, _ := otbridge.NewTracerPair(tp.Tracer(serviceName)) - return otTracer, tp + logger.Bg().Debug("Created OTEL tracer", zap.String("service-name", serviceName)) + return tp } // withSecure instructs the client to use HTTPS scheme, instead of hotrod's desired default HTTP diff --git a/examples/hotrod/services/customer/database.go b/examples/hotrod/services/customer/database.go index f20e1a59fa7..984eeff79ae 100644 --- a/examples/hotrod/services/customer/database.go +++ b/examples/hotrod/services/customer/database.go @@ -75,12 +75,12 @@ func newDatabase(tracer trace.Tracer, logger log.Factory) *database { func (d *database) Get(ctx context.Context, customerID int) (*Customer, error) { d.logger.For(ctx).Info("Loading customer", zap.Int("customer_id", customerID)) - // simulate opentracing instrumentation of an SQL query ctx, span := d.tracer.Start(ctx, "SQL SELECT", trace.WithSpanKind(trace.SpanKindClient)) - // #nosec span.SetAttributes( semconv.PeerServiceKey.String("mysql"), - attribute.Key("sql.query").String(fmt.Sprintf("SELECT * FROM customer WHERE customer_id=%d", customerID)), + attribute. + Key("sql.query"). + String(fmt.Sprintf("SELECT * FROM customer WHERE customer_id=%d", customerID)), ) defer span.End()