Skip to content

fix(gotracer): respect context_propagation for Go HTTP/gRPC header in…#2292

Open
mohd-ibadullah wants to merge 3 commits into
open-telemetry:mainfrom
mohd-ibadullah:fix-grpc-context-propagation
Open

fix(gotracer): respect context_propagation for Go HTTP/gRPC header in…#2292
mohd-ibadullah wants to merge 3 commits into
open-telemetry:mainfrom
mohd-ibadullah:fix-grpc-context-propagation

Conversation

@mohd-ibadullah

Copy link
Copy Markdown

Summary

When context_propagation is disabled, Go HTTP/gRPC clients still inject traceparent headers because the Go-specific propagation path only checks kernel capabilities and ignores the configured propagation mode.

This change aligns gotracer behavior with tpinjector and generictracer by requiring header propagation to be explicitly enabled before registering propagation probes or enabling header injection.

Fixes #2276

Changes

  • Add headerPropagationEnabled()
  • Gate g_bpf_header_propagation on both kernel support and ContextPropagation.HasHeaders()
  • Align g_bpf_traceparent_enabled with generictracer
  • Register HTTP/gRPC propagation probes only when header propagation is enabled
  • Add regression tests covering propagation constants and probe registration

Validation

  • Added unit tests for disabled, tcp, headers, and all propagation modes
  • Verified probe registration behavior matches configured propagation mode
  • Verified Go gRPC instrumentation remains registered independently of propagation mode

@mohd-ibadullah mohd-ibadullah requested a review from a team as a code owner June 10, 2026 10:23
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 10, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: mohd-ibadullah / name: ibad (fd9bc6e)

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.49%. Comparing base (62333b5) to head (54e10c5).
⚠️ Report is 52 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2292      +/-   ##
==========================================
+ Coverage   68.83%   69.49%   +0.65%     
==========================================
  Files         308      317       +9     
  Lines       40127    41228    +1101     
==========================================
+ Hits        27623    28653    +1030     
+ Misses      10977    10973       -4     
- Partials     1527     1602      +75     
Flag Coverage Δ
integration-test 51.73% <100.00%> (+1.72%) ⬆️
integration-test-arm 28.81% <80.00%> (-0.53%) ⬇️
integration-test-vm-5.15-lts 29.29% <80.00%> (-0.59%) ⬇️
integration-test-vm-6.18-lts 28.74% <80.00%> (-0.20%) ⬇️
k8s-integration-test 39.66% <100.00%> (+0.27%) ⬆️
oats-test 37.02% <100.00%> (-0.05%) ⬇️
unittests 62.26% <80.00%> (-0.32%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 Go tracer (gotracer) context propagation behavior so that traceparent header injection (HTTP/1, HTTP/2, gRPC) is only enabled when the configured context_propagation mode includes headers, aligning behavior with tpinjector/generictracer and addressing #2276.

Changes:

  • Add headerPropagationEnabled() and use it to gate g_bpf_header_propagation and HTTP/HTTP2 propagation uprobe registration.
  • Align g_bpf_traceparent_enabled with generictracer (enabled only when TrackRequestHeaders or any context propagation is enabled).
  • Add unit tests covering constants and (some) probe-registration expectations across propagation modes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/internal/ebpf/gotracer/gotracer.go Gates Go header propagation constants/probes on both kernel capability and ContextPropagation.HasHeaders(), and aligns traceparent parsing enablement with other tracers.
pkg/internal/ebpf/gotracer/gotracer_test.go Adds regression tests for propagation-related constants and for conditional registration of key HTTP/HTTP2 propagation probes.
Comments suppressed due to low confidence (1)

pkg/internal/ebpf/gotracer/gotracer.go:834

  • The new header-propagation gating in GoProbes only wraps the net/http and http2 WriteHeaders probes. Several gRPC header-propagation helper probes (e.g., google.golang.org/grpc/internal/transport.(*http2Client).NewStream return probe, (*controlBuffer).executeAndPut, (*loopyWriter).originateStream) are still registered unconditionally even though their eBPF programs early-return when g_bpf_header_propagation=false. To fully “register propagation probes only when header propagation is enabled” (per PR description) and to avoid unnecessary uprobe attachment overhead, consider moving those gRPC propagation-only probes under the same headerPropagationEnabled() condition (while keeping non-propagation gRPC tracing probes always-on).
	if p.headerPropagationEnabled() {
		m["net/http.Header.writeSubset"] = []*ebpfcommon.ProbeDesc{{
			Start: p.bpfObjects.ObiUprobeWriteSubset, // http 1.x context propagation
		}}
		m["golang.org/x/net/http2.(*Framer).WriteHeaders"] = []*ebpfcommon.ProbeDesc{
			{ // http2 context propagation
				Start: p.bpfObjects.ObiUprobeGolangHttp2FramerWriteHeaders,
				End:   p.bpfObjects.ObiUprobeHttp2FramerWriteHeadersReturns,
			},
			{ // for grpc
				Start: p.bpfObjects.ObiUprobeGrpcFramerWriteHeaders,
				End:   p.bpfObjects.ObiUprobeGrpcFramerWriteHeadersReturns,
			},
		}
		m["net/http.(*http2Framer).WriteHeaders"] = []*ebpfcommon.ProbeDesc{{ // http2 context propagation
			Start: p.bpfObjects.ObiUprobeNetHttp2FramerWriteHeaders,
			End:   p.bpfObjects.ObiUprobeHttp2FramerWriteHeadersReturns,
		}}
	}

@mmat11

mmat11 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

looks like a lot of tests are failing, they probably need explicit config for headers context propagation

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

pkg/internal/ebpf/gotracer/gotracer.go:113

  • The CAP_SYS_ADMIN/lockdown log in LoadSpecs() is emitted even when header propagation is not requested (e.g., context_propagation: disabled or tcp). Since this message is specifically about Go library-level header injection support, it’s misleading/noisy unless header propagation is enabled in config. Consider gating the log behind ContextPropagation.HasHeaders() so users don’t see propagation warnings when they’ve explicitly disabled it (or enabled tcp-only propagation).

func (p *Tracer) LoadSpecs() ([]*ebpfcommon.SpecBundle, error) {
	if !p.supportsContextPropagation() {
		p.log.Info("Kernel in lockdown mode or missing CAP_SYS_ADMIN.")
	}

Comment thread pkg/internal/ebpf/gotracer/gotracer.go

@mmat11 mmat11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

needs linter fix and copilot comment looks valid, lgtm after that

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disabling context_propagation doesn't disable gRPC traceparent header injection (golang)

3 participants