-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load OTel SDK config from environment variables and system properties…
….… (#1434)
- Loading branch information
1 parent
2b6625e
commit bfd7390
Showing
4 changed files
with
236 additions
and
51 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
maven-extension/src/main/java/io/opentelemetry/maven/AutoConfigureUtil2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.maven; | ||
|
||
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
/** Utility class to use the {@link AutoConfiguredOpenTelemetrySdk}. */ | ||
public class AutoConfigureUtil2 { | ||
|
||
private AutoConfigureUtil2() {} | ||
|
||
/** | ||
* Returns the {@link Resource} that was autoconfigured. | ||
* | ||
* <p>Inspired by {@link | ||
* io.opentelemetry.sdk.autoconfigure.internal.AutoConfigureUtil#getConfig(AutoConfiguredOpenTelemetrySdk)} | ||
*/ | ||
public static Resource getResource( | ||
AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) { | ||
try { | ||
Method method = AutoConfiguredOpenTelemetrySdk.class.getDeclaredMethod("getResource"); | ||
method.setAccessible(true); | ||
return (Resource) method.invoke(autoConfiguredOpenTelemetrySdk); | ||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { | ||
throw new IllegalStateException( | ||
"Error calling getResource on AutoConfiguredOpenTelemetrySdk", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
maven-extension/src/test/java/io/opentelemetry/maven/AutoConfigureUtil2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.maven; | ||
|
||
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; | ||
import java.lang.reflect.Method; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class AutoConfigureUtil2Test { | ||
|
||
/** | ||
* Verify the reflection call works with the current version of AutoConfiguredOpenTelemetrySdk. | ||
* | ||
* @throws NoSuchMethodException if the method does not exist | ||
*/ | ||
@Test | ||
void test_getResource() throws NoSuchMethodException { | ||
Method method = AutoConfiguredOpenTelemetrySdk.class.getDeclaredMethod("getResource"); | ||
method.setAccessible(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters