Skip to content

fix: propagate OTel trace context through the func runtime#167

Open
Nachiket-Roy wants to merge 3 commits into
knative-extensions:mainfrom
Nachiket-Roy:fix/otel-trace-propagation
Open

fix: propagate OTel trace context through the func runtime#167
Nachiket-Roy wants to merge 3 commits into
knative-extensions:mainfrom
Nachiket-Roy:fix/otel-trace-propagation

Conversation

@Nachiket-Roy

Copy link
Copy Markdown

Changes

This PR resolves issue knative/func#3866 where OpenTelemetry trace propagation would break between Knative's queue proxy and deployed Go functions.

OTel Trace Context Propagation:

  • Configured a global TextMapPropagator using a composite W3C Trace Context and Baggage propagator in both HTTP and CloudEvents services.
  • Wrapped the HTTP receiver handlers with otelhttp.NewHandler to extract incoming traceparent/tracestate headers and inject the extracted context into the request context before passing it to the function's handler.

/kind bug

Fixes knative/func#3866

Fixes an issue where OpenTelemetry trace context was dropped between Knative's queue proxy and Go functions. The runtime now correctly extracts W3C trace context headers and propagates them to the context passed to function handlers.

@knative-prow knative-prow Bot added the kind/bug Categorizes issue or PR as related to a bug. label Jun 12, 2026
@knative-prow knative-prow Bot requested review from lkingland and matejvasek June 12, 2026 19:06
@knative-prow

knative-prow Bot commented Jun 12, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Nachiket-Roy
Once this PR has been reviewed and has the lgtm label, please assign matejvasek for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow

knative-prow Bot commented Jun 12, 2026

Copy link
Copy Markdown

Welcome @Nachiket-Roy! It looks like this is your first PR to knative-extensions/func-go 🎉

@knative-prow knative-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 12, 2026
@matejvasek matejvasek requested review from Copilot and gauron99 June 14, 2026 13:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes OpenTelemetry trace context propagation for Go functions running behind Knative’s queue-proxy by ensuring W3C traceparent/tracestate headers are extracted on ingress and made available via context.Context to function handlers.

Changes:

  • Configure a W3C Trace Context + Baggage TextMapPropagator and wrap HTTP/CloudEvents receivers with otelhttp.NewHandler.
  • Add tests validating that an incoming traceparent results in a valid span context in the handler.
  • Add OpenTelemetry dependencies to go.mod/go.sum.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
http/service.go Adds global propagator configuration and wraps the root handler with otelhttp for context extraction.
http/service_test.go Adds coverage for trace-context propagation into HTTP handler contexts.
cloudevents/service.go Adds global propagator configuration and wraps the CloudEvents receiver with otelhttp.
cloudevents/service_test.go Adds coverage for trace-context propagation into CloudEvents handler contexts.
go.mod Introduces OpenTelemetry module requirements used by the runtime/tests.
go.sum Updates sums for newly introduced OpenTelemetry and transitive dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread http/service.go Outdated
Comment thread cloudevents/service.go Outdated
Comment thread http/service_test.go Outdated
Comment thread cloudevents/service_test.go Outdated
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 27, 2026
@knative-prow-robot

Copy link
Copy Markdown

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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

Labels

kind/bug Categorizes issue or PR as related to a bug. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

functions seem to not be working with opentelemetry

3 participants