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

Replace Jaeger SDK with OTEL SDK + OT Bridge #4574

Merged
merged 37 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
29a75e9
adds OTLP to jtracer
afzal442 Jul 7, 2023
9dbdbe0
replace ot with otlp
afzal442 Jul 7, 2023
f739427
made singleton otel tracer
afzal442 Jul 8, 2023
d4ce5cf
subjugate initialise method to support both tracer
afzal442 Jul 9, 2023
642d772
adds shudown method to tp
afzal442 Jul 9, 2023
8425410
creates tracer in the parent method
afzal442 Jul 9, 2023
6bcab4b
transform gRPC OT to OTEL
afzalbin64 Jul 11, 2023
ce29456
update http_handler test to support OTEL sdktrace
afzalbin64 Jul 12, 2023
d429861
updates jaeger tracer to shutdown in the main call
afzal442 Jul 13, 2023
d705dad
adds gRPC server conn
afzal442 Jul 13, 2023
29824ce
adds logger to jtracer and adjsted the tp.shutdown
afzal442 Jul 13, 2023
2018857
adds Close method to jtracer pkg
afzal442 Jul 13, 2023
b54e872
enscapulate err field in jtracer
afzal442 Jul 14, 2023
fd6d707
reform tracer in cmd app
afzal442 Jul 14, 2023
b01349e
modifies jtracer in cmd/app
afzal442 Jul 14, 2023
9447bcf
moves the tracer to main
afzal442 Jul 15, 2023
68ec355
undo reader file changes
afzal442 Jul 15, 2023
a2eb44a
reformats the jtracer pkg
afzal442 Jul 15, 2023
9b2be20
modifies svc name
afzal442 Jul 17, 2023
9cb1de5
Merge remote-tracking branch 'upstream/main' into add-otel-tp-jtracer
afzal442 Jul 17, 2023
2e03743
adds middleware for tracer response
afzal442 Jul 17, 2023
056b81d
adds trace-id url
afzal442 Jul 17, 2023
7e157eb
reverts prob value
afzal442 Jul 17, 2023
8e96af8
minor modification around pointers and versions
afzal442 Jul 18, 2023
88d5f25
pass OTEL tracer into the tracer method
afzal442 Jul 19, 2023
55918b4
excludes pkg from testing
afzal442 Jul 19, 2023
f26e1b2
rmvs jtracer_test file
afzal442 Jul 20, 2023
0eba87a
modifies .nocover
afzal442 Jul 20, 2023
3600c09
makes minor modification around *jtracer pointer
afzal442 Jul 20, 2023
7f81f62
updates pointer receivers for jtracer
afzal442 Jul 20, 2023
eab6735
rmv pointer dereferrencing
afzal442 Jul 20, 2023
e419417
replces with jaeger-all-in-one
afzal442 Jul 20, 2023
22fb80a
updates the log err
afzal442 Jul 20, 2023
43e5032
updates logger to log err jaeger-query
afzal442 Jul 20, 2023
c64e90c
simplifies the traceRes obj
afzal442 Jul 20, 2023
c2960e3
adds defer to resp from Do()
afzal442 Jul 20, 2023
f905480
rmvs OT tracer
afzal442 Jul 20, 2023
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
4 changes: 2 additions & 2 deletions cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ func startQuery(
) *queryApp.Server {
spanReader = storageMetrics.NewReadMetricsDecorator(spanReader, baseFactory.Namespace(metrics.NSOptions{Name: "query"}))
qs := querysvc.NewQueryService(spanReader, depReader, *queryOpts)
jtracer := jtracer.OT(opentracing.GlobalTracer())
server, err := queryApp.NewServer(svc.Logger, qs, metricsQueryService, qOpts, tm, jtracer)
tracer := jtracer.JTracer{OT: opentracing.GlobalTracer()}
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
server, err := queryApp.NewServer(svc.Logger, qs, metricsQueryService, qOpts, tm, tracer)
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
svc.Logger.Fatal("Could not start jaeger-query service", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/grpc_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewGRPCHandler(queryService *querysvc.QueryService,
options.Logger = zap.NewNop()
}

if options.Tracer.OT == nil {
if options.Tracer.OTEL == nil {
options.Tracer = jtracer.NoOp()
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (handlerOptions) QueryLookbackDuration(queryLookbackDuration time.Duration)
// Tracer creates a HandlerOption that initializes OpenTracing tracer
func (handlerOptions) Tracer(tracer jtracer.JTracer) HandlerOption {
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
return func(apiHandler *APIHandler) {
apiHandler.tracer = tracer
apiHandler.tracer.OT = tracer.OT
}
}

Expand Down
20 changes: 13 additions & 7 deletions cmd/query/app/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import (
testHttp "github.com/stretchr/testify/http"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/uber/jaeger-client-go"
otbridge "go.opentelemetry.io/otel/bridge/opentracing"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -303,10 +305,14 @@ func TestGetTrace(t *testing.T) {
for _, tc := range testCases {
testCase := tc // capture loop var
t.Run(testCase.suffix, func(t *testing.T) {
reporter := jaeger.NewInMemoryReporter()
jaegerTracer, jaegerCloser := jaeger.NewTracer("test", jaeger.NewConstSampler(true), reporter)
jTracer := jtracer.OT(jaegerTracer)
defer jaegerCloser.Close()
exporter := tracetest.NewInMemoryExporter()
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSyncer(exporter),
sdktrace.WithSampler(sdktrace.AlwaysSample()),
)
// Use the bridgeTracer as OpenTracing tracer(otTrace).
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
otTracer, _ := otbridge.NewTracerPair(tracerProvider.Tracer(""))
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
jTracer := jtracer.JTracer{OT: otTracer}
afzal442 marked this conversation as resolved.
Show resolved Hide resolved

ts := initializeTestServer(HandlerOptions.Tracer(jTracer))
defer ts.server.Close()
Expand All @@ -319,8 +325,8 @@ func TestGetTrace(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, response.Errors, 0)

assert.Len(t, reporter.GetSpans(), 1, "HTTP request was traced and span reported")
assert.Equal(t, "/api/traces/{traceID}", reporter.GetSpans()[0].(*jaeger.Span).OperationName())
assert.Len(t, exporter.GetSpans(), 1, "HTTP request was traced and span reported")
assert.Equal(t, "/api/traces/{traceID}", exporter.GetSpans()[0].Name)

traces := extractTraces(t, &response)
assert.Len(t, traces[0].Spans, 2)
Expand Down
22 changes: 2 additions & 20 deletions cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ import (
"log"
"os"

"github.com/opentracing/opentracing-go"
"github.com/spf13/cobra"
"github.com/spf13/viper"
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
jaegerClientZapLog "github.com/uber/jaeger-client-go/log/zap"
_ "go.uber.org/automaxprocs"
"go.uber.org/zap"

Expand All @@ -34,7 +31,6 @@ import (
"github.com/jaegertracing/jaeger/cmd/query/app"
"github.com/jaegertracing/jaeger/cmd/query/app/querysvc"
"github.com/jaegertracing/jaeger/cmd/status"
"github.com/jaegertracing/jaeger/internal/metrics/jlibadapter"
"github.com/jaegertracing/jaeger/pkg/bearertoken"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/jtracer"
Expand Down Expand Up @@ -76,28 +72,14 @@ func main() {
metricsFactory := baseFactory.Namespace(metrics.NSOptions{Name: "query"})
version.NewInfoMetrics(metricsFactory)

traceCfg := &jaegerClientConfig.Configuration{
ServiceName: "jaeger-query",
Sampler: &jaegerClientConfig.SamplerConfig{
Type: "const",
Param: 1.0,
},
RPCMetrics: true,
}
traceCfg, err = traceCfg.FromEnv()
if err != nil {
logger.Fatal("Failed to read tracer configuration", zap.Error(err))
}
tracer, closer, err := traceCfg.NewTracer(
jaegerClientConfig.Metrics(jlibadapter.NewAdapter(svc.MetricsFactory)),
jaegerClientConfig.Logger(jaegerClientZapLog.NewLogger(logger)),
)
if err != nil {
logger.Fatal("Failed to initialize tracer", zap.Error(err))
}
defer closer.Close()
opentracing.SetGlobalTracer(tracer)
jtracer := jtracer.OT(tracer)

jtracer := jtracer.New()
queryOpts, err := new(app.QueryOptions).InitFromViper(v, logger)
if err != nil {
logger.Fatal("Failed to configure query service", zap.Error(err))
Expand Down
71 changes: 66 additions & 5 deletions pkg/jtracer/jtracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,77 @@

package jtracer

import "github.com/opentracing/opentracing-go"
import (
"context"
"log"
"sync"

"github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel"
otbridge "go.opentelemetry.io/otel/bridge/opentracing"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
"go.opentelemetry.io/otel/trace"
)

type JTracer struct {
OT opentracing.Tracer
OT opentracing.Tracer
OTEL trace.TracerProvider
}

func OT(t opentracing.Tracer) JTracer {
return JTracer{OT: t}
var once sync.Once

func New() JTracer {
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
opentracingTracer, otelTracerProvider := initBoth()
return JTracer{OT: opentracingTracer, OTEL: otelTracerProvider}
}

func NoOp() JTracer {
return JTracer{OT: opentracing.NoopTracer{}}
return JTracer{OT: opentracing.NoopTracer{}, OTEL: trace.NewNoopTracerProvider()}
}

// initBoth initializes OpenTelemetry SDK and uses OTel-OpenTracing Bridge
func initBoth() (opentracing.Tracer, trace.TracerProvider) {
opts := []otlptracehttp.Option{otlptracehttp.WithInsecure()}
traceExporter, err := otlptrace.New(
context.Background(),
otlptracehttp.NewClient(opts...),
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
log.Fatal("failed to create exporter: %w", err)
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
}

// Register the trace exporter with a TracerProvider, using a batch
// span processor to aggregate spans before export.
bsp := sdktrace.NewBatchSpanProcessor(traceExporter)
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSpanProcessor(bsp),
sdktrace.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("otlp"),
)),
)

once.Do(func() {
otel.SetTextMapPropagator(
propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
))
})

// Use the bridgeTracer as your OpenTracing tracer(otTrace).
otTracer, wrapperTracerProvider := otbridge.NewTracerPair(tracerProvider.Tracer(""))
afzal442 marked this conversation as resolved.
Show resolved Hide resolved

// Shutdown the tracerProvider to clean up resources
err = tracerProvider.Shutdown(context.Background())
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Fatal("failed to shutdown tracerProvider: ", err)
}

return otTracer, wrapperTracerProvider
}
16 changes: 1 addition & 15 deletions pkg/jtracer/jtracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,4 @@

package jtracer_test

import (
"testing"

"github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert"

"github.com/jaegertracing/jaeger/pkg/jtracer"
)

func TestOT(t *testing.T) {
mockTracer := opentracing.NoopTracer{}
jtracer := jtracer.OT(opentracing.NoopTracer{})

assert.Equal(t, mockTracer, jtracer.OT)
}
// TODO
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 18 additions & 14 deletions plugin/metrics/prometheus/metricsstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ import (
"time"
"unicode"

"github.com/opentracing/opentracing-go"
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
ottag "github.com/opentracing/opentracing-go/ext"
otlog "github.com/opentracing/opentracing-go/log"
"github.com/prometheus/client_golang/api"
promapi "github.com/prometheus/client_golang/api/prometheus/v1"
"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/pkg/bearertoken"
"github.com/jaegertracing/jaeger/pkg/jtracer"
"github.com/jaegertracing/jaeger/pkg/prometheus/config"
"github.com/jaegertracing/jaeger/plugin/metrics/prometheus/metricsstore/dbmodel"
"github.com/jaegertracing/jaeger/proto-gen/api_v2/metrics"
Expand All @@ -54,6 +55,7 @@ type (
latencyMetricName string
callsMetricName string
operationLabel string
tracer jtracer.JTracer
}

promQueryParams struct {
Expand Down Expand Up @@ -101,6 +103,7 @@ func NewMetricsReader(logger *zap.Logger, cfg config.Configuration) (*MetricsRea
callsMetricName: buildFullCallsMetricName(cfg),
latencyMetricName: buildFullLatencyMetricName(cfg),
operationLabel: operationLabel,
tracer: jtracer.New(),
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
}

logger.Info("Prometheus reader initialized", zap.String("addr", cfg.ServerURL))
Expand Down Expand Up @@ -224,8 +227,8 @@ func (m MetricsReader) executeQuery(ctx context.Context, p metricsQueryParams) (
}
promQuery := m.buildPromQuery(p)

span, ctx := startSpanForQuery(ctx, p.metricName, promQuery)
defer span.Finish()
ctx, span := startSpanForQuery(ctx, p.metricName, promQuery, m.tracer.OTEL)
defer span.End()

queryRange := promapi.Range{
Start: p.EndTime.Add(-1 * *p.Lookback),
Expand Down Expand Up @@ -287,17 +290,18 @@ func promqlDurationString(d *time.Duration) string {
return string(b)
}

func startSpanForQuery(ctx context.Context, metricName, query string) (opentracing.Span, context.Context) {
span, ctx := opentracing.StartSpanFromContext(ctx, metricName)
ottag.DBStatement.Set(span, query)
ottag.DBType.Set(span, "prometheus")
ottag.Component.Set(span, "promql")
return span, ctx
func startSpanForQuery(ctx context.Context, metricName, query string, tp trace.TracerProvider) (context.Context, trace.Span) {
ctx, span := tp.Tracer("prom-metrics-reader").Start(ctx, metricName)
span.SetAttributes(
attribute.Key(semconv.DBStatementKey).String(query),
attribute.Key("db.type").String("prometheus"),
attribute.Key("component").String("promql"),
)
return ctx, span
}

func logErrorToSpan(span opentracing.Span, err error) {
ottag.Error.Set(span, true)
span.LogFields(otlog.Error(err))
func logErrorToSpan(span trace.Span, err error) {
span.AddEvent(err.Error(), trace.WithAttributes(semconv.OTelStatusCodeError))
}

func getHTTPRoundTripper(c *config.Configuration, logger *zap.Logger) (rt http.RoundTripper, err error) {
Expand Down