Skip to content

Commit 8653b1c

Browse files
committed
- refactor constructor to static method
1 parent 63f5c3a commit 8653b1c

File tree

1 file changed

+14
-7
lines changed
  • instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/log4j/contextdata/v2_17

1 file changed

+14
-7
lines changed

instrumentation/log4j/log4j-context-data/log4j-context-data-2.17/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/log4j/contextdata/v2_17/OpenTelemetryContextDataProvider.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,28 @@
2727
*/
2828
public class OpenTelemetryContextDataProvider implements ContextDataProvider {
2929

30-
private boolean configuredResourceAttributeAccessible;
30+
private static final boolean BAGGAGE_ENABLED =
31+
ConfigPropertiesUtil.getBoolean("otel.instrumentation.log4j-context-data.add-baggage", false);
32+
33+
private static final boolean configuredResourceAttributeAccessible =
34+
isConfiguredResourceAttributeAccessible();
3135

32-
public OpenTelemetryContextDataProvider() {
36+
/**
37+
* Checks whether {@link ConfiguredResourceAttributesHolder} is available in classpath. The result
38+
* is true if {@link ConfiguredResourceAttributesHolder} can be loaded, false otherwise.
39+
*
40+
* @return A boolean
41+
*/
42+
private static boolean isConfiguredResourceAttributeAccessible() {
3343
try {
3444
Class.forName("io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder");
35-
this.configuredResourceAttributeAccessible = true;
45+
return true;
3646

3747
} catch (ClassNotFoundException ok) {
38-
this.configuredResourceAttributeAccessible = false;
48+
return false;
3949
}
4050
}
4151

42-
private static final boolean BAGGAGE_ENABLED =
43-
ConfigPropertiesUtil.getBoolean("otel.instrumentation.log4j-context-data.add-baggage", false);
44-
4552
/**
4653
* Returns context from the current span when available.
4754
*

0 commit comments

Comments
 (0)