-
Notifications
You must be signed in to change notification settings - Fork 218
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
How to set OpenTelemetry tracing parameters? #693
Comments
Hey, @boramalper are still looking for an answer to this? I recently did an implementation of the Observability service, working with OpenTelemetry. If I understood correctly you want to put the trace data (traceparent) inside the event before you send it? The approach I took is to the use DistributedTracingExtension, in conjunction with a custom carrier from OTel. You can check it here: https://github.com/dynatrace-oss-contrib/go-utils/blob/feat/2422/add-otel-instrumentation/pkg/common/observability/otel_observability_service.go, here: https://github.com/dynatrace-oss-contrib/go-utils/blob/feat/2422/add-otel-instrumentation/pkg/common/observability/cloudevents_carrrier.go and here: https://github.com/dynatrace-oss-contrib/go-utils/blob/feat/2422/add-otel-instrumentation/pkg/common/observability/cloudevents_trace_context.go Then when sending the event you can do: func sendEvent(ctx context.Context, e cloudevents.Event) {
// will inject the traceparent from the ctx into the event
// Or you could also start a span here and use the new context
// ctx, span := tracer.Start(ctx, "sending", trace.WithSpanKind(trace.SpanKindProducer))
// defer span.End()
InjectDistributedTracingExtension(ctx, e)
// send the event..
} Then on the other side receiving, you can extract it to continue the trace: func longRunningReceive() {
evt := getFromQueue()
// ctx here will have again the proper tracecontext and you can pass it around to continue the trace
ctx := ExtractDistributedTracingExtension(context.Background(), *evt)
} Not sure that helps? I might contribute this to cloudevents, just need some discussion on the details/API. |
hi @joaopgrassi, this is definitely something we would be interested in. Would be great if you could upstream that. thanks @boramalper for bringing me into this discussion. |
Yes please, glad you got it working. @benmoss was also helping clear some of this up with some examples added to the sdk. Maybe Ben has more to say? |
With the changes I made in #708 you can propagate trace headers through with the otelhttp middleware, I did this in this demo app: https://github.com/benmoss/knative-tracing/blob/main/cmd/coinflip/main.go#L60-L62 I think this is nice from a simplicity perspective, but having an ObservabilityService implementation seems like a good idea too. |
@benmoss thanks a lot for your response! this seems very useful and easy to use. do you know what is the minimal version of otelhttp that supports it? |
@ustiugov it looks like it's been in since 0.12.0 https://pkg.go.dev/go.opentelemetry.io/contrib/instrumentation/net/http/[email protected] |
I am using Knative Eventing and want to set OpenTelemetry tracing parameters (tracing ID, span ID etc.) for the event that I am sending to Knative Eventing Broker.
I thought
WithTracePropagation()
could have been helpful but it is deprecated and no alternatives are listed.ObservabilityService
could have been an alternative solution but it does not have anOutboundContextDecorators()
... Though I would like to be able to set OpenTelemetry tracing parameters myself freely, without using middlewares or other magic.What I currently have is this (simplified):
The text was updated successfully, but these errors were encountered: