in exporter/awsxrayexporter/internal/translator/http.go [19:146]
func makeHTTP(span ptrace.Span) (map[string]pcommon.Value, *awsxray.HTTPData) {
var (
info = awsxray.HTTPData{
Request: &awsxray.RequestData{},
Response: &awsxray.ResponseData{},
}
filtered = make(map[string]pcommon.Value)
urlParts = make(map[string]string)
)
if span.Attributes().Len() == 0 {
return filtered, nil
}
hasHTTP := false
hasHTTPRequestURLAttributes := false
hasNetPeerAddr := false
for key, value := range span.Attributes().All() {
switch key {
case conventionsv112.AttributeHTTPMethod, conventions.AttributeHTTPRequestMethod:
info.Request.Method = awsxray.String(value.Str())
hasHTTP = true
case conventionsv112.AttributeHTTPClientIP:
info.Request.ClientIP = awsxray.String(value.Str())
hasHTTP = true
case conventionsv112.AttributeHTTPUserAgent, conventions.AttributeUserAgentOriginal:
info.Request.UserAgent = awsxray.String(value.Str())
hasHTTP = true
case conventionsv112.AttributeHTTPStatusCode, conventions.AttributeHTTPResponseStatusCode:
info.Response.Status = aws.Int64(value.Int())
hasHTTP = true
case conventionsv112.AttributeHTTPURL, conventions.AttributeURLFull:
urlParts[conventionsv112.AttributeHTTPURL] = value.Str()
hasHTTP = true
hasHTTPRequestURLAttributes = true
case conventionsv112.AttributeHTTPScheme, conventions.AttributeURLScheme:
urlParts[conventionsv112.AttributeHTTPScheme] = value.Str()
hasHTTP = true
case conventionsv112.AttributeHTTPHost:
urlParts[key] = value.Str()
hasHTTP = true
hasHTTPRequestURLAttributes = true
case conventionsv112.AttributeHTTPTarget, conventions.AttributeURLQuery:
urlParts[conventionsv112.AttributeHTTPTarget] = value.Str()
hasHTTP = true
case conventionsv112.AttributeHTTPServerName:
urlParts[key] = value.Str()
hasHTTP = true
hasHTTPRequestURLAttributes = true
case conventionsv112.AttributeNetHostPort:
urlParts[key] = value.Str()
hasHTTP = true
if len(urlParts[key]) == 0 {
urlParts[key] = strconv.FormatInt(value.Int(), 10)
}
case conventionsv112.AttributeHostName:
urlParts[key] = value.Str()
hasHTTPRequestURLAttributes = true
case conventionsv112.AttributeNetHostName:
urlParts[key] = value.Str()
hasHTTPRequestURLAttributes = true
case conventionsv112.AttributeNetPeerName:
urlParts[key] = value.Str()
hasHTTPRequestURLAttributes = true
case conventionsv112.AttributeNetPeerPort:
urlParts[key] = value.Str()
if len(urlParts[key]) == 0 {
urlParts[key] = strconv.FormatInt(value.Int(), 10)
}
case conventionsv112.AttributeNetPeerIP:
// Prefer HTTP forwarded information (AttributeHTTPClientIP) when present.
if info.Request.ClientIP == nil {
info.Request.ClientIP = awsxray.String(value.Str())
}
urlParts[key] = value.Str()
hasHTTPRequestURLAttributes = true
hasNetPeerAddr = true
case conventions.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 conventions.AttributeClientAddress:
if net.ParseIP(value.Str()) != nil {
info.Request.ClientIP = awsxray.String(value.Str())
}
case conventions.AttributeURLPath:
urlParts[key] = value.Str()
hasHTTP = true
case conventions.AttributeServerAddress:
urlParts[key] = value.Str()
hasHTTPRequestURLAttributes = true
case conventions.AttributeServerPort:
urlParts[key] = value.Str()
if len(urlParts[key]) == 0 {
urlParts[key] = strconv.FormatInt(value.Int(), 10)
}
default:
filtered[key] = value
}
}
if !hasNetPeerAddr && 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
}
if hasHTTPRequestURLAttributes {
if span.Kind() == ptrace.SpanKindServer {
info.Request.URL = awsxray.String(constructServerURL(urlParts))
} else {
info.Request.URL = awsxray.String(constructClientURL(urlParts))
}
}
info.Response.ContentLength = aws.Int64(extractResponseSizeFromEvents(span))
return filtered, &info
}