From e2067eff42c1f14c55a28c3da42d609c551f3c9d Mon Sep 17 00:00:00 2001 From: Alok Kumar Singh <62210712+akstron@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:06:40 +0530 Subject: [PATCH] Respect environment variables when creating internal tracer (#6179) ## Which problem is this PR solving? Resolves #6122 ## Description of the changes - The changes include using the `otlptracegrpc.WithInsecure()` based on `OTEL_EXPORTER_OTLP_ENDPOINT` and `OTEL_EXPORTER_OTLP_INSECURE` env variables. ## 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 - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Alok Kumar Singh --- pkg/jtracer/jtracer.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/jtracer/jtracer.go b/pkg/jtracer/jtracer.go index 6e7509a50e8..25523f8d3f1 100644 --- a/pkg/jtracer/jtracer.go +++ b/pkg/jtracer/jtracer.go @@ -5,6 +5,8 @@ package jtracer import ( "context" + "os" + "strings" "sync" "go.opentelemetry.io/otel" @@ -109,9 +111,17 @@ func otelResource(ctx context.Context, svc string) (*resource.Resource, error) { ) } +func defaultGRPCOptions() []otlptracegrpc.Option { + var options []otlptracegrpc.Option + if !(strings.HasPrefix(os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"), "https://") || strings.ToLower(os.Getenv("OTEL_EXPORTER_OTLP_INSECURE")) == "false") { + options = append(options, otlptracegrpc.WithInsecure()) + } + return options +} + func otelExporter(ctx context.Context) (sdktrace.SpanExporter, error) { client := otlptracegrpc.NewClient( - otlptracegrpc.WithInsecure(), + defaultGRPCOptions()..., ) return otlptrace.New(ctx, client) }