-
Notifications
You must be signed in to change notification settings - Fork 944
feat(config): Add exporter customizers for declarative config (#6576) #8081
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
Open
MikeGoldsmith
wants to merge
12
commits into
open-telemetry:main
Choose a base branch
from
honeycombio:mike/exporter-customizers-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c5dab10
Add exporter customizers for declarative config (#6576)
MikeGoldsmith c4e927e
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java i…
MikeGoldsmith 52c4f98
Add null handling tests for metric and log exporter customizers
MikeGoldsmith c95e072
Pass builder to context instead of separate setters
MikeGoldsmith ea75471
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java i…
MikeGoldsmith eab2d56
feat(config): Improve exporter customizer contract for declarative co…
MikeGoldsmith 3e7f252
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java i…
MikeGoldsmith d456639
Refactor exporter customizers: Customizer class, throw on null, setBu…
MikeGoldsmith d66ee82
Add customizer tests to exporter factory tests
MikeGoldsmith 7f35762
Fix existing tests: file_format version and setBuilder
MikeGoldsmith 091f3cb
Merge branch 'main' of github.com:open-telemetry/opentelemetry-java i…
MikeGoldsmith d977871
Close original exporter in maybeCustomize when replaced by customizer
MikeGoldsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationBuilderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
| import io.opentelemetry.sdk.logs.export.LogRecordExporter; | ||
| import io.opentelemetry.sdk.metrics.export.MetricExporter; | ||
| import io.opentelemetry.sdk.trace.export.SpanExporter; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class DeclarativeConfigurationBuilderTest { | ||
|
|
||
| @Test | ||
| void spanExporterCustomizer_Single() { | ||
| DeclarativeConfigurationBuilder builder = new DeclarativeConfigurationBuilder(); | ||
|
|
||
| builder.addSpanExporterCustomizer( | ||
| SpanExporter.class, (exporter, properties) -> mock(SpanExporter.class)); | ||
|
|
||
| assertThat(builder.getSpanExporterCustomizers()).hasSize(1); | ||
| } | ||
|
|
||
| @Test | ||
| void spanExporterCustomizer_Multiple_Compose() { | ||
| DeclarativeConfigurationBuilder builder = new DeclarativeConfigurationBuilder(); | ||
|
|
||
| builder.addSpanExporterCustomizer( | ||
| SpanExporter.class, (exporter, properties) -> mock(SpanExporter.class)); | ||
| builder.addSpanExporterCustomizer( | ||
| SpanExporter.class, (exporter, properties) -> mock(SpanExporter.class)); | ||
|
|
||
| assertThat(builder.getSpanExporterCustomizers()).hasSize(2); | ||
| } | ||
|
|
||
| @Test | ||
| void metricExporterCustomizer_Single() { | ||
| DeclarativeConfigurationBuilder builder = new DeclarativeConfigurationBuilder(); | ||
|
|
||
| builder.addMetricExporterCustomizer( | ||
| MetricExporter.class, (exporter, properties) -> mock(MetricExporter.class)); | ||
|
|
||
| assertThat(builder.getMetricExporterCustomizers()).hasSize(1); | ||
| } | ||
|
|
||
| @Test | ||
| void metricExporterCustomizer_Multiple_Compose() { | ||
| DeclarativeConfigurationBuilder builder = new DeclarativeConfigurationBuilder(); | ||
|
|
||
| builder.addMetricExporterCustomizer( | ||
| MetricExporter.class, (exporter, properties) -> mock(MetricExporter.class)); | ||
| builder.addMetricExporterCustomizer( | ||
| MetricExporter.class, (exporter, properties) -> mock(MetricExporter.class)); | ||
|
|
||
| assertThat(builder.getMetricExporterCustomizers()).hasSize(2); | ||
| } | ||
|
|
||
| @Test | ||
| void logRecordExporterCustomizer_Single() { | ||
| DeclarativeConfigurationBuilder builder = new DeclarativeConfigurationBuilder(); | ||
|
|
||
| builder.addLogRecordExporterCustomizer( | ||
| LogRecordExporter.class, (exporter, properties) -> mock(LogRecordExporter.class)); | ||
|
|
||
| assertThat(builder.getLogRecordExporterCustomizers()).hasSize(1); | ||
| } | ||
|
|
||
| @Test | ||
| void logRecordExporterCustomizer_Multiple_Compose() { | ||
| DeclarativeConfigurationBuilder builder = new DeclarativeConfigurationBuilder(); | ||
|
|
||
| builder.addLogRecordExporterCustomizer( | ||
| LogRecordExporter.class, (exporter, properties) -> mock(LogRecordExporter.class)); | ||
| builder.addLogRecordExporterCustomizer( | ||
| LogRecordExporter.class, (exporter, properties) -> mock(LogRecordExporter.class)); | ||
|
|
||
| assertThat(builder.getLogRecordExporterCustomizers()).hasSize(2); | ||
| } | ||
|
|
||
| @Test | ||
| void customizer_ClosesOriginalWhenReplaced() throws Exception { | ||
| SpanExporter original = mock(SpanExporter.class); | ||
| SpanExporter replacement = mock(SpanExporter.class); | ||
| DeclarativeConfigProperties props = mock(DeclarativeConfigProperties.class); | ||
|
|
||
| DeclarativeConfigurationBuilder.Customizer<SpanExporter> customizer = | ||
| new DeclarativeConfigurationBuilder.Customizer<>( | ||
| SpanExporter.class, (exporter, properties) -> replacement); | ||
|
|
||
| SpanExporter result = customizer.maybeCustomize(original, "test", props); | ||
|
|
||
| assertThat(result).isSameAs(replacement); | ||
| verify(original).close(); | ||
| } | ||
|
|
||
| @Test | ||
| void customizer_DoesNotCloseWhenSameInstance() throws Exception { | ||
| SpanExporter exporter = mock(SpanExporter.class); | ||
| DeclarativeConfigProperties props = mock(DeclarativeConfigProperties.class); | ||
|
|
||
| DeclarativeConfigurationBuilder.Customizer<SpanExporter> customizer = | ||
| new DeclarativeConfigurationBuilder.Customizer<>(SpanExporter.class, (e, properties) -> e); | ||
|
|
||
| SpanExporter result = customizer.maybeCustomize(exporter, "test", props); | ||
|
|
||
| assertThat(result).isSameAs(exporter); | ||
| verify(exporter, never()).close(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.