Skip to content

Commit

Permalink
[hotrod] Remove most references to OpenTracing (#4585)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Part of #3380

Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed Jul 16, 2023
1 parent fab0369 commit 7b6cd83
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 48 deletions.
6 changes: 3 additions & 3 deletions 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

Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions examples/hotrod/pkg/log/factory.go
Expand Up @@ -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
}
Expand Down
17 changes: 0 additions & 17 deletions examples/hotrod/pkg/tracing/baggage.go
Expand Up @@ -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()
Expand Down
22 changes: 2 additions & 20 deletions examples/hotrod/pkg/tracing/init.go
Expand Up @@ -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"
Expand All @@ -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(
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/hotrod/services/customer/database.go
Expand Up @@ -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()

Expand Down

0 comments on commit 7b6cd83

Please sign in to comment.