From 0860c1c90ab8884c84d95177160445abd87539a4 Mon Sep 17 00:00:00 2001 From: Wang Date: Wed, 7 Feb 2024 15:55:40 -0800 Subject: [PATCH 1/6] handling http semantic convention breaking changes in v1.23.0 --- .../internal/translator/http.go | 76 +++-- .../internal/translator/http_test.go | 263 ++++++++++++++++++ 2 files changed, 309 insertions(+), 30 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/http.go b/exporter/awsxrayexporter/internal/translator/http.go index d6a1795c1502..20dfd6fb3f77 100644 --- a/exporter/awsxrayexporter/internal/translator/http.go +++ b/exporter/awsxrayexporter/internal/translator/http.go @@ -14,6 +14,20 @@ import ( awsxray "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray" ) +const ( + AttributeHTTPRequestMethod = "http.request.method" + AttributeHTTPResponseStatusCode = "http.response.status_code" + AttributeServerAddress = "server.address" + AttributeServerPort = "server.port" + AttributeNetworkPeerAddress = "network.peer.address" + AttributeClientAddress = "client.address" + AttributeClientPort = "client.port" + AttributeURLSchema = "url.scheme" + AttributeURLFull = "url.full" + AttributeURLPath = "url.path" + AttributeUserAgentOriginal = "user_agent.original" +) + func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) { var ( info = awsxray.HTTPData{ @@ -33,62 +47,63 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) { span.Attributes().Range(func(key string, value pcommon.Value) bool { switch key { - case conventions.AttributeHTTPMethod: + case conventions.AttributeHTTPMethod, AttributeHTTPRequestMethod: info.Request.Method = awsxray.String(value.Str()) hasHTTP = true - case conventions.AttributeHTTPClientIP: + case conventions.AttributeHTTPClientIP, AttributeClientAddress: + //urlParts[conventions.AttributeHTTPClientIP] = value.Str() info.Request.ClientIP = awsxray.String(value.Str()) info.Request.XForwardedFor = aws.Bool(true) hasHTTP = true - case conventions.AttributeHTTPUserAgent: + case conventions.AttributeHTTPUserAgent, AttributeUserAgentOriginal: info.Request.UserAgent = awsxray.String(value.Str()) hasHTTP = true - case conventions.AttributeHTTPStatusCode: + case conventions.AttributeHTTPStatusCode, AttributeHTTPResponseStatusCode: info.Response.Status = aws.Int64(value.Int()) hasHTTP = true - case conventions.AttributeHTTPURL: - urlParts[key] = value.Str() + case conventions.AttributeHTTPURL, AttributeURLFull: + urlParts[conventions.AttributeHTTPURL] = value.Str() hasHTTP = true hasHTTPRequestURLAttributes = true - case conventions.AttributeHTTPScheme: - urlParts[key] = value.Str() + case conventions.AttributeHTTPScheme, AttributeURLSchema: + urlParts[conventions.AttributeHTTPScheme] = value.Str() hasHTTP = true - case conventions.AttributeHTTPHost: - urlParts[key] = value.Str() + case conventions.AttributeHTTPHost, AttributeServerAddress: + urlParts[conventions.AttributeHTTPHost] = value.Str() hasHTTP = true hasHTTPRequestURLAttributes = true - case conventions.AttributeHTTPTarget: - urlParts[key] = value.Str() + case conventions.AttributeHTTPTarget, AttributeURLPath: + urlParts[conventions.AttributeHTTPTarget] = value.Str() hasHTTP = true - case conventions.AttributeHTTPServerName: + case conventions.AttributeHTTPServerName: // Deprecated, use `server.address` urlParts[key] = value.Str() hasHTTP = true hasHTTPRequestURLAttributes = true - case conventions.AttributeNetHostPort: - urlParts[key] = value.Str() + case conventions.AttributeNetHostPort, AttributeServerPort: + urlParts[conventions.AttributeNetHostPort] = value.Str() hasHTTP = true - if len(urlParts[key]) == 0 { - urlParts[key] = strconv.FormatInt(value.Int(), 10) + if len(urlParts[conventions.AttributeNetHostPort]) == 0 { + urlParts[conventions.AttributeNetHostPort] = strconv.FormatInt(value.Int(), 10) } - case conventions.AttributeHostName: + case conventions.AttributeHostName: // Deprecated, use `server.address` urlParts[key] = value.Str() hasHTTPRequestURLAttributes = true - case conventions.AttributeNetHostName: + case conventions.AttributeNetHostName: // Deprecated, use `server.address` urlParts[key] = value.Str() hasHTTPRequestURLAttributes = true - case conventions.AttributeNetPeerName: - urlParts[key] = value.Str() - case conventions.AttributeNetPeerPort: + case conventions.AttributeNetPeerName: // Deprecated, use `client.address` urlParts[key] = value.Str() - if len(urlParts[key]) == 0 { + case conventions.AttributeNetPeerPort, AttributeClientPort: + urlParts[conventions.AttributeNetPeerPort] = value.Str() + if len(urlParts[conventions.AttributeNetPeerPort]) == 0 { urlParts[key] = strconv.FormatInt(value.Int(), 10) } - case conventions.AttributeNetPeerIP: + case conventions.AttributeNetPeerIP, AttributeNetworkPeerAddress: // Prefer HTTP forwarded information (AttributeHTTPClientIP) when present. if info.Request.ClientIP == nil { info.Request.ClientIP = awsxray.String(value.Str()) } - urlParts[key] = value.Str() + urlParts[conventions.AttributeNetPeerIP] = value.Str() hasHTTPRequestURLAttributes = true default: filtered[key] = value @@ -193,7 +208,12 @@ func constructServerURL(urlParts map[string]string) string { if !ok { scheme = "http" } - port := "" + + port, ok := urlParts[conventions.AttributeNetHostPort] + if !ok { + port = "" + } + host, ok := urlParts[conventions.AttributeHTTPHost] if !ok { host, ok = urlParts[conventions.AttributeHTTPServerName] @@ -203,10 +223,6 @@ func constructServerURL(urlParts map[string]string) string { host = urlParts[conventions.AttributeHostName] } } - port, ok = urlParts[conventions.AttributeNetHostPort] - if !ok { - port = "" - } } url = scheme + "://" + host if len(port) > 0 && !(scheme == "http" && port == "80") && !(scheme == "https" && port == "443") { diff --git a/exporter/awsxrayexporter/internal/translator/http_test.go b/exporter/awsxrayexporter/internal/translator/http_test.go index 8d9948eab050..4b7ac59d1f8c 100644 --- a/exporter/awsxrayexporter/internal/translator/http_test.go +++ b/exporter/awsxrayexporter/internal/translator/http_test.go @@ -33,6 +33,24 @@ func TestClientSpanWithURLAttribute(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) } +func TestClientSpanWithURLAttributeStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLFull] = "https://api.example.com/users/junit" + attributes[AttributeHTTPResponseStatusCode] = 200 + span := constructHTTPClientSpan(attributes) + + filtered, httpData := makeHTTP(span) + + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) +} + func TestClientSpanWithSchemeHostTargetAttributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -54,6 +72,27 @@ func TestClientSpanWithSchemeHostTargetAttributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) } +func TestClientSpanWithSchemeHostTargetAttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLSchema] = "https" + attributes[AttributeServerAddress] = "api.example.com" + attributes[AttributeURLPath] = "/users/junit" + attributes[AttributeHTTPResponseStatusCode] = 200 + attributes["user.id"] = "junit" + span := constructHTTPClientSpan(attributes) + + filtered, httpData := makeHTTP(span) + + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) +} + func TestClientSpanWithPeerAttributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -79,6 +118,31 @@ func TestClientSpanWithPeerAttributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "http://kb234.example.com:8080/users/junit")) } +func TestClientSpanWithPeerAttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLSchema] = "http" + attributes[conventions.AttributeNetPeerName] = "kb234.example.com" + attributes[conventions.AttributeNetPeerPort] = 8080 + attributes[conventions.AttributeNetPeerIP] = "10.8.17.36" + attributes[conventions.AttributeHTTPTarget] = "/users/junit" + attributes[conventions.AttributeHTTPStatusCode] = 200 + span := constructHTTPClientSpan(attributes) + + filtered, httpData := makeHTTP(span) + + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + + assert.Equal(t, "10.8.17.36", *httpData.Request.ClientIP) + + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "http://kb234.example.com:8080/users/junit")) +} + func TestClientSpanWithHttpPeerAttributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPClientIP] = "1.2.3.4" @@ -93,6 +157,20 @@ func TestClientSpanWithHttpPeerAttributes(t *testing.T) { assert.Equal(t, "1.2.3.4", *httpData.Request.ClientIP) } +func TestClientSpanWithHttpPeerAttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeClientAddress] = "1.2.3.4" + attributes[AttributeNetworkPeerAddress] = "10.8.17.36" + span := constructHTTPClientSpan(attributes) + + filtered, httpData := makeHTTP(span) + + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + + assert.Equal(t, "1.2.3.4", *httpData.Request.ClientIP) +} + func TestClientSpanWithPeerIp4Attributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -112,6 +190,25 @@ func TestClientSpanWithPeerIp4Attributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "http://10.8.17.36:8080/users/junit")) } +func TestClientSpanWithPeerIp4AttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLSchema] = "http" + attributes[AttributeNetworkPeerAddress] = "10.8.17.36" + attributes[AttributeClientPort] = "8080" + attributes[AttributeURLPath] = "/users/junit" + span := constructHTTPClientSpan(attributes) + + filtered, httpData := makeHTTP(span) + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "http://10.8.17.36:8080/users/junit")) +} + func TestClientSpanWithPeerIp6Attributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -131,6 +228,25 @@ func TestClientSpanWithPeerIp6Attributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "https://2001:db8:85a3::8a2e:370:7334/users/junit")) } +func TestClientSpanWithPeerIp6AttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLSchema] = "https" + attributes[AttributeNetworkPeerAddress] = "2001:db8:85a3::8a2e:370:7334" + attributes[AttributeClientPort] = "443" + attributes[AttributeURLPath] = "/users/junit" + span := constructHTTPClientSpan(attributes) + + filtered, httpData := makeHTTP(span) + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "https://2001:db8:85a3::8a2e:370:7334/users/junit")) +} + func TestServerSpanWithURLAttribute(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -151,6 +267,26 @@ func TestServerSpanWithURLAttribute(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) } +func TestServerSpanWithURLAttributeStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLFull] = "https://api.example.com/users/junit" + attributes[AttributeClientAddress] = "192.168.15.32" + attributes[AttributeUserAgentOriginal] = "PostmanRuntime/7.21.0" + attributes[AttributeHTTPResponseStatusCode] = 200 + span := constructHTTPServerSpan(attributes) + + filtered, httpData := makeHTTP(span) + + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) +} + func TestServerSpanWithSchemeHostTargetAttributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -172,6 +308,27 @@ func TestServerSpanWithSchemeHostTargetAttributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) } +func TestServerSpanWithSchemeHostTargetAttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLSchema] = "https" + attributes[AttributeServerAddress] = "api.example.com" + attributes[AttributeURLPath] = "/users/junit" + attributes[AttributeClientAddress] = "192.168.15.32" + attributes[AttributeHTTPResponseStatusCode] = 200 + span := constructHTTPServerSpan(attributes) + + filtered, httpData := makeHTTP(span) + + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) +} + func TestServerSpanWithSchemeServernamePortTargetAttributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -194,6 +351,28 @@ func TestServerSpanWithSchemeServernamePortTargetAttributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) } +func TestServerSpanWithSchemeServernamePortTargetAttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLSchema] = "https" + attributes[AttributeServerAddress] = "api.example.com" + attributes[AttributeServerPort] = 443 + attributes[AttributeURLPath] = "/users/junit" + attributes[AttributeClientAddress] = "192.168.15.32" + attributes[AttributeHTTPResponseStatusCode] = 200 + span := constructHTTPServerSpan(attributes) + + filtered, httpData := makeHTTP(span) + + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) +} + func TestServerSpanWithSchemeNamePortTargetAttributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -218,6 +397,30 @@ func TestServerSpanWithSchemeNamePortTargetAttributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "http://kb234.example.com:8080/users/junit")) } +func TestServerSpanWithSchemeNamePortTargetAttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLSchema] = "http" + attributes[AttributeServerAddress] = "kb234.example.com" + attributes[AttributeServerPort] = 8080 + attributes[AttributeURLPath] = "/users/junit" + attributes[AttributeClientAddress] = "192.168.15.32" + attributes[AttributeHTTPResponseStatusCode] = 200 + span := constructHTTPServerSpan(attributes) + timeEvents := constructTimedEventsWithReceivedMessageEvent(span.EndTimestamp()) + timeEvents.CopyTo(span.Events()) + + filtered, httpData := makeHTTP(span) + + assert.NotNil(t, httpData) + assert.NotNil(t, filtered) + w := testWriters.borrow() + require.NoError(t, w.Encode(httpData)) + jsonStr := w.String() + testWriters.release(w) + assert.True(t, strings.Contains(jsonStr, "http://kb234.example.com:8080/users/junit")) +} + func TestSpanWithNotEnoughHTTPRequestURLAttributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -244,6 +447,66 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributes(t *testing.T) { assert.NotNil(t, filtered) } +func TestSpanWithNotEnoughHTTPRequestURLAttributesStable(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeURLSchema] = "http" + attributes[AttributeClientAddress] = "192.168.15.32" + attributes[AttributeUserAgentOriginal] = "PostmanRuntime/7.21.0" + attributes[AttributeURLPath] = "/users/junit" + attributes[AttributeServerPort] = 443 + attributes[AttributeClientPort] = 8080 + attributes[AttributeHTTPResponseStatusCode] = 200 + span := constructHTTPServerSpan(attributes) + timeEvents := constructTimedEventsWithReceivedMessageEvent(span.EndTimestamp()) + timeEvents.CopyTo(span.Events()) + + filtered, httpData := makeHTTP(span) + + assert.Nil(t, httpData.Request.URL) + assert.Equal(t, "192.168.15.32", *httpData.Request.ClientIP) + assert.Equal(t, "GET", *httpData.Request.Method) + assert.Equal(t, "PostmanRuntime/7.21.0", *httpData.Request.UserAgent) + contentLength := *httpData.Response.ContentLength.(*int64) + assert.Equal(t, int64(12452), contentLength) + assert.Equal(t, int64(200), *httpData.Response.Status) + assert.NotNil(t, filtered) +} + +func TestSpanWithNotEnoughHTTPRequestURLAttributesDuplicated(t *testing.T) { + attributes := make(map[string]any) + attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[AttributeHTTPRequestMethod] = "GET" + attributes[conventions.AttributeHTTPScheme] = "http" + attributes[AttributeURLSchema] = "http" + attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32" + attributes[AttributeClientAddress] = "192.168.15.32" + attributes[conventions.AttributeHTTPUserAgent] = "PostmanRuntime/7.21.0" + attributes[AttributeUserAgentOriginal] = "PostmanRuntime/7.21.0" + attributes[conventions.AttributeHTTPTarget] = "/users/junit" + attributes[AttributeURLPath] = "/users/junit" + attributes[conventions.AttributeNetHostPort] = 443 + attributes[AttributeServerPort] = 443 + attributes[conventions.AttributeNetPeerPort] = 8080 + attributes[AttributeClientPort] = 8080 + attributes[conventions.AttributeHTTPStatusCode] = 200 + attributes[AttributeHTTPResponseStatusCode] = 200 + span := constructHTTPServerSpan(attributes) + timeEvents := constructTimedEventsWithReceivedMessageEvent(span.EndTimestamp()) + timeEvents.CopyTo(span.Events()) + + filtered, httpData := makeHTTP(span) + + assert.Nil(t, httpData.Request.URL) + assert.Equal(t, "192.168.15.32", *httpData.Request.ClientIP) + assert.Equal(t, "GET", *httpData.Request.Method) + assert.Equal(t, "PostmanRuntime/7.21.0", *httpData.Request.UserAgent) + contentLength := *httpData.Response.ContentLength.(*int64) + assert.Equal(t, int64(12452), contentLength) + assert.Equal(t, int64(200), *httpData.Response.Status) + assert.NotNil(t, filtered) +} + func constructHTTPClientSpan(attributes map[string]any) ptrace.Span { endTime := time.Now().Round(time.Second) startTime := endTime.Add(-90 * time.Second) From 29abd36a2f7513a7239198fff58e7f4b6d311886 Mon Sep 17 00:00:00 2001 From: Wang Date: Wed, 7 Feb 2024 17:50:23 -0800 Subject: [PATCH 2/6] add changelog --- ...aws-xray-exporter-http-semconv-stable.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/aws-xray-exporter-http-semconv-stable.yaml diff --git a/.chloggen/aws-xray-exporter-http-semconv-stable.yaml b/.chloggen/aws-xray-exporter-http-semconv-stable.yaml new file mode 100644 index 000000000000..ae61c668d6a7 --- /dev/null +++ b/.chloggen/aws-xray-exporter-http-semconv-stable.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: awsxrayexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: support both deprecated and stable http attributes translation for backward compatibility. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [30935] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] From cd9adf47592a49b9fb378a8661ac35ed951a63a9 Mon Sep 17 00:00:00 2001 From: Wang Date: Fri, 9 Feb 2024 19:01:45 -0800 Subject: [PATCH 3/6] address PR comments --- .../internal/translator/http.go | 13 ++++-- .../internal/translator/http_test.go | 43 +++++++++++++++---- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/http.go b/exporter/awsxrayexporter/internal/translator/http.go index 20dfd6fb3f77..d911871365ec 100644 --- a/exporter/awsxrayexporter/internal/translator/http.go +++ b/exporter/awsxrayexporter/internal/translator/http.go @@ -22,9 +22,10 @@ const ( AttributeNetworkPeerAddress = "network.peer.address" AttributeClientAddress = "client.address" AttributeClientPort = "client.port" - AttributeURLSchema = "url.scheme" + AttributeURLScheme = "url.scheme" AttributeURLFull = "url.full" AttributeURLPath = "url.path" + AttributeURLQuery = "url.query" AttributeUserAgentOriginal = "user_agent.original" ) @@ -51,9 +52,7 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) { info.Request.Method = awsxray.String(value.Str()) hasHTTP = true case conventions.AttributeHTTPClientIP, AttributeClientAddress: - //urlParts[conventions.AttributeHTTPClientIP] = value.Str() info.Request.ClientIP = awsxray.String(value.Str()) - info.Request.XForwardedFor = aws.Bool(true) hasHTTP = true case conventions.AttributeHTTPUserAgent, AttributeUserAgentOriginal: info.Request.UserAgent = awsxray.String(value.Str()) @@ -65,7 +64,7 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) { urlParts[conventions.AttributeHTTPURL] = value.Str() hasHTTP = true hasHTTPRequestURLAttributes = true - case conventions.AttributeHTTPScheme, AttributeURLSchema: + case conventions.AttributeHTTPScheme, AttributeURLScheme: urlParts[conventions.AttributeHTTPScheme] = value.Str() hasHTTP = true case conventions.AttributeHTTPHost, AttributeServerAddress: @@ -111,6 +110,12 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) { return true }) + // if there is no network peer address, then `client.address` is from X-Forwarded-For. + _, ok := urlParts[conventions.AttributeNetPeerIP] + if !ok && info.Request.ClientIP != nil { + info.Request.XForwardedFor = aws.Bool(true) + } + if !hasHTTP { // Didn't have any HTTP-specific information so don't need to fill it in segment return filtered, nil diff --git a/exporter/awsxrayexporter/internal/translator/http_test.go b/exporter/awsxrayexporter/internal/translator/http_test.go index 4b7ac59d1f8c..597ec57b6ca8 100644 --- a/exporter/awsxrayexporter/internal/translator/http_test.go +++ b/exporter/awsxrayexporter/internal/translator/http_test.go @@ -4,6 +4,7 @@ package translator import ( + "github.com/aws/aws-sdk-go/aws" "strings" "testing" "time" @@ -75,7 +76,7 @@ func TestClientSpanWithSchemeHostTargetAttributes(t *testing.T) { func TestClientSpanWithSchemeHostTargetAttributesStable(t *testing.T) { attributes := make(map[string]any) attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLSchema] = "https" + attributes[AttributeURLScheme] = "https" attributes[AttributeServerAddress] = "api.example.com" attributes[AttributeURLPath] = "/users/junit" attributes[AttributeHTTPResponseStatusCode] = 200 @@ -121,7 +122,7 @@ func TestClientSpanWithPeerAttributes(t *testing.T) { func TestClientSpanWithPeerAttributesStable(t *testing.T) { attributes := make(map[string]any) attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLSchema] = "http" + attributes[AttributeURLScheme] = "http" attributes[conventions.AttributeNetPeerName] = "kb234.example.com" attributes[conventions.AttributeNetPeerPort] = 8080 attributes[conventions.AttributeNetPeerIP] = "10.8.17.36" @@ -193,7 +194,7 @@ func TestClientSpanWithPeerIp4Attributes(t *testing.T) { func TestClientSpanWithPeerIp4AttributesStable(t *testing.T) { attributes := make(map[string]any) attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLSchema] = "http" + attributes[AttributeURLScheme] = "http" attributes[AttributeNetworkPeerAddress] = "10.8.17.36" attributes[AttributeClientPort] = "8080" attributes[AttributeURLPath] = "/users/junit" @@ -231,7 +232,7 @@ func TestClientSpanWithPeerIp6Attributes(t *testing.T) { func TestClientSpanWithPeerIp6AttributesStable(t *testing.T) { attributes := make(map[string]any) attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLSchema] = "https" + attributes[AttributeURLScheme] = "https" attributes[AttributeNetworkPeerAddress] = "2001:db8:85a3::8a2e:370:7334" attributes[AttributeClientPort] = "443" attributes[AttributeURLPath] = "/users/junit" @@ -311,7 +312,7 @@ func TestServerSpanWithSchemeHostTargetAttributes(t *testing.T) { func TestServerSpanWithSchemeHostTargetAttributesStable(t *testing.T) { attributes := make(map[string]any) attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLSchema] = "https" + attributes[AttributeURLScheme] = "https" attributes[AttributeServerAddress] = "api.example.com" attributes[AttributeURLPath] = "/users/junit" attributes[AttributeClientAddress] = "192.168.15.32" @@ -354,7 +355,7 @@ func TestServerSpanWithSchemeServernamePortTargetAttributes(t *testing.T) { func TestServerSpanWithSchemeServernamePortTargetAttributesStable(t *testing.T) { attributes := make(map[string]any) attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLSchema] = "https" + attributes[AttributeURLScheme] = "https" attributes[AttributeServerAddress] = "api.example.com" attributes[AttributeServerPort] = 443 attributes[AttributeURLPath] = "/users/junit" @@ -400,7 +401,7 @@ func TestServerSpanWithSchemeNamePortTargetAttributes(t *testing.T) { func TestServerSpanWithSchemeNamePortTargetAttributesStable(t *testing.T) { attributes := make(map[string]any) attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLSchema] = "http" + attributes[AttributeURLScheme] = "http" attributes[AttributeServerAddress] = "kb234.example.com" attributes[AttributeServerPort] = 8080 attributes[AttributeURLPath] = "/users/junit" @@ -450,7 +451,7 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributes(t *testing.T) { func TestSpanWithNotEnoughHTTPRequestURLAttributesStable(t *testing.T) { attributes := make(map[string]any) attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLSchema] = "http" + attributes[AttributeURLScheme] = "http" attributes[AttributeClientAddress] = "192.168.15.32" attributes[AttributeUserAgentOriginal] = "PostmanRuntime/7.21.0" attributes[AttributeURLPath] = "/users/junit" @@ -478,7 +479,7 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributesDuplicated(t *testing.T) { attributes[conventions.AttributeHTTPMethod] = "GET" attributes[AttributeHTTPRequestMethod] = "GET" attributes[conventions.AttributeHTTPScheme] = "http" - attributes[AttributeURLSchema] = "http" + attributes[AttributeURLScheme] = "http" attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32" attributes[AttributeClientAddress] = "192.168.15.32" attributes[conventions.AttributeHTTPUserAgent] = "PostmanRuntime/7.21.0" @@ -507,6 +508,30 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributesDuplicated(t *testing.T) { assert.NotNil(t, filtered) } +func TestSpanWithClientAddrWithoutNetworkPeerAddr(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeClientAddress] = "192.168.15.32" + span := constructHTTPServerSpan(attributes) + timeEvents := constructTimedEventsWithReceivedMessageEvent(span.EndTimestamp()) + timeEvents.CopyTo(span.Events()) + + _, httpData := makeHTTP(span) + + assert.Equal(t, aws.Bool(true), httpData.Request.XForwardedFor) +} +func TestSpanWithClientAddrAndNetworkPeerAddr(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeClientAddress] = "192.168.15.32" + attributes[AttributeNetworkPeerAddress] = "192.168.15.32" + span := constructHTTPServerSpan(attributes) + timeEvents := constructTimedEventsWithReceivedMessageEvent(span.EndTimestamp()) + timeEvents.CopyTo(span.Events()) + + _, httpData := makeHTTP(span) + + assert.Nil(t, httpData.Request.XForwardedFor) +} + func constructHTTPClientSpan(attributes map[string]any) ptrace.Span { endTime := time.Now().Round(time.Second) startTime := endTime.Add(-90 * time.Second) From 904b11b4a9443e702bc491eda6b85fd746522a30 Mon Sep 17 00:00:00 2001 From: Wang Date: Fri, 9 Feb 2024 19:05:07 -0800 Subject: [PATCH 4/6] remove useless const --- exporter/awsxrayexporter/internal/translator/http.go | 1 - 1 file changed, 1 deletion(-) diff --git a/exporter/awsxrayexporter/internal/translator/http.go b/exporter/awsxrayexporter/internal/translator/http.go index d911871365ec..6cb56e00429e 100644 --- a/exporter/awsxrayexporter/internal/translator/http.go +++ b/exporter/awsxrayexporter/internal/translator/http.go @@ -25,7 +25,6 @@ const ( AttributeURLScheme = "url.scheme" AttributeURLFull = "url.full" AttributeURLPath = "url.path" - AttributeURLQuery = "url.query" AttributeUserAgentOriginal = "user_agent.original" ) From 5c38298c87ccdd1d2c7ed68613523fdc0a3a9795 Mon Sep 17 00:00:00 2001 From: Wang Date: Wed, 14 Feb 2024 23:51:56 -0800 Subject: [PATCH 5/6] address comments --- .../internal/translator/http.go | 98 +++++++++++++------ .../internal/translator/http_test.go | 82 ++++------------ 2 files changed, 83 insertions(+), 97 deletions(-) diff --git a/exporter/awsxrayexporter/internal/translator/http.go b/exporter/awsxrayexporter/internal/translator/http.go index 6cb56e00429e..f1f135dafe62 100644 --- a/exporter/awsxrayexporter/internal/translator/http.go +++ b/exporter/awsxrayexporter/internal/translator/http.go @@ -4,6 +4,7 @@ package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter/internal/translator" import ( + "net" "strconv" "github.com/aws/aws-sdk-go/aws" @@ -21,7 +22,6 @@ const ( AttributeServerPort = "server.port" AttributeNetworkPeerAddress = "network.peer.address" AttributeClientAddress = "client.address" - AttributeClientPort = "client.port" AttributeURLScheme = "url.scheme" AttributeURLFull = "url.full" AttributeURLPath = "url.path" @@ -44,13 +44,14 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) { hasHTTP := false hasHTTPRequestURLAttributes := false + hasNetPeerAddr := false span.Attributes().Range(func(key string, value pcommon.Value) bool { switch key { case conventions.AttributeHTTPMethod, AttributeHTTPRequestMethod: info.Request.Method = awsxray.String(value.Str()) hasHTTP = true - case conventions.AttributeHTTPClientIP, AttributeClientAddress: + case conventions.AttributeHTTPClientIP: info.Request.ClientIP = awsxray.String(value.Str()) hasHTTP = true case conventions.AttributeHTTPUserAgent, AttributeUserAgentOriginal: @@ -66,52 +67,75 @@ func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) { case conventions.AttributeHTTPScheme, AttributeURLScheme: urlParts[conventions.AttributeHTTPScheme] = value.Str() hasHTTP = true - case conventions.AttributeHTTPHost, AttributeServerAddress: - urlParts[conventions.AttributeHTTPHost] = value.Str() + case conventions.AttributeHTTPHost: + urlParts[key] = value.Str() hasHTTP = true hasHTTPRequestURLAttributes = true - case conventions.AttributeHTTPTarget, AttributeURLPath: - urlParts[conventions.AttributeHTTPTarget] = value.Str() + case conventions.AttributeHTTPTarget: + urlParts[key] = value.Str() hasHTTP = true - case conventions.AttributeHTTPServerName: // Deprecated, use `server.address` + case conventions.AttributeHTTPServerName: urlParts[key] = value.Str() hasHTTP = true hasHTTPRequestURLAttributes = true - case conventions.AttributeNetHostPort, AttributeServerPort: - urlParts[conventions.AttributeNetHostPort] = value.Str() + case conventions.AttributeNetHostPort: + urlParts[key] = value.Str() hasHTTP = true - if len(urlParts[conventions.AttributeNetHostPort]) == 0 { - urlParts[conventions.AttributeNetHostPort] = strconv.FormatInt(value.Int(), 10) + if len(urlParts[key]) == 0 { + urlParts[key] = strconv.FormatInt(value.Int(), 10) } - case conventions.AttributeHostName: // Deprecated, use `server.address` + case conventions.AttributeHostName: urlParts[key] = value.Str() hasHTTPRequestURLAttributes = true - case conventions.AttributeNetHostName: // Deprecated, use `server.address` + case conventions.AttributeNetHostName: urlParts[key] = value.Str() hasHTTPRequestURLAttributes = true - case conventions.AttributeNetPeerName: // Deprecated, use `client.address` + case conventions.AttributeNetPeerName: urlParts[key] = value.Str() - case conventions.AttributeNetPeerPort, AttributeClientPort: - urlParts[conventions.AttributeNetPeerPort] = value.Str() - if len(urlParts[conventions.AttributeNetPeerPort]) == 0 { + case conventions.AttributeNetPeerPort: + urlParts[key] = value.Str() + if len(urlParts[key]) == 0 { urlParts[key] = strconv.FormatInt(value.Int(), 10) } - case conventions.AttributeNetPeerIP, AttributeNetworkPeerAddress: + case conventions.AttributeNetPeerIP: // Prefer HTTP forwarded information (AttributeHTTPClientIP) when present. if info.Request.ClientIP == nil { info.Request.ClientIP = awsxray.String(value.Str()) } - urlParts[conventions.AttributeNetPeerIP] = value.Str() + urlParts[key] = value.Str() hasHTTPRequestURLAttributes = true + hasNetPeerAddr = true + case AttributeNetworkPeerAddress: + // Prefer HTTP forwarded information (AttributeHTTPClientIP) when present. + if net.ParseIP(value.Str()) != nil { + if info.Request.ClientIP == nil { + info.Request.ClientIP = awsxray.String(value.Str()) + } + hasHTTPRequestURLAttributes = true + hasNetPeerAddr = true + } + case AttributeClientAddress: + if net.ParseIP(value.Str()) != nil { + info.Request.ClientIP = awsxray.String(value.Str()) + } + case AttributeURLPath: + urlParts[key] = value.Str() + hasHTTP = true + case AttributeServerAddress: + urlParts[key] = value.Str() + hasHTTPRequestURLAttributes = true + case AttributeServerPort: + urlParts[key] = value.Str() + if len(urlParts[key]) == 0 { + urlParts[key] = strconv.FormatInt(value.Int(), 10) + } default: filtered[key] = value } return true }) - // if there is no network peer address, then `client.address` is from X-Forwarded-For. - _, ok := urlParts[conventions.AttributeNetPeerIP] - if !ok && info.Request.ClientIP != nil { + if !hasNetPeerAddr && info.Request.ClientIP != nil { info.Request.XForwardedFor = aws.Bool(true) } @@ -161,7 +185,7 @@ func extractResponseSizeFromAttributes(attributes pcommon.Map) int64 { func constructClientURL(urlParts map[string]string) string { // follows OpenTelemetry specification-defined combinations for client spans described in - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-client + // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client url, ok := urlParts[conventions.AttributeHTTPURL] if ok { @@ -200,7 +224,7 @@ func constructClientURL(urlParts map[string]string) string { func constructServerURL(urlParts map[string]string) string { // follows OpenTelemetry specification-defined combinations for server spans described in - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-server-semantic-conventions + // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-server url, ok := urlParts[conventions.AttributeHTTPURL] if ok { @@ -212,19 +236,24 @@ func constructServerURL(urlParts map[string]string) string { if !ok { scheme = "http" } - - port, ok := urlParts[conventions.AttributeNetHostPort] - if !ok { - port = "" - } - + port := "" host, ok := urlParts[conventions.AttributeHTTPHost] if !ok { host, ok = urlParts[conventions.AttributeHTTPServerName] if !ok { host, ok = urlParts[conventions.AttributeNetHostName] if !ok { - host = urlParts[conventions.AttributeHostName] + host, ok = urlParts[conventions.AttributeHostName] + if !ok { + host = urlParts[AttributeServerAddress] + } + } + } + port, ok = urlParts[conventions.AttributeNetHostPort] + if !ok { + port, ok = urlParts[AttributeServerPort] + if !ok { + port = "" } } } @@ -236,7 +265,12 @@ func constructServerURL(urlParts map[string]string) string { if ok { url += target } else { - url += "/" + path, ok := urlParts[AttributeURLPath] + if ok { + url += path + } else { + url += "/" + } } return url } diff --git a/exporter/awsxrayexporter/internal/translator/http_test.go b/exporter/awsxrayexporter/internal/translator/http_test.go index 597ec57b6ca8..4bbea97ab2e8 100644 --- a/exporter/awsxrayexporter/internal/translator/http_test.go +++ b/exporter/awsxrayexporter/internal/translator/http_test.go @@ -73,27 +73,6 @@ func TestClientSpanWithSchemeHostTargetAttributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) } -func TestClientSpanWithSchemeHostTargetAttributesStable(t *testing.T) { - attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLScheme] = "https" - attributes[AttributeServerAddress] = "api.example.com" - attributes[AttributeURLPath] = "/users/junit" - attributes[AttributeHTTPResponseStatusCode] = 200 - attributes["user.id"] = "junit" - span := constructHTTPClientSpan(attributes) - - filtered, httpData := makeHTTP(span) - - assert.NotNil(t, httpData) - assert.NotNil(t, filtered) - w := testWriters.borrow() - require.NoError(t, w.Encode(httpData)) - jsonStr := w.String() - testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://api.example.com/users/junit")) -} - func TestClientSpanWithPeerAttributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -160,6 +139,7 @@ func TestClientSpanWithHttpPeerAttributes(t *testing.T) { func TestClientSpanWithHttpPeerAttributesStable(t *testing.T) { attributes := make(map[string]any) + attributes[AttributeURLFull] = "https://api.example.com/users/junit" attributes[AttributeClientAddress] = "1.2.3.4" attributes[AttributeNetworkPeerAddress] = "10.8.17.36" span := constructHTTPClientSpan(attributes) @@ -191,25 +171,6 @@ func TestClientSpanWithPeerIp4Attributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "http://10.8.17.36:8080/users/junit")) } -func TestClientSpanWithPeerIp4AttributesStable(t *testing.T) { - attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLScheme] = "http" - attributes[AttributeNetworkPeerAddress] = "10.8.17.36" - attributes[AttributeClientPort] = "8080" - attributes[AttributeURLPath] = "/users/junit" - span := constructHTTPClientSpan(attributes) - - filtered, httpData := makeHTTP(span) - assert.NotNil(t, httpData) - assert.NotNil(t, filtered) - w := testWriters.borrow() - require.NoError(t, w.Encode(httpData)) - jsonStr := w.String() - testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "http://10.8.17.36:8080/users/junit")) -} - func TestClientSpanWithPeerIp6Attributes(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -229,25 +190,6 @@ func TestClientSpanWithPeerIp6Attributes(t *testing.T) { assert.True(t, strings.Contains(jsonStr, "https://2001:db8:85a3::8a2e:370:7334/users/junit")) } -func TestClientSpanWithPeerIp6AttributesStable(t *testing.T) { - attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" - attributes[AttributeURLScheme] = "https" - attributes[AttributeNetworkPeerAddress] = "2001:db8:85a3::8a2e:370:7334" - attributes[AttributeClientPort] = "443" - attributes[AttributeURLPath] = "/users/junit" - span := constructHTTPClientSpan(attributes) - - filtered, httpData := makeHTTP(span) - assert.NotNil(t, httpData) - assert.NotNil(t, filtered) - w := testWriters.borrow() - require.NoError(t, w.Encode(httpData)) - jsonStr := w.String() - testWriters.release(w) - assert.True(t, strings.Contains(jsonStr, "https://2001:db8:85a3::8a2e:370:7334/users/junit")) -} - func TestServerSpanWithURLAttribute(t *testing.T) { attributes := make(map[string]any) attributes[conventions.AttributeHTTPMethod] = "GET" @@ -456,7 +398,6 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributesStable(t *testing.T) { attributes[AttributeUserAgentOriginal] = "PostmanRuntime/7.21.0" attributes[AttributeURLPath] = "/users/junit" attributes[AttributeServerPort] = 443 - attributes[AttributeClientPort] = 8080 attributes[AttributeHTTPResponseStatusCode] = 200 span := constructHTTPServerSpan(attributes) timeEvents := constructTimedEventsWithReceivedMessageEvent(span.EndTimestamp()) @@ -489,7 +430,6 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributesDuplicated(t *testing.T) { attributes[conventions.AttributeNetHostPort] = 443 attributes[AttributeServerPort] = 443 attributes[conventions.AttributeNetPeerPort] = 8080 - attributes[AttributeClientPort] = 8080 attributes[conventions.AttributeHTTPStatusCode] = 200 attributes[AttributeHTTPResponseStatusCode] = 200 span := constructHTTPServerSpan(attributes) @@ -510,10 +450,9 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributesDuplicated(t *testing.T) { func TestSpanWithClientAddrWithoutNetworkPeerAddr(t *testing.T) { attributes := make(map[string]any) + attributes[AttributeURLFull] = "https://api.example.com/users/junit" attributes[AttributeClientAddress] = "192.168.15.32" span := constructHTTPServerSpan(attributes) - timeEvents := constructTimedEventsWithReceivedMessageEvent(span.EndTimestamp()) - timeEvents.CopyTo(span.Events()) _, httpData := makeHTTP(span) @@ -521,14 +460,27 @@ func TestSpanWithClientAddrWithoutNetworkPeerAddr(t *testing.T) { } func TestSpanWithClientAddrAndNetworkPeerAddr(t *testing.T) { attributes := make(map[string]any) + attributes[AttributeURLFull] = "https://api.example.com/users/junit" attributes[AttributeClientAddress] = "192.168.15.32" attributes[AttributeNetworkPeerAddress] = "192.168.15.32" span := constructHTTPServerSpan(attributes) - timeEvents := constructTimedEventsWithReceivedMessageEvent(span.EndTimestamp()) - timeEvents.CopyTo(span.Events()) _, httpData := makeHTTP(span) + assert.Equal(t, "192.168.15.32", *httpData.Request.ClientIP) + assert.Nil(t, httpData.Request.XForwardedFor) +} + +func TestSpanWithClientAddrNotIP(t *testing.T) { + attributes := make(map[string]any) + attributes[AttributeURLFull] = "https://api.example.com/users/junit" + attributes[AttributeClientAddress] = "api.example.com" + attributes[AttributeNetworkPeerAddress] = "api.example.com" + span := constructHTTPServerSpan(attributes) + + _, httpData := makeHTTP(span) + + assert.Nil(t, httpData.Request.ClientIP) assert.Nil(t, httpData.Request.XForwardedFor) } From 7c50f23c602f0de1ae2797593b1059f9bab0aee4 Mon Sep 17 00:00:00 2001 From: Lei Wang Date: Tue, 27 Feb 2024 00:05:43 +0000 Subject: [PATCH 6/6] golint fix --- exporter/awsxrayexporter/internal/translator/http_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/awsxrayexporter/internal/translator/http_test.go b/exporter/awsxrayexporter/internal/translator/http_test.go index 4bbea97ab2e8..0c5ff1b9983f 100644 --- a/exporter/awsxrayexporter/internal/translator/http_test.go +++ b/exporter/awsxrayexporter/internal/translator/http_test.go @@ -4,11 +4,11 @@ package translator import ( - "github.com/aws/aws-sdk-go/aws" "strings" "testing" "time" + "github.com/aws/aws-sdk-go/aws" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/pdata/pcommon"