Skip to content

Commit

Permalink
adds otel instrumn to customer svc
Browse files Browse the repository at this point in the history
Signed-off-by: Afzal Ansari <[email protected]>
  • Loading branch information
afzal442 committed Jul 2, 2023
1 parent 050ba81 commit 3fc922a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions examples/hotrod/services/customer/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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
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),
logger.With(zap.String("component", "mysql")),
),
}
Expand Down

0 comments on commit 3fc922a

Please sign in to comment.