diff --git a/exporter/awsxrayexporter/internal/translator/http.go b/exporter/awsxrayexporter/internal/translator/http.go index 781583afe37cf..515f2eb3cab4d 100644 --- a/exporter/awsxrayexporter/internal/translator/http.go +++ b/exporter/awsxrayexporter/internal/translator/http.go @@ -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() @@ -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 @@ -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 } @@ -259,6 +271,10 @@ func constructServerURL(urlParts map[string]string) string { } else { url += "/" } + query, ok := urlParts[conventions.AttributeURLQuery] + if ok { + url += "?" + query + } } return url } diff --git a/exporter/awsxrayexporter/internal/translator/http_test.go b/exporter/awsxrayexporter/internal/translator/http_test.go index e6c40b9826e6d..498bb7c324dfb 100644 --- a/exporter/awsxrayexporter/internal/translator/http_test.go +++ b/exporter/awsxrayexporter/internal/translator/http_test.go @@ -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) @@ -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) { @@ -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) @@ -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) { @@ -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) @@ -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) { @@ -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) @@ -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) { @@ -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) @@ -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) {