Skip to content

Commit

Permalink
Actually call listeners (#421)
Browse files Browse the repository at this point in the history
* pass sdk to listeners

* spotless

* fix test
  • Loading branch information
breedx-splk authored Jun 10, 2024
1 parent a371094 commit fdadc56
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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() {
return new OtelRumConfig().disableNetworkAttributes().disableSdkInitializationEvents();
}
}

0 comments on commit fdadc56

Please sign in to comment.