-
Notifications
You must be signed in to change notification settings - Fork 987
Vendor specific instrumentation config options handling #14016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
16da1b0
c707f0e
73b1797
506425b
8e03ae6
6940b8c
c01877c
f7be9c8
7375716
6d0f85a
f413172
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.extension; | ||
|
||
import io.opentelemetry.api.incubator.config.ConfigProvider; | ||
import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; | ||
import io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
|
||
// TODO: Add unit test | ||
public class ConfigPropertiesUtil { | ||
private ConfigPropertiesUtil() {} | ||
|
||
/** Resolve {@link ConfigProperties} from the {@code autoConfiguredOpenTelemetrySdk}. */ | ||
public static ConfigProperties resolveConfigProperties( | ||
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) { | ||
ConfigProperties sdkConfigProperties = | ||
AutoConfigureUtil.getConfig(autoConfiguredOpenTelemetrySdk); | ||
if (sdkConfigProperties != null) { | ||
return sdkConfigProperties; | ||
} | ||
ConfigProvider configProvider = | ||
AutoConfigureUtil.getConfigProvider(autoConfiguredOpenTelemetrySdk); | ||
if (configProvider != null) { | ||
DeclarativeConfigProperties instrumentationConfig = configProvider.getInstrumentationConfig(); | ||
|
||
if (instrumentationConfig != null) { | ||
return new DeclarativeConfigPropertiesBridge(instrumentationConfig); | ||
} | ||
robsunday marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
// Should never happen | ||
throw new IllegalStateException( | ||
"AutoConfiguredOpenTelemetrySdk does not have ConfigProperties or DeclarativeConfigProperties. This is likely a programming error in opentelemetry-java"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,30 @@ public Map<String, String> getMap(String propertyName) { | |
@Nullable | ||
private <T> T getPropertyValue( | ||
String property, BiFunction<DeclarativeConfigProperties, String, T> extractor) { | ||
T value = getOtelPropertyValue(property, extractor); | ||
if (value == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could achieve this same effect without duplicating the logic to split on |
||
value = getVendorPropertyValue(property, extractor); | ||
} | ||
return value; | ||
} | ||
|
||
@Nullable | ||
private <T> T getPropertyValue( | ||
String[] segments, BiFunction<DeclarativeConfigProperties, String, T> extractor) { | ||
|
||
DeclarativeConfigProperties target = instrumentationJavaNode; | ||
if (segments.length > 1) { | ||
for (int i = 0; i < segments.length - 1; i++) { | ||
target = target.getStructured(segments[i], empty()); | ||
} | ||
} | ||
String lastPart = segments[segments.length - 1]; | ||
return extractor.apply(target, lastPart); | ||
} | ||
|
||
@Nullable | ||
private <T> T getOtelPropertyValue( | ||
String property, BiFunction<DeclarativeConfigProperties, String, T> extractor) { | ||
if (!property.startsWith(OTEL_INSTRUMENTATION_PREFIX)) { | ||
return null; | ||
} | ||
|
@@ -139,13 +163,18 @@ private <T> T getPropertyValue( | |
if (segments.length == 0) { | ||
return null; | ||
} | ||
DeclarativeConfigProperties target = instrumentationJavaNode; | ||
if (segments.length > 1) { | ||
for (int i = 0; i < segments.length - 1; i++) { | ||
target = target.getStructured(segments[i], empty()); | ||
} | ||
|
||
return getPropertyValue(segments, extractor); | ||
} | ||
|
||
@Nullable | ||
private <T> T getVendorPropertyValue( | ||
String property, BiFunction<DeclarativeConfigProperties, String, T> extractor) { | ||
String[] segments = property.split("\\."); | ||
if (segments.length == 0) { | ||
return null; | ||
} | ||
String lastPart = segments[segments.length - 1]; | ||
return extractor.apply(target, lastPart); | ||
|
||
return getPropertyValue(segments, extractor); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,10 @@ class DeclarativeConfigPropertiesBridgeTest { | |
+ " map_key:\n" | ||
+ " string_key1: value1\n" | ||
+ " string_key2: value2\n" | ||
+ " bool_key: true\n"; | ||
+ " bool_key: true\n" | ||
+ " acme:\n" | ||
+ " full_name:\n" | ||
+ " preserved: true"; | ||
|
||
private ConfigProperties bridge; | ||
private ConfigProperties emptyBridge; | ||
|
@@ -132,5 +135,12 @@ void getProperties() { | |
.isEqualTo(Arrays.asList("value1", "value2")); | ||
assertThat(bridge.getMap("otel.instrumentation.other-instrumentation.map_key", expectedMap)) | ||
.isEqualTo(expectedMap); | ||
|
||
// verify vendor specific property names are preserved in unchanged form (prefix is not stripped | ||
// as for otel.instrumentation.*) | ||
assertThat(bridge.getBoolean("acme.full_name.preserved")).isTrue(); | ||
// Example of property name collision: | ||
assertThat(bridge.getBoolean("acme.full_name.preserved")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] This is the downside of the approach without .vendor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems alright to me. What do @open-telemetry/java-instrumentation-approvers think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like a good compromise to me 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it 👍 |
||
.isEqualTo(bridge.getBoolean("otel.instrumentation.acme.full_name.preserved")); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] This was extracted to separate public class (see ConfigPropertiesUtil) so can be used also for BeforeAgentListener's