Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotROD] Add OTEL instrumentation to customer svc #4559

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions examples/hotrod/services/customer/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
"context"
"errors"

"github.com/opentracing/opentracing-go"
tags "github.com/opentracing/opentracing-go/ext"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.20.0"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/examples/hotrod/pkg/delay"
Expand All @@ -31,13 +32,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,
Expand Down Expand Up @@ -73,15 +74,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")
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
// #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(semconv.PeerServiceKey.String("mysql"), 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
Expand Down
2 changes: 1 addition & 1 deletion examples/hotrod/services/customer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).Tracer("mysql"),
logger.With(zap.String("component", "mysql")),
),
}
Expand Down