Skip to content

Commit

Permalink
Support empty url path in HTTP client probe (#810)
Browse files Browse the repository at this point in the history
* support empty url path

* add changelog

* Update fixtures

* update gin test

* update test files

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
RonFed and MrAlias authored Apr 30, 2024
1 parent 5acdf20 commit c16adc0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http
### Fixed

- Change HTTP client span name to `{http.request.method}` ([#775](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/775))
- Don't set empty URL path in HTTP client probe. ([#810](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/810))
- Don't fail HTTP client probe attribute resolution on empty URL path. ([#810](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/810))


## [v0.12.0-alpha] - 2024-04-10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
bpf_probe_read(&url_ptr, sizeof(url_ptr), (void *)(req_ptr+url_ptr_pos));
if (!get_go_string_from_user_ptr((void *)(url_ptr+path_ptr_pos), httpReq->path, sizeof(httpReq->path))) {
bpf_printk("uprobe_Transport_roundTrip: Failed to get path from Request.URL");
return 0;
}

// get host from Request
Expand Down
5 changes: 4 additions & 1 deletion internal/pkg/instrumentation/bpf/net/http/client/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,13 @@ func convertEvent(e *event) []*probe.SpanEvent {

attrs := []attribute.KeyValue{
semconv.HTTPRequestMethodKey.String(method),
semconv.URLPath(path),
semconv.HTTPResponseStatusCodeKey.Int(int(e.StatusCode)),
}

if path != "" {
attrs = append(attrs, semconv.URLPath(path))
}

// Server address and port
serverAddr, serverPort := http.ServerAddressPortAttributes(e.Host[:])
if serverAddr.Valid() {
Expand Down
8 changes: 4 additions & 4 deletions internal/test/e2e/databasesql/traces.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@
}
},
{
"key": "url.path",
"key": "http.response.status_code",
"value": {
"stringValue": "/query_db"
"intValue": "200"
}
},
{
"key": "http.response.status_code",
"key": "url.path",
"value": {
"intValue": "200"
"stringValue": "/query_db"
}
},
{
Expand Down
8 changes: 4 additions & 4 deletions internal/test/e2e/gin/traces.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@
}
},
{
"key": "url.path",
"key": "http.response.status_code",
"value": {
"stringValue": "/hello-gin"
"intValue": "200"
}
},
{
"key": "http.response.status_code",
"key": "url.path",
"value": {
"intValue": "200"
"stringValue": "/hello-gin"
}
},
{
Expand Down
8 changes: 4 additions & 4 deletions internal/test/e2e/nethttp/traces.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@
}
},
{
"key": "url.path",
"key": "http.response.status_code",
"value": {
"stringValue": "/hello"
"intValue": "200"
}
},
{
"key": "http.response.status_code",
"key": "url.path",
"value": {
"intValue": "200"
"stringValue": "/hello"
}
},
{
Expand Down
8 changes: 4 additions & 4 deletions internal/test/e2e/nethttp_custom/traces.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@
}
},
{
"key": "url.path",
"key": "http.response.status_code",
"value": {
"stringValue": "/hello"
"intValue": "200"
}
},
{
"key": "http.response.status_code",
"key": "url.path",
"value": {
"intValue": "200"
"stringValue": "/hello"
}
},
{
Expand Down

0 comments on commit c16adc0

Please sign in to comment.