-
Hi! Guys, I am using Otel I narrowed down to the SDKs tracing resource res := resource.NewWithAttributes(semconv.ServiceNameKey.String(appName)) but I can't get rid of it. Here is the complete code package tracing
import (
"context"
"fmt"
"os"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/exporters/otlp"
"go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/semconv"
"go.opentelemetry.io/otel/trace"
)
func InitTracer(collectorAddr string, appName string, operationName string) (trace.Span, *sdktrace.TracerProvider, context.Context) {
ctx := context.Background()
driver :=
otlpgrpc.NewDriver(
otlpgrpc.WithInsecure(),
otlpgrpc.WithEndpoint(collectorAddr),
)
exporter, err := otlp.NewExporter(ctx, driver)
if err != nil {
fmt.Printf("Error initializing the tracer exporter")
}
res := resource.NewWithAttributes(semconv.ServiceNameKey.String(appName))
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(res),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
ctx, span := tp.Tracer(operationName).Start(ctx, operationName)
return span, tp, ctx
}
func ErrExit(span trace.Span, tp *sdktrace.TracerProvider, errorMsg string, exitNumber int) {
span.SetAttributes(attribute.String("error", errorMsg))
span.SetStatus(codes.Error, errorMsg)
span.End()
tp.Shutdown(context.Background())
fmt.Println(errorMsg)
os.Exit(exitNumber)
}
func Attribute(span trace.Span, label string, msg string) trace.Span {
span.SetAttributes(attribute.String(label, msg))
return span
} Removing the whole |
Beta Was this translation helpful? Give feedback.
Answered by
dxalfonzo
Nov 6, 2021
Replies: 1 comment
-
Found my answer: Upgrade to 1.1.0 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dxalfonzo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found my answer: Upgrade to 1.1.0