From b0826a9504c12fb2c5682f5af6cd47d7a4b6fd0e Mon Sep 17 00:00:00 2001 From: James Ryans <46216691+james-ryans@users.noreply.github.com> Date: Thu, 19 Oct 2023 22:53:31 +0700 Subject: [PATCH] Add OTel resource detector to Jaeger components (#4864) ## Which problem is this PR solving? - Resolves #4534 - Continuation from #4844 ## Description of the changes - Add OTel resources to Jaeger components and tracegen tool. ## How was this change tested? - Tested manually in local image image ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: James Ryans Co-authored-by: Yuri Shkuro --- cmd/tracegen/main.go | 17 +++++++++++++---- pkg/jtracer/jtracer.go | 18 ++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/cmd/tracegen/main.go b/cmd/tracegen/main.go index 14799bf7544..f78fd70dbb6 100644 --- a/cmd/tracegen/main.go +++ b/cmd/tracegen/main.go @@ -82,12 +82,21 @@ func createTracers(cfg *tracegen.Config, logger *zap.Logger) ([]trace.Tracer, fu } logger.Sugar().Infof("using %s trace exporter for service %s", cfg.TraceExporter, svc) + res, err := resource.New( + context.Background(), + resource.WithSchemaURL(semconv.SchemaURL), + resource.WithAttributes(semconv.ServiceNameKey.String(svc)), + resource.WithTelemetrySDK(), + resource.WithHost(), + resource.WithOSType(), + ) + if err != nil { + logger.Sugar().Fatalf("resource creation failed: %s", err) + } + tp := sdktrace.NewTracerProvider( sdktrace.WithBatcher(exp, sdktrace.WithBlocking()), - sdktrace.WithResource(resource.NewWithAttributes( - semconv.SchemaURL, - semconv.ServiceNameKey.String(svc), - )), + sdktrace.WithResource(res), ) tracers = append(tracers, tp.Tracer(cfg.Service)) shutdown = append(shutdown, tp.Shutdown) diff --git a/pkg/jtracer/jtracer.go b/pkg/jtracer/jtracer.go index 2f75107cd44..cf58a9522cd 100644 --- a/pkg/jtracer/jtracer.go +++ b/pkg/jtracer/jtracer.go @@ -72,12 +72,22 @@ func initOTEL(ctx context.Context, svc string) (*sdktrace.TracerProvider, error) // Register the trace exporter with a TracerProvider, using a batch // span processor to aggregate spans before export. bsp := sdktrace.NewBatchSpanProcessor(traceExporter) + + res, err := resource.New( + ctx, + resource.WithSchemaURL(semconv.SchemaURL), + resource.WithAttributes(semconv.ServiceNameKey.String(svc)), + resource.WithTelemetrySDK(), + resource.WithHost(), + resource.WithOSType(), + ) + if err != nil { + return nil, err + } + tracerProvider := sdktrace.NewTracerProvider( sdktrace.WithSpanProcessor(bsp), - sdktrace.WithResource(resource.NewWithAttributes( - semconv.SchemaURL, - semconv.ServiceNameKey.String(svc), - )), + sdktrace.WithResource(res), ) once.Do(func() {