@@ -124,8 +124,10 @@ public class Exporter implements SpanExporter {
124124 private static final AttributeKey <String > AI_LOGGER_NAME_KEY = AttributeKey .stringKey ("applicationinsights.internal.logger_name" );
125125 private static final AttributeKey <String > AI_LOG_ERROR_STACK_KEY = AttributeKey .stringKey ("applicationinsights.internal.log_error_stack" );
126126
127- private static final AttributeKey <String > EVENTHUBS_PEER_ADDRESS = AttributeKey .stringKey ("peer.address" );
128- private static final AttributeKey <String > EVENTHUBS_MESSAGE_BUS_DESTINATION = AttributeKey .stringKey ("message_bus.destination" );
127+ // note: this gets filtered out of user dimensions automatically since it shares official "peer." prefix
128+ // (even though it's not an official semantic convention attribute)
129+ private static final AttributeKey <String > AZURE_SDK_PEER_ADDRESS = AttributeKey .stringKey ("peer.address" );
130+ private static final AttributeKey <String > AZURE_SDK_MESSAGE_BUS_DESTINATION = AttributeKey .stringKey ("message_bus.destination" );
129131
130132 private static final AtomicBoolean alreadyLoggedSamplingPercentageMissing = new AtomicBoolean ();
131133 private static final AtomicBoolean alreadyLoggedSamplingPercentageParseError = new AtomicBoolean ();
@@ -193,7 +195,8 @@ private void export(SpanData span) {
193195 }
194196 } else if (kind == SpanKind .CLIENT || kind == SpanKind .PRODUCER ) {
195197 exportRemoteDependency (span , false );
196- } else if (kind == SpanKind .CONSUMER && !span .getParentSpanContext ().isRemote () && !span .getName ().equals ("EventHubs.process" )) {
198+ } else if (kind == SpanKind .CONSUMER && !span .getParentSpanContext ().isRemote ()
199+ && !span .getName ().equals ("EventHubs.process" ) && !span .getName ().equals ("ServiceBus.process" )) {
197200 // earlier versions of the azure sdk opentelemetry shim did not set remote parent
198201 // see https://github.com/Azure/azure-sdk-for-java/pull/21667
199202
@@ -306,11 +309,19 @@ private void applySemanticConventions(SpanData span, RemoteDependencyTelemetry r
306309 }
307310 // TODO (trask) ideally EventHubs SDK should conform and fit the above path used for other messaging systems
308311 // but no rush as messaging semantic conventions may still change
312+ // https://github.com/Azure/azure-sdk-for-java/issues/21684
309313 String name = span .getName ();
310314 if (name .equals ("EventHubs.send" ) || name .equals ("EventHubs.message" )) {
311315 applyEventHubsSpan (attributes , remoteDependencyData );
312316 return ;
313317 }
318+ // TODO (trask) ideally ServiceBus SDK should conform and fit the above path used for other messaging systems
319+ // but no rush as messaging semantic conventions may still change
320+ // https://github.com/Azure/azure-sdk-for-java/issues/21686
321+ if (name .equals ("ServiceBus.message" ) || name .equals ("ServiceBus.process" )) {
322+ applyServiceBusSpan (attributes , remoteDependencyData );
323+ return ;
324+ }
314325 }
315326
316327 private void exportLogSpan (SpanData span ) {
@@ -521,10 +532,21 @@ private void applyMessagingClientSpan(Attributes attributes, RemoteDependencyTel
521532
522533 // TODO (trask) ideally EventHubs SDK should conform and fit the above path used for other messaging systems
523534 // but no rush as messaging semantic conventions may still change
535+ // https://github.com/Azure/azure-sdk-for-java/issues/21684
524536 private void applyEventHubsSpan (Attributes attributes , RemoteDependencyTelemetry telemetry ) {
525537 telemetry .setType ("Microsoft.EventHub" );
526- String peerAddress = attributes .get (EVENTHUBS_PEER_ADDRESS );
527- String destination = attributes .get (EVENTHUBS_MESSAGE_BUS_DESTINATION );
538+ String peerAddress = attributes .get (AZURE_SDK_PEER_ADDRESS );
539+ String destination = attributes .get (AZURE_SDK_MESSAGE_BUS_DESTINATION );
540+ telemetry .setTarget (peerAddress + "/" + destination );
541+ }
542+
543+ // TODO (trask) ideally ServiceBus SDK should conform and fit the above path used for other messaging systems
544+ // but no rush as messaging semantic conventions may still change
545+ // https://github.com/Azure/azure-sdk-for-java/issues/21686
546+ private void applyServiceBusSpan (Attributes attributes , RemoteDependencyTelemetry telemetry ) {
547+ telemetry .setType ("AZURE SERVICE BUS" );
548+ String peerAddress = attributes .get (AZURE_SDK_PEER_ADDRESS );
549+ String destination = attributes .get (AZURE_SDK_MESSAGE_BUS_DESTINATION );
528550 telemetry .setTarget (peerAddress + "/" + destination );
529551 }
530552
@@ -748,6 +770,12 @@ private static void setExtraAttributes(Telemetry telemetry, Attributes attribute
748770 if (stringKey .startsWith ("applicationinsights.internal." )) {
749771 return ;
750772 }
773+ // TODO use az.namespace for something?
774+ if (stringKey .equals (AZURE_SDK_MESSAGE_BUS_DESTINATION .getKey ())
775+ || stringKey .equals ("az.namespace" )) {
776+ // these are from azure SDK
777+ return ;
778+ }
751779 // special case mappings
752780 if (key .equals (SemanticAttributes .ENDUSER_ID ) && value instanceof String ) {
753781 telemetry .getContext ().getUser ().setId ((String ) value );
0 commit comments