Skip to content

Commit

Permalink
Merge pull request #10 from go-coldbrew/nr-opentel
Browse files Browse the repository at this point in the history
updating open telemetry
  • Loading branch information
ankurs authored Sep 10, 2022
2 parents 414abd0 + ca73ee3 commit 61ee8bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *cb) processConfig() {
grpc_prometheus.EnableHandlingTimeHistogram()
}
if c.config.NewRelicOpentelemetry {
setupNROpenTelemetry(c.config.AppName, c.config.NewRelicLicenseKey)
setupNROpenTelemetry(c.config.AppName, c.config.NewRelicLicenseKey, c.config.ReleaseName)
}
}

Expand Down
27 changes: 16 additions & 11 deletions initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
"google.golang.org/grpc/credentials"
)

func setupNewRelic(serviceName, apiKey string, tracing bool) {
Expand Down Expand Up @@ -105,19 +104,17 @@ func setupJaeger(serviceName string) io.Closer {
return closer
}

func setupNROpenTelemetry(serviceName string, license string) {
func setupNROpenTelemetry(serviceName, license, version string) {
if serviceName == "" || license == "" {
log.Error(context.Background(), "msg", "not initializing NR opentelemetry tracing")
log.Info(context.Background(), "msg", "not initializing NR opentelemetry tracing")
return
}
var headers = map[string]string{
"api-key": license,
}

var clientOpts = []otlptracegrpc.Option{
otlptracegrpc.WithEndpoint("https://otlp.nr-data.net:4317"),
otlptracegrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, "")),
otlptracegrpc.WithReconnectionPeriod(1 * time.Second),
otlptracegrpc.WithTimeout(3 * time.Second),
otlptracegrpc.WithEndpoint("otlp.nr-data.net:4317"),
otlptracegrpc.WithHeaders(headers),
otlptracegrpc.WithCompressor("gzip"),
}
Expand All @@ -128,29 +125,37 @@ func setupNROpenTelemetry(serviceName string, license string) {
return
}

r, err := resource.New(context.Background(),
d := resource.Default()
res, err := resource.New(context.Background(),
resource.WithAttributes(
// the service name used to display traces in backends
semconv.ServiceNameKey.String(serviceName),
semconv.ServiceVersionKey.String(version),
),
resource.WithFromEnv(),
)
if err != nil {
log.Error(context.Background(), "msg", "creating OTLP resource", "err", err)
return
}
r, err := resource.Merge(d, res)

if err != nil {
log.Error(context.Background(), "msg", "creating OTLP trace exporter", "err", err)
log.Error(context.Background(), "msg", "merging OTLP resource", "err", err)
return
}

tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithBatcher(otlpExporter),
sdktrace.WithResource(r),
)
otelTracer := tracerProvider.Tracer("NR")
otelTracer := tracerProvider.Tracer("")
// Use the bridgeTracer as your OpenTracing tracer.
bridgeTracer, wrapperTracerProvider := otelBridge.NewTracerPair(otelTracer)

otel.SetTracerProvider(wrapperTracerProvider)
opentracing.SetGlobalTracer(bridgeTracer)
log.Info(context.Background(), "msg", "Initialized NR opentelemetry tracing")
}

func setupHystrix() {
Expand Down

0 comments on commit 61ee8bc

Please sign in to comment.