Skip to content
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

Load OTel SDK config from environment variables and system properties.… #1434

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

cyrille-leclerc
Copy link
Member

Description:

Load OTel SDK config from environment variables and system properties.

Existing Issue(s):

Testing:

See added unit tests

Documentation:

< Describe the documentation added.
Please be sure to modify relevant existing documentation if needed. >

Outstanding items:

< Anything that these changes are intentionally missing
that will be needed or can be helpful in the future. >

AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk =
AutoConfiguredOpenTelemetrySdk.builder()
.setServiceClassLoader(getClass().getClassLoader())
.addPropertiesSupplier(() -> properties)
.addPropertiesCustomizer(configProperties -> {
// Change default of "otel.[traces,metrics,logs].exporter" from "otlp" to "none"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] Could you elaborate a bit in a comment on why we need to override the default here ? For example, if I understand correctly when there is no endpoint configured then we assume the extension should silently skip exporting signals.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review Sylvain, please see updated comment

@trask
Copy link
Member

trask commented Sep 16, 2024

@cyrille-leclerc just a heads up looks like there's a failing test

@cyrille-leclerc
Copy link
Member Author

Thanks @trask , unit test fixed.

@trask
Copy link
Member

trask commented Sep 27, 2024

cc @kenfinnigan in case you have a chance to review

@cyrille-leclerc
Copy link
Member Author

@SylvainJuge could you by any chance review this PR?

@trask trask added this to the v1.40.0 milestone Oct 8, 2024
@cyrille-leclerc
Copy link
Member Author

Thanks @SylvainJuge , I'll improve ASAP

@cyrille-leclerc cyrille-leclerc requested a review from a team as a code owner October 18, 2024 10:48
@trask trask removed this from the v1.40.0 milestone Oct 18, 2024
return properties;
}

enum SignalType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] could be made private, also this might be further simplified to an Arrays.asList("traces","metrics","logs").

ConfigProperties configProperties) {

Map<String, String> properties = new HashMap<>();
if (configProperties.getString("otel.exporter.otlp.endpoint") == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor style] given most of the code is within this if statement, then inverting the condition and doing an early return with the debug statement avoids a bit of nesting by doing the "quick path" first.

.disableShutdownHook()
.build();

this.openTelemetrySdk = autoConfiguredOpenTelemetrySdk.getOpenTelemetrySdk();

logger.debug("OpenTelemetry: OpenTelemetrySdkService initialized, resource:{}", resource);

// TODO should we replace `getBooleanConfig(name)` by `configProperties.getBoolean(name)`?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] can we answer this TODO directly into this PR or are there still unknowns there to be answered before being able to do this change ?

System.setProperty("otel.service.name", "my-maven");
try {
testConfiguration("my-maven");
System.setProperty("otel.resource.attributes", "key1=val1,key2=val2");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a bit better to not rely on global state (here in system properties) as we have to take care of the cleanup here.

What I think could be slightly better is to add an argument to the OpenTelemetrySdkService constructor to control which system properties are present or not if we can. While this slightly alters the design for test purpose it could be worth it here as it allows to get rid of any early cleanup or finally block. Also with such a change there can't be any side effect if system properties are set on the JVM that execute the tests which usually require us to ensure properties are not set in some cases.

The AutoConfiguredOpenTelemetrySdkBuilder.setConfigPropertiesCustomizer allows to override the config properties, but it's package-private so using AutoConfigureUtil.setConfigPropertiesCustomizer is needed. While it's an internal API doing this only for tests should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants