Skip to content

Commit a1c1c26

Browse files
authored
Support sampling on az.namespace attribute (#42548)
1 parent 9e796fa commit a1c1c26

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.
@@ -148,16 +150,15 @@ public Context start(String spanName, StartSpanOptions options, Context context)
148150
spanBuilder.setStartTimestamp(options.getStartTimestamp());
149151
}
150152

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

160+
Span span = spanBuilder.startSpan();
161+
161162
return context.addData(PARENT_TRACE_CONTEXT_KEY,
162163
(traceContext != null ? traceContext : io.opentelemetry.context.Context.current()).with(span));
163164
}

0 commit comments

Comments
 (0)