Skip to content
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

Actually call listeners #421

Merged
merged 3 commits into from
Jun 10, 2024
Merged
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 @@ -337,6 +337,8 @@ OpenTelemetryRum build(ServiceManager serviceManager) {
.setPropagators(buildFinalPropagators())
.build();

otelSdkReadyListeners.forEach(listener -> listener.accept(sdk));

scheduleDiskTelemetryReader(signalFromDiskExporter, diskBufferingConfiguration);

SdkPreconfiguredRumBuilder delegate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.opentelemetry.context.propagation.TextMapGetter;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.contrib.disk.buffering.SpanToDiskExporter;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.sdk.logs.export.SimpleLogRecordProcessor;
import io.opentelemetry.sdk.resources.Resource;
Expand All @@ -56,6 +57,7 @@
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -149,10 +151,6 @@ void shouldInstallInstrumentation() {
verify(listener).onApplicationBackgrounded();
}

private OtelRumConfig buildConfig() {
return new OtelRumConfig().disableNetworkAttributes();
}

@Test
void canAddPropagator() {
Context context = Context.root();
Expand Down Expand Up @@ -256,6 +254,16 @@ void diskBufferingEnabled_when_exception_thrown() {
assertThat(SignalFromDiskExporter.get()).isNull();
}

@Test
void sdkReadyListeners() {
OtelRumConfig config = buildConfig();
AtomicReference<OpenTelemetrySdk> seen = new AtomicReference<>();
OpenTelemetryRum.builder(application, config)
.addOtelSdkReadyListener(seen::set)
.build(mock(ServiceManager.class));
assertThat(seen.get()).isNotNull();
}

@Test
void diskBufferingDisabled() {
ArgumentCaptor<SpanExporter> exporterCaptor = ArgumentCaptor.forClass(SpanExporter.class);
Expand Down Expand Up @@ -336,4 +344,8 @@ private static ServiceManager createServiceManager(Object... services) {
private OpenTelemetryRumBuilder makeBuilder() {
return OpenTelemetryRum.builder(application, buildConfig());
}

private OtelRumConfig buildConfig() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is called in several tests and doesn't simply create a OtelRumConfig instance that just uses the defaults, should the method name indicate that?

return new OtelRumConfig().disableNetworkAttributes().disableSdkInitializationEvents();
}
}