Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import static com.azure.core.util.tracing.Tracer.PARENT_TRACE_CONTEXT_KEY;

class OpenTelemetryUtils {
private static boolean warnedOnContextType = false;
private static boolean warnedOnBuilderType = false;
private static final ClientLogger LOGGER = new ClientLogger(OpenTelemetryUtils.class);

/**
Expand Down Expand Up @@ -55,11 +57,14 @@ static io.opentelemetry.context.Context getTraceContextOrCurrent(Context azConte
if (traceContextObj instanceof io.opentelemetry.context.Context) {
return (io.opentelemetry.context.Context) traceContextObj;
} else if (traceContextObj != null) {
LOGGER.warning("Expected instance of `io.opentelemetry.context.Context` under `PARENT_TRACE_CONTEXT_KEY`, but got {}, ignoring it.", traceContextObj.getClass().getName());
// TODO (limolkova) somehow we can get shaded otel agent context here
if (!warnedOnContextType) {
LOGGER.warning("Expected instance of `io.opentelemetry.context.Context` under `PARENT_TRACE_CONTEXT_KEY`, but got {}, ignoring it.", traceContextObj.getClass().getName());
warnedOnContextType = true;
}
}
}

LOGGER.verbose("No context is found under `PARENT_TRACE_CONTEXT_KEY`, getting current context");
return io.opentelemetry.context.Context.current();
}

Expand All @@ -68,8 +73,9 @@ static Attributes getAttributes(TelemetryAttributes attributesBuilder) {
return ((OpenTelemetryAttributes) attributesBuilder).get();
}

if (attributesBuilder != null) {
if (attributesBuilder != null && !warnedOnBuilderType) {
LOGGER.warning("Expected instance of `OpenTelemetryAttributeBuilder` in `attributeCollection`, but got {}, ignoring it.", attributesBuilder.getClass().getName());
warnedOnBuilderType = true;
}

return Attributes.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ public AutoCloseable makeSpanCurrent(Context context) {

io.opentelemetry.context.Context traceContext = getTraceContextOrDefault(context, null);
if (traceContext == null) {
LOGGER.verbose("There is no OpenTelemetry Context on the context, cannot make it current");
return NOOP_CLOSEABLE;
}
return traceContext.makeCurrent();
Expand Down Expand Up @@ -506,10 +505,7 @@ private void addMessagingAttributes(Span span, Context context) {
@SuppressWarnings("unchecked")
private static <T> T getOrNull(Context context, String key, Class<T> clazz) {
final Optional<Object> optional = context.getData(key);
final Object result = optional.filter(value -> clazz.isAssignableFrom(value.getClass())).orElseGet(() -> {
LOGGER.verbose("Could not extract key '{}' of type '{}' from context.", key, clazz);
return null;
});
final Object result = optional.filter(value -> clazz.isAssignableFrom(value.getClass())).orElse(null);

return (T) result;
}
Expand Down