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 3 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
sbin64 Jul 11, 2023
ce29456
update http_handler test to support OTEL sdktrace
sbin64 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
3 changes: 2 additions & 1 deletion cmd/all-in-one/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/spf13/viper"
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
jaegerClientZapLog "github.com/uber/jaeger-client-go/log/zap"
"go.opentelemetry.io/otel/trace"
_ "go.uber.org/automaxprocs"
"go.uber.org/zap"

Expand Down Expand Up @@ -274,7 +275,7 @@ 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())
jtracer := jtracer.New(opentracing.GlobalTracer(), trace.NewNoopTracerProvider())
server, err := queryApp.NewServer(svc.Logger, qs, metricsQueryService, qOpts, tm, jtracer)
if err != nil {
svc.Logger.Fatal("Could not start jaeger-query service", zap.Error(err))
Expand Down
3 changes: 2 additions & 1 deletion cmd/query/app/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/uber/jaeger-client-go"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -305,7 +306,7 @@ func TestGetTrace(t *testing.T) {
t.Run(testCase.suffix, func(t *testing.T) {
reporter := jaeger.NewInMemoryReporter()
jaegerTracer, jaegerCloser := jaeger.NewTracer("test", jaeger.NewConstSampler(true), reporter)
jTracer := jtracer.OT(jaegerTracer)
jTracer := jtracer.New(jaegerTracer, trace.NewNoopTracerProvider())
defer jaegerCloser.Close()

ts := initializeTestServer(HandlerOptions.Tracer(jTracer))
Expand Down
3 changes: 2 additions & 1 deletion cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/spf13/viper"
jaegerClientConfig "github.com/uber/jaeger-client-go/config"
jaegerClientZapLog "github.com/uber/jaeger-client-go/log/zap"
"go.opentelemetry.io/otel/trace"
_ "go.uber.org/automaxprocs"
"go.uber.org/zap"

Expand Down Expand Up @@ -97,7 +98,7 @@ func main() {
}
defer closer.Close()
opentracing.SetGlobalTracer(tracer)
jtracer := jtracer.OT(tracer)
jtracer := jtracer.New(tracer, trace.NewNoopTracerProvider())
queryOpts, err := new(app.QueryOptions).InitFromViper(v, logger)
if err != nil {
logger.Fatal("Failed to configure query service", zap.Error(err))
Expand Down
59 changes: 54 additions & 5 deletions pkg/jtracer/jtracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,65 @@

package jtracer

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

"github.com/opentracing/opentracing-go"
"go.opentelemetry.io/otel"
"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 globalTracerProvider trace.TracerProvider
afzal442 marked this conversation as resolved.
Show resolved Hide resolved

func New(t opentracing.Tracer, tp trace.TracerProvider) JTracer {
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
return JTracer{OT: t, OTEL: tp}
}

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

func init() {
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)
globalTracerProvider = sdktrace.NewTracerProvider(
sdktrace.WithSpanProcessor(bsp),
sdktrace.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("otlp"),
)),
)

otel.SetTracerProvider(globalTracerProvider)
otel.SetTextMapPropagator(
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
))
}

func GetTracerProvider() trace.TracerProvider {
return globalTracerProvider
}
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 Down Expand Up @@ -224,8 +225,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)
defer span.End()

queryRange := promapi.Range{
Start: p.EndTime.Add(-1 * *p.Lookback),
Expand Down Expand Up @@ -287,17 +288,20 @@ 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) (context.Context, trace.Span) {
tp := jtracer.GetTracerProvider()
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.SetStatus(codes.Error, semconv.OTelStatusCodeError.Value.AsString())
span.AddEvent(err.Error(), trace.WithAttributes(semconv.OTelStatusCodeError))
}

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