Arthur S
Arthur S

Reputation: 11

Go labstack/echo and OpenTelemetry doesn't work

I'm trying to add otel tracing to my Echo server. I'm basing my code on example but anything is not coming from application to Jaeger instance that i'm running locally.

First, I've injected the middleware

e := echo.New()
e.Validator = validator
e.HTTPErrorHandler = handlers.CustomHTTPErrorHandler

// Applying middleware
e.Use(echozap.ZapLogger(logger))
e.Use(middleware.Recover())
e.Use(echoprometheus.NewMiddleware("http"))
e.Use(middleware.RequestID())
e.Use(otelecho.Middleware("http"))

// ... rest of server initialization stuff

In my CustomHTTPErrorHandler I've put these lines

ctx := c.Request().Context()
trace.SpanFromContext(ctx).RecordError(err)

Also, in my main.go file I've initialized the tracer by calling otel.Tracer("my_app").

As you can guess my app is not in a single file but has several packages, the one that I'm initializing HTTP server is httpserver. Instrumentation should work OOTB, I don't want to create spans for each endpoint. How can I achieve automatic instrumentation?

Upvotes: 1

Views: 578

Answers (0)

Related Questions