-
Notifications
You must be signed in to change notification settings - Fork 0
Fix HttpExporterBuilder.copy() to preserve componentLoader field #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…orService Co-authored-by: trask <[email protected]>
Co-authored-by: trask <[email protected]>
OtlpMetricExporterProvider
to dynamically inject authentication headers, calling OtlpHttpMetricExporter.toBuilder()
causes a classloader mismatch.
The HttpExporterBuilder.copy()
method used internally does no...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Don't copy executor service
@copilot don't copy over the executor service |
…uested Co-authored-by: trask <[email protected]>
Done. Removed the executorService copying from HttpExporterBuilder.copy() method and its associated test. Only the componentLoader field is now preserved to fix the class loader mismatch issue. See commit 26f9e7d.
Done. Removed the executorService copying from HttpExporterBuilder.copy() method and its associated test. Only the componentLoader field is now preserved to fix the class loader mismatch issue. See commit 26f9e7d. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
||
@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); | ||
} |
There was a problem hiding this comment.
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
@@ -237,4 +238,27 @@ void verifyToBuilderPreservesSettings() { | |||
original.close(); | |||
copy.close(); | |||
} | |||
|
|||
@Test | |||
void toBuilderPreservesComponentLoader() { |
There was a problem hiding this comment.
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
?
Summary
Fixes a class loader mismatch issue in
OtlpHttpMetricExporter.toBuilder()
where theHttpExporterBuilder.copy()
method was not preserving thecomponentLoader
field, causing new instances to use default values instead of the original configuration.Problem
When extending
OtlpMetricExporterProvider
to dynamically inject authentication headers, callingOtlpHttpMetricExporter.toBuilder()
caused a class loader mismatch. The issue occurred because:ComponentLoader
(e.g.,MultipleParentClassLoader
in agent scenarios)toBuilder()
internally callsHttpExporterBuilder.copy()
copy()
method was not preserving thecomponentLoader
fieldAgentClassLoader
insteadExample usage that failed before this fix:
Solution
Fixed the
HttpExporterBuilder.copy()
method to preserve thecomponentLoader
field:Note: The
executorService
field is intentionally not copied to allow each exporter instance to manage its own executor lifecycle.Testing
Added comprehensive tests to verify the fix:
HttpExporterBuilderTest
to ensurecopy()
preserves the componentLoader fieldOtlpHttpMetricExporterBuilderTest
to verifytoBuilder()
works correctly with custom component loadersThe fix ensures that when
toBuilder()
is called on an OTLP HTTP exporter, the resulting builder maintains the same component loader configuration, preventing class loader mismatches in agent environments.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.