-
Notifications
You must be signed in to change notification settings - Fork 150
Go std net HTTP/1 clients: avoid injecting the traceparent twice #2752
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
Merged
mariomac
merged 6 commits into
open-telemetry:main
from
mariomac:fix-double-tp-go-http1
Jul 23, 2026
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bfc8520
Go HTTP1 clients: avoid injecting the traceparent twice
mariomac 215af4d
Addressed code comments and fixed verification issues
mariomac 0fa6a94
fixed verifier tests
mariomac 05dcec7
Prevent optimizer from removing check
mariomac dd2c0d6
Test the verifier
mariomac cf963ff
use bpf_clamp_umax
mariomac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //go:build ignore | ||
|
|
||
| // Command tphttpclient is a helper binary for the gotracer HTTP/1 traceparent | ||
| // injection privileged test. It issues an HTTP/1 request to its own loopback | ||
| // server, which reports how many `Traceparent` header values it received. Two | ||
| // modes exercise the two scenarios: | ||
| // | ||
| // - "WITH_TP": the client sets its own Traceparent header (as an SDK or a | ||
| // hand-rolled propagator would). OBI must NOT add a second one -> the | ||
| // receiver sees exactly 1. | ||
| // - "NO_TP": the client sets no Traceparent. OBI injects its own -> the | ||
| // receiver sees exactly 1 (proving injection still happens when absent). | ||
| package main | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "fmt" | ||
| "io" | ||
| "net" | ||
| "net/http" | ||
| "os" | ||
| ) | ||
|
|
||
| // A valid W3C traceparent used by the WITH_TP mode. | ||
| const staticTraceparent = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01" | ||
|
|
||
| func main() { | ||
| mux := http.NewServeMux() | ||
| mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
| fmt.Fprintf(w, "%d", len(r.Header.Values("Traceparent"))) | ||
| }) | ||
| ln, err := net.Listen("tcp", "127.0.0.1:0") | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "listen error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| go func() { _ = http.Serve(ln, mux) }() | ||
|
|
||
| // http:// with the default transport keeps this on HTTP/1.1, exercising | ||
| // OBI's net/http header_writeSubset injection path. | ||
| url := "http://" + ln.Addr().String() + "/" | ||
|
|
||
| fmt.Println("READY") | ||
|
|
||
| scanner := bufio.NewScanner(os.Stdin) | ||
| for scanner.Scan() { | ||
| switch scanner.Text() { | ||
| case "WITH_TP": | ||
| report(doRequest(url, true)) | ||
| case "NO_TP": | ||
| report(doRequest(url, false)) | ||
| case "EXIT": | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func report(count string, err error) { | ||
| if err != nil { | ||
| fmt.Printf("ERROR %v\n", err) | ||
| return | ||
| } | ||
| fmt.Printf("TP_COUNT=%s\n", count) | ||
| } | ||
|
|
||
| func doRequest(url string, withTraceparent bool) (string, error) { | ||
| req, err := http.NewRequest(http.MethodGet, url, http.NoBody) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if withTraceparent { | ||
| req.Header.Set("Traceparent", staticTraceparent) | ||
| } | ||
| resp, err := http.DefaultClient.Do(req) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| defer resp.Body.Close() | ||
| body, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return string(body), nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to bpf_probe_read_user.
Added error checks to all memory reads and moving to
donein case of failure.