diff --git a/input/otlp/traces.go b/input/otlp/traces.go index 29dd1145..e98b3581 100644 --- a/input/otlp/traces.go +++ b/input/otlp/traces.go @@ -75,6 +75,9 @@ const ( attributeServerAddress = "server.address" attributeServerPort = "server.port" attributeUrlFull = "url.full" + attributeUrlScheme = "url.scheme" + attributeUrlPath = "url.path" + attributeUrlQuery = "url.query" attributeUserAgentOriginal = "user_agent.original" attributeDbElasticsearchClusterName = "db.elasticsearch.cluster.name" attributeStackTrace = "code.stacktrace" // semconv 1.24 or later @@ -255,6 +258,8 @@ func TranslateTransaction( http modelpb.HTTP httpRequest modelpb.HTTPRequest httpResponse modelpb.HTTPResponse + urlPath string + urlQuery string ) var isHTTP, isRPC, isMessaging bool @@ -304,7 +309,7 @@ func TranslateTransaction( event.Source = modelpb.SourceFromVTPool() } event.Source.Port = uint32(v.Int()) - case semconv.AttributeNetHostPort: + case semconv.AttributeNetHostPort, attributeServerPort: netHostPort = int(v.Int()) case semconv.AttributeRPCGRPCStatusCode: isRPC = true @@ -324,10 +329,16 @@ func TranslateTransaction( case semconv.AttributeHTTPURL, semconv.AttributeHTTPTarget, "http.path": isHTTP = true httpURL = stringval + case attributeUrlPath: + isHTTP = true + urlPath = stringval + case attributeUrlQuery: + isHTTP = true + urlQuery = stringval case semconv.AttributeHTTPHost: isHTTP = true httpHost = stringval - case semconv.AttributeHTTPScheme: + case semconv.AttributeHTTPScheme, attributeUrlScheme: isHTTP = true httpScheme = stringval case semconv.AttributeHTTPStatusCode, attributeHttpResponseStatusCode: @@ -376,7 +387,7 @@ func TranslateTransaction( event.Source = modelpb.SourceFromVTPool() } event.Source.Domain = stringval - case semconv.AttributeNetHostName: + case semconv.AttributeNetHostName, attributeServerAddress: netHostName = stringval case attributeNetworkConnectionType: if event.Network == nil { @@ -450,11 +461,6 @@ func TranslateTransaction( case semconv.AttributeRPCService: case semconv.AttributeRPCMethod: - // URL - case attributeUrlFull: - isHTTP = true - httpURL = stringval - // miscellaneous case "type": event.Transaction.Type = stringval @@ -515,7 +521,6 @@ func TranslateTransaction( } } - // Build the modelpb.URL from http{URL,Host,Scheme}. httpHost := httpHost if httpHost == "" { httpHost = httpServerName @@ -529,8 +534,20 @@ func TranslateTransaction( httpHost = net.JoinHostPort(httpHost, strconv.Itoa(netHostPort)) } } + + // Build a relative url from the UrlPath and UrlQuery. + httpURL := httpURL + if httpURL == "" && urlPath != "" { + httpURL = urlPath + if urlQuery != "" { + httpURL += "?" + urlQuery + } + } + + // Build the modelpb.URL from http{URL,Host,Scheme}. event.Url = modelpb.ParseURL(httpURL, httpHost, httpScheme) } + if isMessaging { // Overwrite existing event.Transaction.Message event.Transaction.Message = nil @@ -555,6 +572,7 @@ func TranslateTransaction( if event.Transaction.Result == "" { event.Transaction.Result = spanStatusResult(spanStatus) } + if name := library.Name(); name != "" { if event.Service == nil { event.Service = modelpb.ServiceFromVTPool() diff --git a/input/otlp/traces_test.go b/input/otlp/traces_test.go index 42eca9cf..b3fda2bf 100644 --- a/input/otlp/traces_test.go +++ b/input/otlp/traces_test.go @@ -253,17 +253,32 @@ func TestHTTPTransactionURL(t *testing.T) { "http.target": "/foo", }) }) - t.Run("url.full", func(t *testing.T) { + t.Run("url_attributes", func(t *testing.T) { test(t, &modelpb.URL{ Scheme: "https", - Original: "https://testing.invalid:80/foo?bar", - Full: "https://testing.invalid:80/foo?bar", + Original: "/foo", + Full: "https://test.domain/foo", + Path: "/foo", + Domain: "test.domain", + }, map[string]interface{}{ + "url.scheme": "https", + "server.address": "test.domain", + "url.path": "/foo", + }) + }) + t.Run("url_attributes_with_query", func(t *testing.T) { + test(t, &modelpb.URL{ + Scheme: "https", + Original: "/foo?bar", + Full: "https://test.domain/foo?bar", Path: "/foo", Query: "bar", - Domain: "testing.invalid", - Port: 80, + Domain: "test.domain", }, map[string]interface{}{ - "url.full": "https://testing.invalid:80/foo?bar", + "url.scheme": "https", + "server.address": "test.domain", + "url.path": "/foo", + "url.query": "bar", }) }) }