Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for OpenTelemetry go tracing example with spans propagating through the gateway #3212

Open
kye308 opened this issue Feb 28, 2023 · 6 comments · Fixed by #3309
Open

Comments

@kye308
Copy link

kye308 commented Feb 28, 2023

🚀 Feature

Are there any examples of something like this using OpenTelemetry's go SDK? Would a tracing wrapper still be required?

@johanbrandhorst
Copy link
Collaborator

I don't know of any examples of using the gateway with the Otel Go SDK. You would still need a tracing wrapper yes, it should be very similar to OpenTracing. Would you like to contribute an opentelemetry example?

@matoous
Copy link

matoous commented Sep 26, 2023

I think this should be re-open, as mentioned on the issue in the examlple that was added in the PR that closed this issue, the propagation doesn't work.

@johanbrandhorst
Copy link
Collaborator

Sorry to hear it's not working. Would you be interested in submitting a fix?

@johanbrandhorst
Copy link
Collaborator

CC @iamrajiv

@iamrajiv
Copy link
Contributor

iamrajiv commented Oct 3, 2023

Hi @johanbrandhorst, I'm currently investigating the issue and working on a solution.

@matoous
Copy link

matoous commented Oct 4, 2023

@iamrajiv here's a working fix: https://github.com/openfga/openfga/pull/1024/files, I just didn't have time to update this issue yet. One needs to wrap the runtime.ServerMux in otelhttp.NewHandler (or alternatively in the PR above we just extract the trace context and propagate it on context.Context) and the same needs to be done for outgoing calls, either by wrapping the gRPC client in UnaryClientInterceptor/StreamClientInterceptor (https://pkg.go.dev/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc#UnaryClientInterceptor) or manually to skip the span:

			propagator := otel.GetTextMapPropagator()
			// If tracig is enabled wrap the handler with custom middleware that extracts
			// the tracing context and sets the corrent tracing context.
			// We use this in favor of [otelhttp.NewHandler] to avoid unnecessary nesting.
			handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				ctx := propagator.Extract(r.Context(), propagation.HeaderCarrier(r.Header))
				handler.ServeHTTP(w, r.WithContext(ctx))
			})

If using the otel package for Golang this results into 2 additional spans so the PR above does this manually to skip both of them and make the grpc-gateway transparent in the trace call stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants