Skip to content

Fix http url generation in awsxrayexporter #323

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
merged 1 commit into from
Jun 18, 2025
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
22 changes: 19 additions & 3 deletions exporter/awsxrayexporter/internal/translator/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) {
urlParts[key] = value.Str()
hasHTTP = true
hasHTTPRequestURLAttributes = true
case conventionsv112.AttributeHTTPTarget, conventions.AttributeURLQuery:
urlParts[conventionsv112.AttributeHTTPTarget] = value.Str()
case conventionsv112.AttributeHTTPTarget:
urlParts[key] = value.Str()
hasHTTP = true
case conventionsv112.AttributeHTTPServerName:
urlParts[key] = value.Str()
Expand Down Expand Up @@ -110,6 +110,9 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) {
case conventions.AttributeURLPath:
urlParts[key] = value.Str()
hasHTTP = true
case conventions.AttributeURLQuery:
urlParts[key] = value.Str()
hasHTTP = true
case conventions.AttributeServerAddress:
urlParts[key] = value.Str()
hasHTTPRequestURLAttributes = true
Expand Down Expand Up @@ -205,7 +208,16 @@ func constructClientURL(urlParts map[string]string) string {
if ok {
url += target
} else {
url += "/"
path, ok := urlParts[conventions.AttributeURLPath]
if ok {
url += path
} else {
url += "/"
}
query, ok := urlParts[conventions.AttributeURLQuery]
if ok {
url += "?" + query
}
}
return url
}
Expand Down Expand Up @@ -259,6 +271,10 @@ func constructServerURL(urlParts map[string]string) string {
} else {
url += "/"
}
query, ok := urlParts[conventions.AttributeURLQuery]
if ok {
url += "?" + query
}
}
return url
}
19 changes: 10 additions & 9 deletions exporter/awsxrayexporter/internal/translator/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestClientSpanWithSchemeHostTargetAttributesStable(t *testing.T) {
attributes[conventions.AttributeHTTPRequestMethod] = "GET"
attributes[conventions.AttributeURLScheme] = "https"
attributes[conventionsv112.AttributeHTTPHost] = "api.example.com"
attributes[conventions.AttributeURLQuery] = "/users/junit"
attributes[conventions.AttributeURLQuery] = "users=junit"
attributes[conventions.AttributeHTTPResponseStatusCode] = 200
attributes["user.id"] = "junit"
span := constructHTTPClientSpan(attributes)
Expand All @@ -92,7 +92,7 @@ func TestClientSpanWithSchemeHostTargetAttributesStable(t *testing.T) {
require.NoError(t, w.Encode(httpData))
jsonStr := w.String()
testWriters.release(w)
assert.Contains(t, jsonStr, "https://api.example.com/users/junit")
assert.Contains(t, jsonStr, "https://api.example.com/?users=junit")
}

func TestClientSpanWithPeerAttributes(t *testing.T) {
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestClientSpanWithPeerAttributesStable(t *testing.T) {
attributes[conventionsv112.AttributeNetPeerName] = "kb234.example.com"
attributes[conventionsv112.AttributeNetPeerPort] = 8080
attributes[conventionsv112.AttributeNetPeerIP] = "10.8.17.36"
attributes[conventions.AttributeURLQuery] = "/users/junit"
attributes[conventions.AttributeURLQuery] = "users=junit"
attributes[conventions.AttributeHTTPResponseStatusCode] = 200
span := constructHTTPClientSpan(attributes)

Expand All @@ -143,7 +143,7 @@ func TestClientSpanWithPeerAttributesStable(t *testing.T) {
require.NoError(t, w.Encode(httpData))
jsonStr := w.String()
testWriters.release(w)
assert.Contains(t, jsonStr, "http://kb234.example.com:8080/users/junit")
assert.Contains(t, jsonStr, "http://kb234.example.com:8080/?users=junit")
}

func TestClientSpanWithHttpPeerAttributes(t *testing.T) {
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestServerSpanWithSchemeHostTargetAttributesStable(t *testing.T) {
attributes[conventions.AttributeHTTPRequestMethod] = http.MethodGet
attributes[conventions.AttributeURLScheme] = "https"
attributes[conventions.AttributeServerAddress] = "api.example.com"
attributes[conventions.AttributeURLQuery] = "/users/junit"
attributes[conventions.AttributeURLQuery] = "users=junit"
attributes[conventions.AttributeClientAddress] = "192.168.15.32"
attributes[conventions.AttributeHTTPResponseStatusCode] = 200
span := constructHTTPServerSpan(attributes)
Expand All @@ -292,7 +292,7 @@ func TestServerSpanWithSchemeHostTargetAttributesStable(t *testing.T) {
require.NoError(t, w.Encode(httpData))
jsonStr := w.String()
testWriters.release(w)
assert.Contains(t, jsonStr, "https://api.example.com/users/junit")
assert.Contains(t, jsonStr, "https://api.example.com/?users=junit")
}

func TestServerSpanWithSchemeServernamePortTargetAttributes(t *testing.T) {
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestServerSpanWithSchemeServernamePortTargetAttributesStable(t *testing.T)
attributes[conventions.AttributeURLScheme] = "https"
attributes[conventions.AttributeServerAddress] = "api.example.com"
attributes[conventions.AttributeServerPort] = 443
attributes[conventions.AttributeURLQuery] = "/users/junit"
attributes[conventions.AttributeURLQuery] = "users=junit"
attributes[conventions.AttributeClientAddress] = "192.168.15.32"
attributes[conventions.AttributeHTTPResponseStatusCode] = 200
span := constructHTTPServerSpan(attributes)
Expand All @@ -336,7 +336,7 @@ func TestServerSpanWithSchemeServernamePortTargetAttributesStable(t *testing.T)
require.NoError(t, w.Encode(httpData))
jsonStr := w.String()
testWriters.release(w)
assert.Contains(t, jsonStr, "https://api.example.com/users/junit")
assert.Contains(t, jsonStr, "https://api.example.com/?users=junit")
}

func TestServerSpanWithSchemeNamePortTargetAttributes(t *testing.T) {
Expand Down Expand Up @@ -370,6 +370,7 @@ func TestServerSpanWithSchemeNamePortTargetAttributesStable(t *testing.T) {
attributes[conventions.AttributeServerAddress] = "kb234.example.com"
attributes[conventions.AttributeServerPort] = 8080
attributes[conventions.AttributeURLPath] = "/users/junit"
attributes[conventions.AttributeURLQuery] = "v=1"
attributes[conventions.AttributeClientAddress] = "192.168.15.32"
attributes[conventions.AttributeHTTPResponseStatusCode] = 200
span := constructHTTPServerSpan(attributes)
Expand All @@ -384,7 +385,7 @@ func TestServerSpanWithSchemeNamePortTargetAttributesStable(t *testing.T) {
require.NoError(t, w.Encode(httpData))
jsonStr := w.String()
testWriters.release(w)
assert.Contains(t, jsonStr, "http://kb234.example.com:8080/users/junit")
assert.Contains(t, jsonStr, "http://kb234.example.com:8080/users/junit?v=1")
}

func TestSpanWithNotEnoughHTTPRequestURLAttributes(t *testing.T) {
Expand Down