Skip to content

Commit 31bb791

Browse files
author
Liudmila Molkova
authored
Otel plugins: minor logging improvements (Azure#31786)
* Otel metrics: minor logging improvements * noisy tracing logs
1 parent f711924 commit 31bb791

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

sdk/core/azure-core-metrics-opentelemetry/src/main/java/com/azure/core/metrics/opentelemetry/OpenTelemetryUtils.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import static com.azure.core.util.tracing.Tracer.PARENT_TRACE_CONTEXT_KEY;
1515

1616
class OpenTelemetryUtils {
17+
private static boolean warnedOnContextType = false;
18+
private static boolean warnedOnBuilderType = false;
1719
private static final ClientLogger LOGGER = new ClientLogger(OpenTelemetryUtils.class);
1820

1921
/**
@@ -55,11 +57,14 @@ static io.opentelemetry.context.Context getTraceContextOrCurrent(Context azConte
5557
if (traceContextObj instanceof io.opentelemetry.context.Context) {
5658
return (io.opentelemetry.context.Context) traceContextObj;
5759
} else if (traceContextObj != null) {
58-
LOGGER.warning("Expected instance of `io.opentelemetry.context.Context` under `PARENT_TRACE_CONTEXT_KEY`, but got {}, ignoring it.", traceContextObj.getClass().getName());
60+
// TODO (limolkova) somehow we can get shaded otel agent context here
61+
if (!warnedOnContextType) {
62+
LOGGER.warning("Expected instance of `io.opentelemetry.context.Context` under `PARENT_TRACE_CONTEXT_KEY`, but got {}, ignoring it.", traceContextObj.getClass().getName());
63+
warnedOnContextType = true;
64+
}
5965
}
6066
}
6167

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

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

71-
if (attributesBuilder != null) {
76+
if (attributesBuilder != null && !warnedOnBuilderType) {
7277
LOGGER.warning("Expected instance of `OpenTelemetryAttributeBuilder` in `attributeCollection`, but got {}, ignoring it.", attributesBuilder.getClass().getName());
78+
warnedOnBuilderType = true;
7379
}
7480

7581
return Attributes.empty();

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ public AutoCloseable makeSpanCurrent(Context context) {
258258

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

514510
return (T) result;
515511
}

0 commit comments

Comments
 (0)