-
Notifications
You must be signed in to change notification settings - Fork 986
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 2 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 |
---|---|---|
|
@@ -52,9 +52,14 @@ final class DeclarativeConfigPropertiesBridge implements ConfigProperties { | |
|
||
// The node at .instrumentation.java | ||
private final DeclarativeConfigProperties instrumentationJavaNode; | ||
// The node at .instrumentation.java.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. [for reviewer] As I mentioned, we may consider moving it under 'general', so it would be .instrumentation.general.vendor' |
||
private final DeclarativeConfigProperties vendorNode; | ||
|
||
DeclarativeConfigPropertiesBridge(DeclarativeConfigProperties instrumentationNode) { | ||
instrumentationJavaNode = instrumentationNode.getStructured("java", empty()); | ||
vendorNode = | ||
instrumentationJavaNode.getStructured( | ||
"vendor", empty()); // vendor could go to instrumentation.general instead | ||
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 don't love the idea of having a dedicated property called
And then accessing To accomplish this, we could introduce logic which:
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 see your point. Let's think about the other approach - do not make any prefix manipulation for otel.instrumentation.* and nest them in 1:1 yaml structure: instrumentation/development:
java:
otel:
instrumentation:
kafka:
producer-propagation:
enabled: true
micrometer:
histogram-gauges:
enabled: true
acme:
server:
name: "prime" This looks a bit awkward doe to repeating |
||
} | ||
|
||
@Nullable | ||
|
@@ -129,17 +134,22 @@ public Map<String, String> getMap(String propertyName) { | |
|
||
@Nullable | ||
private <T> T getPropertyValue( | ||
String property, BiFunction<DeclarativeConfigProperties, String, T> extractor) { | ||
if (!property.startsWith(OTEL_INSTRUMENTATION_PREFIX)) { | ||
return null; | ||
String propertyName, BiFunction<DeclarativeConfigProperties, String, T> extractor) { | ||
if (!propertyName.startsWith(OTEL_INSTRUMENTATION_PREFIX)) { | ||
return getVendorPropertyValue(propertyName, extractor); | ||
} | ||
String suffix = property.substring(OTEL_INSTRUMENTATION_PREFIX.length()); | ||
// Split the remainder of the property on ".", and walk to the N-1 entry | ||
String[] segments = suffix.split("\\."); | ||
String suffix = propertyName.substring(OTEL_INSTRUMENTATION_PREFIX.length()); | ||
return getPropertyValue(instrumentationJavaNode, suffix, extractor); | ||
} | ||
|
||
private static <T> T getPropertyValue( | ||
DeclarativeConfigProperties target, | ||
String propertyName, | ||
BiFunction<DeclarativeConfigProperties, String, T> extractor) { | ||
String[] segments = propertyName.split("\\."); | ||
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()); | ||
|
@@ -148,4 +158,9 @@ private <T> T getPropertyValue( | |
String lastPart = segments[segments.length - 1]; | ||
return extractor.apply(target, lastPart); | ||
} | ||
|
||
private <T> T getVendorPropertyValue( | ||
String propertyName, BiFunction<DeclarativeConfigProperties, String, T> extractor) { | ||
return getPropertyValue(vendorNode, propertyName, extractor); | ||
} | ||
} |
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