From f62ba96bba50a1ca391066b86988707a44f4df1c Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 20 Oct 2022 11:30:51 -0700 Subject: [PATCH] Add back compat for http.host attribute (#2608) I realized I should have kept backwards compatibility in mind when upgrading to otel 1.19, for (manual) instrumentation that may still be using older semantic convention. --- .../exporter/implementation/SpanDataMapper.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index 27ef5de0d61..318a0cb8de2 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -602,15 +602,20 @@ public static String getHttpUrlFromServerSpan(Attributes attributes) { if (scheme == null) { return null; } - String host = attributes.get(SemanticAttributes.NET_HOST_NAME); - if (host == null) { - return null; - } - Long port = attributes.get(SemanticAttributes.NET_HOST_PORT); String target = attributes.get(SemanticAttributes.HTTP_TARGET); if (target == null) { return null; } + String host = attributes.get(SemanticAttributes.NET_HOST_NAME); + if (host == null) { + // fall back to deprecated http.host if available + host = attributes.get(SemanticAttributes.HTTP_HOST); + if (host == null) { + return null; + } + return scheme + "://" + host + target; + } + Long port = attributes.get(SemanticAttributes.NET_HOST_PORT); if (port != null && port > 0) { return scheme + "://" + host + ":" + port + target; }