Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- refactor constructor to static method
  • Loading branch information
cleverchuk committed Oct 26, 2023
1 parent 87b61ae commit 744d15d
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,28 @@
*/
public class OpenTelemetryContextDataProvider implements ContextDataProvider {

private boolean configuredResourceAttributeAccessible;
private static final boolean BAGGAGE_ENABLED =
ConfigPropertiesUtil.getBoolean("otel.instrumentation.log4j-context-data.add-baggage", false);

private static final boolean configuredResourceAttributeAccessible =
isConfiguredResourceAttributeAccessible();

public OpenTelemetryContextDataProvider() {
/**
* Checks whether {@link ConfiguredResourceAttributesHolder} is available in classpath. The result
* is true if {@link ConfiguredResourceAttributesHolder} can be loaded, false otherwise.
*
* @return A boolean
*/
private static boolean isConfiguredResourceAttributeAccessible() {
try {
Class.forName("io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder");
this.configuredResourceAttributeAccessible = true;
return true;

} catch (ClassNotFoundException ok) {
this.configuredResourceAttributeAccessible = false;
return false;
}
}

private static final boolean BAGGAGE_ENABLED =
ConfigPropertiesUtil.getBoolean("otel.instrumentation.log4j-context-data.add-baggage", false);

/**
* Returns context from the current span when available.
*
Expand Down

0 comments on commit 744d15d

Please sign in to comment.