instrumentation config: return empty object when not set#4817
instrumentation config: return empty object when not set#4817carlosalberto merged 5 commits intoopen-telemetry:mainfrom
Conversation
36d7304 to
a4f2070
Compare
|
I agree that it doesn’t matter whether However, I don’t agree that Even though this change does not affect functionality, from my perspective I don’t see why it is needed. There is no clear benefit in having an empty object when we can use |
It's a matter of API consistency. If some methods return empty objects and some return null, it's more difficult for consumers of the API to know which is which and when they should check for null and when they shouldn't. I pushed for non-null to match with other methods on the configuration objects. Consistency in an API is important; parallel methods should return the same types. Either all nulls, or all empty objects, but not an arbitrary mix of both. |
I think there are a couple of assumptions here:
(btw, I do agree that some languages make dealing with nulls easier)
yeah, this is also a big usability issue we ran into when migrating the Java Instrumentation to the declarative configuration API to avoid this in Java, we added an additional convenience accessor to ConfigProperties which returns nested mappings or empty, so that we can just chain without checking for null at each step, and we only need to check the final scalar value |
this is an example: @Bean
static SpringKafkaTelemetry getTelemetry(ObjectProvider<OpenTelemetry> openTelemetryProvider) {
OpenTelemetry openTelemetry = openTelemetryProvider.getObject();
return SpringKafkaTelemetry.builder(openTelemetry)
.setCaptureExperimentalSpanAttributes(
DeclarativeConfigUtil.getInstrumentationConfig(openTelemetry, "kafka")
.getBoolean("experimental_span_attributes/development", false))
.setMessagingReceiveTelemetryEnabled(
DeclarativeConfigUtil.getInstrumentationConfig(openTelemetry, "common")
.get("messaging")
.get("receive_telemetry/development")
.getBoolean("enabled", false))
.setCapturedHeaders(
DeclarativeConfigUtil.getInstrumentationConfig(openTelemetry, "common")
.get("messaging")
.getScalarList("capture_headers/development", String.class, emptyList()))
.build();
} |
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Co-authored-by: Jack Berg <34418638+jack-berg@users.noreply.github.com>
### Context - Deprecate Jaeger propagator and make propagator implementation optional. ([#4827](#4827)) - Deprecate OT Trace propagator and make propagator implementation optional. ([#4851](#4851)) ### Metrics - Add normative language to the Metrics API/SDK spec concurrency requirements. ([#4868](#4868)) ### Logs - Add optional `Exception` parameter to Emit LogRecord. ([#4824](#4824)) - Add normative language to the Logging API/SDK spec concurrency requirements. ([#4885](#4885)) ### Resource - Refine the handling of OTEL_RESOURCE_ATTRIBUTES. ([#4856](#4856)) ### Common - Add string representation guidance for complex attribute value types (byte arrays, empty values, arrays, and maps) for non-OTLP protocols. ([#4848](#4848)) ### Compatibility - Stabilize Prometheus Counter to OTLP Sum transformation. ([#4862](#4862)) - Stabilize Prometheus Gauge to OTLP Gauge transformation. ([#4871](#4871)) ### SDK Configuration - Swap Tracer/Meter/LoggerConfig `disabled` for `enabled` to avoid double negatives ([#4823](#4823)) - Declarative configuration: rename `ComponentProvider` to `PluginComponentProvider`, `CreatePlugin` to `CreateComponent` in effort to use consistent vocabulary ([#4806](#4806)) - Declarative configuration: Update instrumentation config behavior to return empty object when not set ([#4817](#4817))
Fixes open-telemetry/opentelemetry-java#7958
Changes
While working on Java, it has turned out to be more convenient to work with empty config objects rather than null/nil.
.instrumentationis missing or is empty, which is a different question than "is declarative config used")CHANGELOG.mdfile updated for non-trivial changes