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

HTTP client: Use Host field in URL if the Request Host is not present #888

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
- Initial support for `trace-flags`. ([#868](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/868))
- Support `google.golang.org/grpc` `1.66.0-dev`. ([#872](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/872))

### Fixed

- HTTP client: Use Host field in URL if the Request Host is not present. ([#888](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/888))

## [v0.13.0-alpha] - 2024-06-04

### Added
Expand Down
163 changes: 163 additions & 0 deletions internal/pkg/inject/offset_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -5286,6 +5286,169 @@
}
]
},
{
"field": "Host",
"offsets": [
{
"offset": 40,
"versions": [
"1.12.0",
"1.12.1",
"1.12.2",
"1.12.3",
"1.12.4",
"1.12.5",
"1.12.6",
"1.12.7",
"1.12.8",
"1.12.9",
"1.12.10",
"1.12.11",
"1.12.12",
"1.12.13",
"1.12.14",
"1.12.15",
"1.12.16",
"1.12.17",
"1.13.0",
"1.13.1",
"1.13.2",
"1.13.3",
"1.13.4",
"1.13.5",
"1.13.6",
"1.13.7",
"1.13.8",
"1.13.9",
"1.13.10",
"1.13.11",
"1.13.12",
"1.13.13",
"1.13.14",
"1.13.15",
"1.14.0",
"1.14.1",
"1.14.2",
"1.14.3",
"1.14.4",
"1.14.5",
"1.14.6",
"1.14.7",
"1.14.8",
"1.14.9",
"1.14.10",
"1.14.11",
"1.14.12",
"1.14.13",
"1.14.14",
"1.14.15",
"1.15.0",
"1.15.1",
"1.15.2",
"1.15.3",
"1.15.4",
"1.15.5",
"1.15.6",
"1.15.7",
"1.15.8",
"1.15.9",
"1.15.10",
"1.15.11",
"1.15.12",
"1.15.13",
"1.15.14",
"1.15.15",
"1.16.0",
"1.16.1",
"1.16.2",
"1.16.3",
"1.16.4",
"1.16.5",
"1.16.6",
"1.16.7",
"1.16.8",
"1.16.9",
"1.16.10",
"1.16.11",
"1.16.12",
"1.16.13",
"1.16.14",
"1.16.15",
"1.17.0",
"1.17.1",
"1.17.2",
"1.17.3",
"1.17.4",
"1.17.5",
"1.17.6",
"1.17.7",
"1.17.8",
"1.17.9",
"1.17.10",
"1.17.11",
"1.17.12",
"1.17.13",
"1.18.0",
"1.18.1",
"1.18.2",
"1.18.3",
"1.18.4",
"1.18.5",
"1.18.6",
"1.18.7",
"1.18.8",
"1.18.9",
"1.18.10",
"1.19.0",
"1.19.1",
"1.19.2",
"1.19.3",
"1.19.4",
"1.19.5",
"1.19.6",
"1.19.7",
"1.19.8",
"1.19.9",
"1.19.10",
"1.19.11",
"1.19.12",
"1.19.13",
"1.20.0",
"1.20.1",
"1.20.2",
"1.20.3",
"1.20.4",
"1.20.5",
"1.20.6",
"1.20.7",
"1.20.8",
"1.20.9",
"1.20.10",
"1.20.11",
"1.20.12",
"1.20.13",
"1.20.14",
"1.21.0",
"1.21.1",
"1.21.2",
"1.21.3",
"1.21.4",
"1.21.5",
"1.21.6",
"1.21.7",
"1.21.8",
"1.21.9",
"1.21.10",
"1.21.11",
"1.22.0",
"1.22.1",
"1.22.2",
"1.22.3",
"1.22.4"
]
}
]
},
{
"field": "OmitHost",
"offsets": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ volatile const u64 raw_fragment_pos;
volatile const u64 username_pos;
volatile const u64 io_writer_buf_ptr_pos;
volatile const u64 io_writer_n_pos;
volatile const u64 url_host_pos;

// This instrumentation attaches uprobe to the following function:
// func net/http/transport.roundTrip(req *Request) (*Response, error)
Expand Down Expand Up @@ -191,7 +192,10 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {

// get host from Request
if (!get_go_string_from_user_ptr((void *)(req_ptr+request_host_pos), httpReq->host, sizeof(httpReq->host))) {
bpf_printk("uprobe_Transport_roundTrip: Failed to get host from Request");
// If host is not present in Request, get it from URL
if (!get_go_string_from_user_ptr((void *)(url_ptr+url_host_pos), httpReq->host, sizeof(httpReq->host))) {
bpf_printk("uprobe_Transport_roundTrip: Failed to get host from Request and URL");
}
}

// get proto from Request
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/instrumentation/bpf/net/http/client/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ func New(logger logr.Logger) probe.Probe {
Key: "username_pos",
Val: structfield.NewID("std", "net/url", "Userinfo", "username"),
},
probe.StructFieldConst{
Key: "url_host_pos",
Val: structfield.NewID("std", "net/url", "URL", "Host"),
},
},
Uprobes: uprobes,
ReaderFn: func(obj bpfObjects) (*perf.Reader, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/tools/inspect/cmd/offsetgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func manifests() ([]inspect.Manifest, error) {
structfield.NewID("std", "net/url", "URL", "RawQuery"),
structfield.NewID("std", "net/url", "URL", "Fragment"),
structfield.NewID("std", "net/url", "URL", "RawFragment"),
structfield.NewID("std", "net/url", "URL", "Host"),
structfield.NewID("std", "net/url", "Userinfo", "username"),
structfield.NewID("std", "bufio", "Writer", "buf"),
structfield.NewID("std", "bufio", "Writer", "n"),
Expand Down
Loading