Skip to content

Commit

Permalink
Respect environment variables when creating internal tracer (#6179)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
akstron authored Nov 11, 2024
1 parent c3fced4 commit e2067ef
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/jtracer/jtracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package jtracer

import (
"context"
"os"
"strings"
"sync"

"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit e2067ef

Please sign in to comment.