Skip to content

Conversation

@zeitlinger
Copy link
Member

@zeitlinger zeitlinger commented Nov 17, 2025

to bridge system properties / env vars to declarative config

Relates #14192

Alternative implementation for #14767

@zeitlinger zeitlinger self-assigned this Nov 17, 2025
@zeitlinger zeitlinger requested a review from a team as a code owner November 17, 2025 17:09
@github-actions github-actions bot added the test native This label can be applied to PRs to trigger them to run native tests label Nov 17, 2025
@zeitlinger
Copy link
Member Author

@trask I really like this new bridge based on your idea 😄

@zeitlinger zeitlinger moved this to Awaiting Review in Declarative Configuration: Java Nov 17, 2025
@zeitlinger zeitlinger changed the title Add system properties bridge Add system properties bridge, part 1 Nov 17, 2025
@zeitlinger zeitlinger force-pushed the system-properties-bridge branch from 3a9e285 to 9ae95f1 Compare November 18, 2025 09:54
@zeitlinger zeitlinger changed the title Add system properties bridge, part 1 Add system properties bridge Nov 18, 2025
Comment on lines 26 to 28
private static final boolean isIncubator = isIncubator();

private static boolean isIncubator() {
Copy link
Member

Choose a reason for hiding this comment

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

maybe supportsDeclarativeConfig? based on comment below it sounds like we'll still need this once it's out of incubation?

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea

Copy link
Member Author

Choose a reason for hiding this comment

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

no, when it's out of incubation, we'll have

  public static boolean isDeclarativeConfig(OpenTelemetry openTelemetry) {
    return openTelemetry instanceof ExtendedOpenTelemetry;
  }

or

  public static boolean isDeclarativeConfig(OpenTelemetry openTelemetry) {
    return openTelemetry.getConfigProvider() != null;
  }

instead of

  public static boolean isDeclarativeConfig(OpenTelemetry openTelemetry) {
    return isIncubator && openTelemetry instanceof ExtendedOpenTelemetry;
  }

depending on how things will evolve.

With the name change, it would be

public static boolean isDeclarativeConfig(OpenTelemetry openTelemetry) {
    return supportsDeclarativeConfig && openTelemetry instanceof ExtendedOpenTelemetry;
  }

which is similar in clarity to what we have now - so I'll go with your proposal

Comment on lines 58 to 59
public static boolean getBoolean(
OpenTelemetry openTelemetry, boolean defaultValue, String... propertyName) {
Copy link
Member

Choose a reason for hiding this comment

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

what about:

public static Optional getBoolean(OpenTelemetry, String...)

then used as:

getBoolean(...).orElse(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it, but I want to keep things consistent - so I'll change it for all methods.

The class in internal, so it's allowed.

Comment on lines +34 to +39
// This only happens in OpenTelemetry API instrumentation tests, where an older version of
// OpenTelemetry API is used that does not have ExtendedOpenTelemetry.
// Having the incubator module without ExtendedOpenTelemetry class should still return false
// for those tests to avoid a ClassNotFoundException.
Copy link
Member

Choose a reason for hiding this comment

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

This only happens in OpenTelemetry API instrumentation tests

these are tests of OpenTelemetry API in the users class loader, so not following how that affects this class which is in the agent?

Copy link
Member Author

Choose a reason for hiding this comment

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

without the check, we get tests where the incubator exists, but is too old to have ExtendedOpenTelemetry:

gradle :instrumentation:opentelemetry-api:opentelemetry-api-1.42:javaagent:incubatorTest

	at io.opentelemetry.instrumentation.api.internal.ConfigPropertiesUtil.isDeclarativeConfig(ConfigPropertiesUtil.java:116)
	at io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder.buildSpanSuppressor(InstrumenterBuilder.java:374)
	at io.opentelemetry.instrumentation.api.instrumenter.Instrumenter.<init>(Instrumenter.java:105)
	at io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder.buildInstrumenter(InstrumenterBuilder.java:298)
	at io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder.buildInstrumenter(InstrumenterBuilder.java:287)
	at io.opentelemetry.instrumentation.testing.TestInstrumenters.<init>(TestInstrumenters.java:41)
	at io.opentelemetry.instrumentation.testing.InstrumentationTestRunner.<init>(InstrumentationTestRunner.java:68)
	at io.opentelemetry.instrumentation.testing.AgentTestRunner.<init>(AgentTestRunner.java:47)
	at io.opentelemetry.instrumentation.testing.AgentTestRunner.<clinit>(AgentTestRunner.java:40)
	at io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension.<init>(AgentInstrumentationExtension.java:35)
	at io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension.create(AgentInstrumentationExtension.java:39)
	at io.opentelemetry.javaagent.instrumentation.opentelemetryapi.v1_42.incubator.logs.LoggerTest.<clinit>(LoggerTest.java:41)
	at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
	at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1160)
	at java.base/java.lang.reflect.Field.acquireOverrideFieldAccessor(Field.java:1200)
	at java.base/java.lang.reflect.Field.getOverrideFieldAccessor(Field.java:1169)
	at java.base/java.lang.reflect.Field.get(Field.java:444)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
	at java.base/java.util.stream.DistinctOps$1$2.end(DistinctOps.java:168)
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:261)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.ClassNotFoundException: io.opentelemetry.api.incubator.ExtendedOpenTelemetry
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	... 29 more

Comment on lines 142 to 128
/** Returns true if the given OpenTelemetry instance supports Declarative Config. */
public static boolean isDeclarativeConfig(OpenTelemetry openTelemetry) {
return isIncubator && openTelemetry instanceof ExtendedOpenTelemetry;
}

Copy link
Member

Choose a reason for hiding this comment

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

is isIncubator needed, since instrumentation-api (unfortunately) already depends on the api-incubator?

Copy link
Member Author

Choose a reason for hiding this comment

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

only for the test (see last comment)

@zeitlinger zeitlinger force-pushed the system-properties-bridge branch from 0138d4f to 16e62ea Compare November 25, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test native This label can be applied to PRs to trigger them to run native tests

Projects

Status: Awaiting Review

Development

Successfully merging this pull request may close these issues.

2 participants