Skip to content

Commit f62ba96

Browse files
authored
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.
1 parent a77b14d commit f62ba96

File tree

1 file changed

+10
-5
lines changed
  • agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation

1 file changed

+10
-5
lines changed

agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,20 @@ public static String getHttpUrlFromServerSpan(Attributes attributes) {
602602
if (scheme == null) {
603603
return null;
604604
}
605-
String host = attributes.get(SemanticAttributes.NET_HOST_NAME);
606-
if (host == null) {
607-
return null;
608-
}
609-
Long port = attributes.get(SemanticAttributes.NET_HOST_PORT);
610605
String target = attributes.get(SemanticAttributes.HTTP_TARGET);
611606
if (target == null) {
612607
return null;
613608
}
609+
String host = attributes.get(SemanticAttributes.NET_HOST_NAME);
610+
if (host == null) {
611+
// fall back to deprecated http.host if available
612+
host = attributes.get(SemanticAttributes.HTTP_HOST);
613+
if (host == null) {
614+
return null;
615+
}
616+
return scheme + "://" + host + target;
617+
}
618+
Long port = attributes.get(SemanticAttributes.NET_HOST_PORT);
614619
if (port != null && port > 0) {
615620
return scheme + "://" + host + ":" + port + target;
616621
}

0 commit comments

Comments
 (0)