use of io.opentelemetry.sdk.trace.IdGenerator in project opentelemetry-java by open-telemetry.
the class AutoConfiguredOpenTelemetrySdkTest method builder_addTracerProviderCustomizer.
@Test
void builder_addTracerProviderCustomizer() {
when(idGenerator.generateTraceId()).thenReturn(TraceId.fromLongs(9999999999L, 9999999999L));
when(idGenerator.generateSpanId()).thenReturn(SpanId.fromLong(9999999999L));
Span span = builder.addTracerProviderCustomizer((tracerProviderBuilder, config) -> tracerProviderBuilder.setIdGenerator(idGenerator)).build().getOpenTelemetrySdk().getTracer("test").spanBuilder("name").startSpan();
assertThat(span.getSpanContext().getSpanId()).isEqualTo(SpanId.fromLong(9999999999L));
assertThat(span.getSpanContext().getTraceId()).isEqualTo(TraceId.fromLongs(9999999999L, 9999999999L));
span.end();
}
use of io.opentelemetry.sdk.trace.IdGenerator in project opentelemetry-java by open-telemetry.
the class OpenTelemetrySdkTest method testConfiguration_tracerSettings.
@Test
void testConfiguration_tracerSettings() {
Resource resource = Resource.create(Attributes.builder().put("cat", "meow").build());
IdGenerator idGenerator = mock(IdGenerator.class);
SpanLimits spanLimits = SpanLimits.getDefault();
OpenTelemetrySdk openTelemetry = OpenTelemetrySdk.builder().setTracerProvider(SdkTracerProvider.builder().setClock(clock).setResource(resource).setIdGenerator(idGenerator).setSpanLimits(spanLimits).build()).build();
TracerProvider unobfuscatedTracerProvider = ((OpenTelemetrySdk.ObfuscatedTracerProvider) openTelemetry.getTracerProvider()).unobfuscate();
assertThat(unobfuscatedTracerProvider).isInstanceOfSatisfying(SdkTracerProvider.class, sdkTracerProvider -> assertThat(sdkTracerProvider.getSpanLimits()).isEqualTo(spanLimits));
// Since TracerProvider is in a different package, the only alternative to this reflective
// approach would be to make the fields public for testing which is worse than this.
assertThat(unobfuscatedTracerProvider).extracting("sharedState").hasFieldOrPropertyWithValue("clock", clock).hasFieldOrPropertyWithValue("resource", resource).hasFieldOrPropertyWithValue("idGenerator", idGenerator);
}
Aggregations