From ca73ee3df998c42e1dde7dce839e9bfec6af9c89 Mon Sep 17 00:00:00 2001 From: Ankur Shrivastava Date: Sat, 10 Sep 2022 20:04:09 +0800 Subject: [PATCH] updating open telemetry --- core.go | 2 +- initializers.go | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core.go b/core.go index 25ff298..ba21981 100644 --- a/core.go +++ b/core.go @@ -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) } } diff --git a/initializers.go b/initializers.go index d36e8ee..d2bab81 100644 --- a/initializers.go +++ b/initializers.go @@ -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) { @@ -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"), } @@ -128,16 +125,23 @@ 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( @@ -145,12 +149,13 @@ func setupNROpenTelemetry(serviceName string, license string) { 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() {