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

handling http semantic convention breaking changes in v1.23.0 #31120

Merged
merged 9 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 27 additions & 0 deletions .chloggen/aws-xray-exporter-http-semconv-stable.yaml
Original file line number Diff line number Diff line change
@@ -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]
76 changes: 46 additions & 30 deletions exporter/awsxrayexporter/internal/translator/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
AttributeURLFull = "url.full"
AttributeURLPath = "url.path"
AttributeUserAgentOriginal = "user_agent.original"
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
)

func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) {
var (
info = awsxray.HTTPData{
Expand All @@ -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()
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
info.Request.ClientIP = awsxray.String(value.Str())
info.Request.XForwardedFor = aws.Bool(true)
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
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()
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
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:
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
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()
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
hasHTTP = true
case conventions.AttributeHTTPServerName:
case conventions.AttributeHTTPServerName: // Deprecated, use `server.address`
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
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:
wangzlei marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -193,7 +208,12 @@ func constructServerURL(urlParts map[string]string) string {
if !ok {
scheme = "http"
}
port := ""

port, ok := urlParts[conventions.AttributeNetHostPort]
if !ok {
port = ""
}

wangzlei marked this conversation as resolved.
Show resolved Hide resolved
host, ok := urlParts[conventions.AttributeHTTPHost]
if !ok {
host, ok = urlParts[conventions.AttributeHTTPServerName]
Expand All @@ -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") {
Expand Down
Loading
Loading