Skip to content

Commit 427d095

Browse files
committed
Support sampling on az.namespace attribute
1 parent 882b322 commit 427d095

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sdk/core/azure-core-tracing-opentelemetry/src/main/java/com/azure/core/tracing/opentelemetry/OpenTelemetryTracer.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.function.BiConsumer;
3232
import java.util.function.Function;
3333

34+
import static java.util.Collections.singletonMap;
35+
3436
/**
3537
* Basic tracing implementation class for use with REST and AMQP Service Clients to create {@link Span} and in-process
3638
* context propagation. Singleton OpenTelemetry tracer capable of starting and exporting spans.
@@ -150,16 +152,15 @@ public Context start(String spanName, StartSpanOptions options, Context context)
150152
spanBuilder.setStartTimestamp(options.getStartTimestamp());
151153
}
152154

153-
Span span = spanBuilder.startSpan();
154-
if (span.isRecording()) {
155-
// If span is sampled in, add additional attributes
156-
157-
String tracingNamespace = getAzNamespace(context);
158-
if (tracingNamespace != null) {
159-
OpenTelemetryUtils.addAttribute(span, AZ_TRACING_NAMESPACE_KEY, tracingNamespace);
160-
}
155+
String tracingNamespace = getAzNamespace(context);
156+
if (tracingNamespace != null) {
157+
Attributes attributes
158+
= OpenTelemetryUtils.convert(singletonMap(AZ_TRACING_NAMESPACE_KEY, tracingNamespace));
159+
spanBuilder.setAllAttributes(attributes);
161160
}
162161

162+
Span span = spanBuilder.startSpan();
163+
163164
return context.addData(PARENT_TRACE_CONTEXT_KEY,
164165
(traceContext != null ? traceContext : io.opentelemetry.context.Context.current()).with(span));
165166
}

0 commit comments

Comments
 (0)