Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sdk/core/azure-core-tracing-opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Release History
## Version 1.0.0-beta.2 (2019-01-)
Comment thread
samvaity marked this conversation as resolved.
Outdated
- Add eventhub properties to attributes of processing spans.

This package's
[documentation](https://github.com/Azure/azure-sdk-for-java/blob/azure-core-tracing-opentelemetry_1.0.0-beta.2/sdk/core/azure-core-tracing-opentelemetry/README.md)
and
[samples](https://github.com/Azure/azure-sdk-for-java/blob/azure-core-tracing-opentelemetry_1.0.0-beta.2/sdk/core/azure-core-tracing-opentelemetry/src/samples).

## Version 1.0.0-beta.1 (2019-11-26)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ private Context startScopedSpan(String spanName, Context context) {
Builder spanBuilder = getSpanBuilder(spanName, context);
span = spanBuilder.setSpanKind(Span.Kind.SERVER).startSpan();
}
if (span.isRecording()) {
// If span is sampled in, add additional request attributes
addSpanRequestAttributes(span, context, spanName);
}
return context.addData(PARENT_SPAN_KEY, span).addData("scope", TRACER.withSpan(span));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ public void startSpanProcessKindSend() {

// verify span attributes
final Map<String, AttributeValue> attributeMap = recordEventsSpan.toSpanData().getAttributes();
assertEquals(attributeMap.get(COMPONENT), AttributeValue.stringAttributeValue(COMPONENT_VALUE));
assertEquals(attributeMap.get(MESSAGE_BUS_DESTINATION),
AttributeValue.stringAttributeValue(ENTITY_PATH_VALUE));
assertEquals(attributeMap.get(PEER_ENDPOINT), AttributeValue.stringAttributeValue(HOSTNAME_VALUE));
verifySpanAttributes(attributeMap);
}

@Test
Expand All @@ -163,9 +160,11 @@ public void startSpanProcessKindMessage() {
public void startSpanProcessKindProcess() {
// Arrange
final SpanId parentSpanId = parentSpan.getContext().getSpanId();

// Add additional metadata to spans for SEND
final Context traceContext = tracingContext.addData(ENTITY_PATH_KEY, ENTITY_PATH_VALUE)
.addData(HOST_NAME_KEY, HOSTNAME_VALUE);
// Act
final Context updatedContext = openTelemetryTracer.start(METHOD_NAME, tracingContext, ProcessKind.PROCESS);
final Context updatedContext = openTelemetryTracer.start(METHOD_NAME, traceContext, ProcessKind.PROCESS);

// verify no parent span passed
assertFalse(tracingContext.getData(SPAN_CONTEXT_KEY).isPresent(),
Expand All @@ -177,6 +176,9 @@ public void startSpanProcessKindProcess() {
final ReadableSpan recordEventsSpan =
(ReadableSpan) updatedContext.getData(PARENT_SPAN_KEY).get();
assertEquals(Span.Kind.SERVER, recordEventsSpan.toSpanData().getKind());
// verify span attributes
final Map<String, AttributeValue> attributeMap = recordEventsSpan.toSpanData().getAttributes();
verifySpanAttributes(attributeMap);
}

@Test
Expand Down Expand Up @@ -305,4 +307,11 @@ private static void assertSpanWithRemoteParent(Context updatedContext, SpanId pa
assertTrue(recordEventsSpan.toSpanData().getHasRemoteParent());
assertEquals(parentSpanId, recordEventsSpan.toSpanData().getParentSpanId());
}

private static void verifySpanAttributes(Map<String, AttributeValue> attributeMap) {
assertEquals(attributeMap.get(COMPONENT), AttributeValue.stringAttributeValue(COMPONENT_VALUE));
assertEquals(attributeMap.get(MESSAGE_BUS_DESTINATION),
AttributeValue.stringAttributeValue(ENTITY_PATH_VALUE));
assertEquals(attributeMap.get(PEER_ENDPOINT), AttributeValue.stringAttributeValue(HOSTNAME_VALUE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.function.Supplier;

import static com.azure.core.util.tracing.Tracer.DIAGNOSTIC_ID_KEY;
import static com.azure.core.util.tracing.Tracer.ENTITY_PATH_KEY;
import static com.azure.core.util.tracing.Tracer.HOST_NAME_KEY;
import static com.azure.core.util.tracing.Tracer.SCOPE_KEY;
import static com.azure.core.util.tracing.Tracer.SPAN_CONTEXT_KEY;

Expand Down Expand Up @@ -140,7 +142,8 @@ void startPartitionPump(PartitionOwnership claimedOwnership, Checkpoint checkpoi
eventHubConsumer.receiveFromPartition(claimedOwnership.getPartitionId(), startFromEventPosition, receiveOptions)
.subscribe(partitionEvent -> {
EventData eventData = partitionEvent.getData();
Context processSpanContext = startProcessTracingSpan(eventData);
Context processSpanContext = startProcessTracingSpan(eventData, eventHubConsumer.getEventHubName(),
eventHubConsumer.getFullyQualifiedNamespace());
if (processSpanContext.getData(SPAN_CONTEXT_KEY).isPresent()) {
eventData.addContext(SPAN_CONTEXT_KEY, processSpanContext);
}
Expand Down Expand Up @@ -199,15 +202,19 @@ private void handleReceiveError(PartitionOwnership claimedOwnership, EventHubCon
}

/*
* Starts a new process tracing span and attached context the EventData object for users.
* Starts a new process tracing span and attaches the returned context to the EventData object for users.
*/
private Context startProcessTracingSpan(EventData eventData) {
private Context startProcessTracingSpan(EventData eventData, String eventHubName, String fullyQualifiedNamespace) {
Object diagnosticId = eventData.getProperties().get(DIAGNOSTIC_ID_KEY);
if (diagnosticId == null || !tracerProvider.isEnabled()) {
return Context.NONE;
}

Context spanContext = tracerProvider.extractContext(diagnosticId.toString(), Context.NONE);
return tracerProvider.startSpan(spanContext, ProcessKind.PROCESS);
Context entityContext = spanContext.addData(ENTITY_PATH_KEY, eventHubName);

return tracerProvider.startSpan(entityContext.addData(HOST_NAME_KEY, fullyQualifiedNamespace),
ProcessKind.PROCESS);
}

/*
Expand Down