Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve AzMon Trace Exporter support for EventHubs #21668

Merged
merged 9 commits into from
Aug 12, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public final class AzureMonitorTraceExporter implements SpanExporter {
// for ThreadContext.getRequestTelemetryContext().getRequestTelemetry().setSource()
private static final AttributeKey<String> AI_SPAN_SOURCE_KEY = AttributeKey.stringKey("applicationinsights.internal.source");

private static final AttributeKey<String> EVENTHUBS_PEER_ADDRESS = AttributeKey.stringKey("peer.address");
private static final AttributeKey<String> EVENTHUBS_MESSAGE_BUS_DESTINATION = AttributeKey.stringKey("message_bus.destination");

static {
Set<String> dbSystems = new HashSet<>();
dbSystems.add("db2");
Expand Down Expand Up @@ -216,12 +219,10 @@ private void exportRemoteDependency(SpanData span, boolean inProc,
addLinks(remoteDependencyData.getProperties(), span.getLinks());
remoteDependencyData.setName(span.getName());

Attributes attributes = span.getAttributes();

if (inProc) {
remoteDependencyData.setType("InProc");
} else {
applySemanticConventions(attributes, remoteDependencyData, span.getKind());
applySemanticConventions(span, remoteDependencyData);
}

remoteDependencyData.setId(span.getSpanId());
Expand All @@ -237,7 +238,7 @@ private void exportRemoteDependency(SpanData span, boolean inProc,

remoteDependencyData.setSuccess(span.getStatus().getStatusCode() != StatusCode.ERROR);

setExtraAttributes(telemetryItem, remoteDependencyData.getProperties(), attributes);
setExtraAttributes(telemetryItem, remoteDependencyData.getProperties(), span.getAttributes());

// sampling will not be supported in this exporter
Double samplingPercentage = 100.0;
Expand All @@ -246,7 +247,8 @@ private void exportRemoteDependency(SpanData span, boolean inProc,
exportEvents(span, samplingPercentage, telemetryItems);
}

private void applySemanticConventions(Attributes attributes, RemoteDependencyData remoteDependencyData, SpanKind spanKind) {
private void applySemanticConventions(SpanData span, RemoteDependencyData remoteDependencyData) {
Attributes attributes = span.getAttributes();
String httpMethod = attributes.get(AttributeKey.stringKey("http.method"));
if (httpMethod != null) {
applyHttpClientSpan(attributes, remoteDependencyData);
Expand All @@ -264,7 +266,14 @@ private void applySemanticConventions(Attributes attributes, RemoteDependencyDat
}
String messagingSystem = attributes.get(AttributeKey.stringKey("messaging.system"));
if (messagingSystem != null) {
applyMessagingClientSpan(attributes, remoteDependencyData, messagingSystem, spanKind);
applyMessagingClientSpan(attributes, remoteDependencyData, messagingSystem, span.getKind());
return;
}
// 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
String name = span.getName();
if (name.equals("EventHubs.send") || name.equals("EventHubs.message")) {
applyEventHubsSpan(attributes, remoteDependencyData);
return;
}
}
Expand Down Expand Up @@ -404,6 +413,15 @@ private void applyMessagingClientSpan(Attributes attributes, RemoteDependencyDat
}
}

// 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
private void applyEventHubsSpan(Attributes attributes, RemoteDependencyData telemetry) {
telemetry.setType("Microsoft.EventHub");
String peerAddress = attributes.get(EVENTHUBS_PEER_ADDRESS);
String destination = attributes.get(EVENTHUBS_MESSAGE_BUS_DESTINATION);
telemetry.setTarget(peerAddress + "/" + destination);
}

private static int getDefaultPortForDbSystem(String dbSystem) {
switch (dbSystem) {
// TODO (trask) add these default ports to the OpenTelemetry database semantic conventions spec
Expand Down