Skip to content

Commit

Permalink
Add OTel resource detector to Jaeger components (#4864)
Browse files Browse the repository at this point in the history
## 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
<img width="1440" alt="image"
src="https://github.com/jaegertracing/jaeger/assets/46216691/28bfb121-0c5a-42b1-a3e3-2c5915c90b17">
<img width="1440" alt="image"
src="https://github.com/jaegertracing/jaeger/assets/46216691/3b6d993a-2fac-4c65-97c2-e3dca581a3a1">


## 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 <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
  • Loading branch information
james-ryans and yurishkuro authored Oct 19, 2023
1 parent bf4e78a commit b0826a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
17 changes: 13 additions & 4 deletions cmd/tracegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 14 additions & 4 deletions pkg/jtracer/jtracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b0826a9

Please sign in to comment.