Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public HttpExporterBuilder<T> copy() {
copy.meterProviderSupplier = meterProviderSupplier;
copy.internalTelemetryVersion = internalTelemetryVersion;
copy.proxyOptions = proxyOptions;
copy.componentLoader = componentLoader;
return copy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,15 @@ void compressionString_usesServiceClassLoader() {
builder.setCompression("none");
assertThat(builder).extracting("compressor").isNull();
}

@Test
void copy_preservesComponentLoader() {
ComponentLoader customComponentLoader =
ComponentLoader.forClassLoader(new URLClassLoader(new URL[0], null));
builder.setComponentLoader(customComponentLoader);

HttpExporterBuilder<Marshaler> copiedBuilder = builder.copy();

assertThat(copiedBuilder).extracting("componentLoader").isEqualTo(customComponentLoader);
}
Comment on lines +94 to +104
Copy link
Owner

Choose a reason for hiding this comment

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

if there aren't other similar tests for other HttpExporter fields, then remove this

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.common.ComponentLoader;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.common.export.MemoryMode;
Expand Down Expand Up @@ -237,4 +238,27 @@ void verifyToBuilderPreservesSettings() {
original.close();
copy.close();
}

@Test
void toBuilderPreservesComponentLoader() {
Copy link
Owner

Choose a reason for hiding this comment

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

why not merge this into above verifyToBuilderPreservesSettings?

// Create a custom component loader that still has access to the necessary classes
// but is different from the default to test preservation
ComponentLoader customComponentLoader =
ComponentLoader.forClassLoader(this.getClass().getClassLoader());

OtlpHttpMetricExporter original =
OtlpHttpMetricExporter.builder()
.setComponentLoader(customComponentLoader)
.setEndpoint("http://localhost:4318/v1/metrics")
.build();

// toBuilder() should preserve the component loader and not throw any class loader related exceptions
OtlpHttpMetricExporter copy = original.toBuilder().build();

// The copy should work without class loader issues
assertThat(copy).isNotNull();

original.close();
copy.close();
}
}