diff --git a/agent/exporter/src/main/java/com/microsoft/applicationinsights/agent/Exporter.java b/agent/exporter/src/main/java/com/microsoft/applicationinsights/agent/Exporter.java index e2d99df42e8..88207e2a00c 100644 --- a/agent/exporter/src/main/java/com/microsoft/applicationinsights/agent/Exporter.java +++ b/agent/exporter/src/main/java/com/microsoft/applicationinsights/agent/Exporter.java @@ -124,8 +124,10 @@ public class Exporter implements SpanExporter { private static final AttributeKey AI_LOGGER_NAME_KEY = AttributeKey.stringKey("applicationinsights.internal.logger_name"); private static final AttributeKey AI_LOG_ERROR_STACK_KEY = AttributeKey.stringKey("applicationinsights.internal.log_error_stack"); - private static final AttributeKey EVENTHUBS_PEER_ADDRESS = AttributeKey.stringKey("peer.address"); - private static final AttributeKey EVENTHUBS_MESSAGE_BUS_DESTINATION = AttributeKey.stringKey("message_bus.destination"); + // note: this gets filtered out of user dimensions automatically since it shares official "peer." prefix + // (even though it's not an official semantic convention attribute) + private static final AttributeKey AZURE_SDK_PEER_ADDRESS = AttributeKey.stringKey("peer.address"); + private static final AttributeKey AZURE_SDK_MESSAGE_BUS_DESTINATION = AttributeKey.stringKey("message_bus.destination"); private static final AtomicBoolean alreadyLoggedSamplingPercentageMissing = new AtomicBoolean(); private static final AtomicBoolean alreadyLoggedSamplingPercentageParseError = new AtomicBoolean(); @@ -193,7 +195,8 @@ private void export(SpanData span) { } } else if (kind == SpanKind.CLIENT || kind == SpanKind.PRODUCER) { exportRemoteDependency(span, false); - } else if (kind == SpanKind.CONSUMER && !span.getParentSpanContext().isRemote() && !span.getName().equals("EventHubs.process")) { + } else if (kind == SpanKind.CONSUMER && !span.getParentSpanContext().isRemote() + && !span.getName().equals("EventHubs.process") && !span.getName().equals("ServiceBus.process")) { // earlier versions of the azure sdk opentelemetry shim did not set remote parent // see https://github.com/Azure/azure-sdk-for-java/pull/21667 @@ -306,11 +309,19 @@ private void applySemanticConventions(SpanData span, RemoteDependencyTelemetry r } // TODO (trask) ideally EventHubs SDK should conform and fit the above path used for other messaging systems // but no rush as messaging semantic conventions may still change + // https://github.com/Azure/azure-sdk-for-java/issues/21684 String name = span.getName(); if (name.equals("EventHubs.send") || name.equals("EventHubs.message")) { applyEventHubsSpan(attributes, remoteDependencyData); return; } + // TODO (trask) ideally ServiceBus SDK should conform and fit the above path used for other messaging systems + // but no rush as messaging semantic conventions may still change + // https://github.com/Azure/azure-sdk-for-java/issues/21686 + if (name.equals("ServiceBus.message") || name.equals("ServiceBus.process")) { + applyServiceBusSpan(attributes, remoteDependencyData); + return; + } } private void exportLogSpan(SpanData span) { @@ -521,10 +532,21 @@ private void applyMessagingClientSpan(Attributes attributes, RemoteDependencyTel // TODO (trask) ideally EventHubs SDK should conform and fit the above path used for other messaging systems // but no rush as messaging semantic conventions may still change + // https://github.com/Azure/azure-sdk-for-java/issues/21684 private void applyEventHubsSpan(Attributes attributes, RemoteDependencyTelemetry telemetry) { telemetry.setType("Microsoft.EventHub"); - String peerAddress = attributes.get(EVENTHUBS_PEER_ADDRESS); - String destination = attributes.get(EVENTHUBS_MESSAGE_BUS_DESTINATION); + String peerAddress = attributes.get(AZURE_SDK_PEER_ADDRESS); + String destination = attributes.get(AZURE_SDK_MESSAGE_BUS_DESTINATION); + telemetry.setTarget(peerAddress + "/" + destination); + } + + // TODO (trask) ideally ServiceBus SDK should conform and fit the above path used for other messaging systems + // but no rush as messaging semantic conventions may still change + // https://github.com/Azure/azure-sdk-for-java/issues/21686 + private void applyServiceBusSpan(Attributes attributes, RemoteDependencyTelemetry telemetry) { + telemetry.setType("AZURE SERVICE BUS"); + String peerAddress = attributes.get(AZURE_SDK_PEER_ADDRESS); + String destination = attributes.get(AZURE_SDK_MESSAGE_BUS_DESTINATION); telemetry.setTarget(peerAddress + "/" + destination); } @@ -748,6 +770,12 @@ private static void setExtraAttributes(Telemetry telemetry, Attributes attribute if (stringKey.startsWith("applicationinsights.internal.")) { return; } + // TODO use az.namespace for something? + if (stringKey.equals(AZURE_SDK_MESSAGE_BUS_DESTINATION.getKey()) + || stringKey.equals("az.namespace")) { + // these are from azure SDK + return; + } // special case mappings if (key.equals(SemanticAttributes.ENDUSER_ID) && value instanceof String) { telemetry.getContext().getUser().setId((String) value);