use of io.opentelemetry.instrumentation.api.config.Config in project splunk-otel-java by signalfx.
the class LogExporterBuilderTest method testCustomEndpoint.
@Test
void testCustomEndpoint() {
String endpoint = "http://example.com:9122/";
Config config = mock(Config.class);
OtlpGrpcLogExporterBuilder builder = mock(OtlpGrpcLogExporterBuilder.class);
OtlpGrpcLogExporter expected = mock(OtlpGrpcLogExporter.class);
when(builder.addHeader(EXTRA_CONTENT_TYPE, STACKTRACES_HEADER_VALUE)).thenReturn(builder);
when(builder.build()).thenReturn(expected);
when(config.getString(Configuration.CONFIG_KEY_OTEL_OTLP_URL, null)).thenReturn("http://shadowed.example.com:9122/");
when(config.getString(Configuration.CONFIG_KEY_INGEST_URL, "http://shadowed.example.com:9122/")).thenReturn(endpoint);
LogExporter exporter = LogExporterBuilder.fromConfig(config, () -> builder);
assertNotNull(exporter);
verify(builder).setEndpoint(endpoint);
}
use of io.opentelemetry.instrumentation.api.config.Config in project splunk-otel-java by signalfx.
the class TLABProcessorTest method tlabProcessTest.
private void tlabProcessTest(Long tlabSize) {
Instant now = Instant.now();
AtomicReference<LogData> seenLogData = new AtomicReference<>();
LogProcessor consumer = seenLogData::set;
String stackAsString = "\"mockingbird\" #606\n" + " java.lang.Thread.State: UNKNOWN\n" + "i am a serialized stack believe me";
StackSerializer serializer = mock(StackSerializer.class);
LogDataCommonAttributes commonAttrs = new LogDataCommonAttributes(new EventPeriods(x -> null));
Clock clock = new MockClock(now);
RecordedEvent event = createMockEvent(serializer, now, tlabSize);
Config config = mock(Config.class);
when(config.getBoolean(CONFIG_KEY_TLAB_ENABLED, DEFAULT_MEMORY_ENABLED)).thenReturn(true);
SpanContext spanContext = SpanContext.create(TraceId.fromLongs(123, 456), SpanId.fromLong(123), TraceFlags.getSampled(), TraceState.getDefault());
SpanContextualizer spanContextualizer = mock(SpanContextualizer.class);
when(spanContextualizer.link(THREAD_ID)).thenReturn(new SpanLinkage(spanContext, THREAD_ID));
TLABProcessor processor = TLABProcessor.builder(config).stackSerializer(serializer).logProcessor(consumer).commonAttributes(commonAttrs).resource(Resource.getDefault()).spanContextualizer(spanContextualizer).build();
processor.accept(event);
assertEquals(stackAsString, seenLogData.get().getBody().asString());
assertEquals(TimeUnit.SECONDS.toNanos(now.getEpochSecond()) + clock.nanoTime(), seenLogData.get().getEpochNanos());
assertEquals("otel.profiling", seenLogData.get().getAttributes().get(SOURCE_TYPE));
assertEquals("tee-lab", seenLogData.get().getAttributes().get(SOURCE_EVENT_NAME));
assertEquals(ONE_MB, seenLogData.get().getAttributes().get(ALLOCATION_SIZE_KEY));
assertEquals(spanContext, seenLogData.get().getSpanContext());
}
use of io.opentelemetry.instrumentation.api.config.Config in project splunk-otel-java by signalfx.
the class TLABProcessorTest method testSampling.
@Test
void testSampling() {
int samplerInterval = 5;
AtomicReference<LogData> seenLogData = new AtomicReference<>();
LogProcessor consumer = seenLogData::set;
StackSerializer serializer = mock(StackSerializer.class);
LogDataCommonAttributes commonAttrs = new LogDataCommonAttributes(new EventPeriods(x -> null));
SpanContextualizer spanContextualizer = mock(SpanContextualizer.class);
when(spanContextualizer.link(anyLong())).thenReturn(SpanLinkage.NONE);
Config config = mock(Config.class);
when(config.getBoolean(CONFIG_KEY_TLAB_ENABLED, DEFAULT_MEMORY_ENABLED)).thenReturn(true);
when(config.getInt(CONFIG_KEY_MEMORY_SAMPLER_INTERVAL, DEFAULT_MEMORY_SAMPLING_INTERVAL)).thenReturn(samplerInterval);
TLABProcessor processor = TLABProcessor.builder(config).stackSerializer(serializer).logProcessor(consumer).commonAttributes(commonAttrs).resource(Resource.getDefault()).spanContextualizer(spanContextualizer).build();
RecordedEvent event = createMockEvent(serializer, Instant.now(), null);
for (int i = 0; i < samplerInterval + 2; i++) {
processor.accept(event);
if (i % samplerInterval == 0) {
assertEquals("otel.profiling", seenLogData.get().getAttributes().get(SOURCE_TYPE));
assertEquals("tee-lab", seenLogData.get().getAttributes().get(SOURCE_EVENT_NAME));
assertEquals("Systematic sampler", seenLogData.get().getAttributes().get(SAMPLER_NAME_KEY));
assertEquals(Long.valueOf(samplerInterval), seenLogData.get().getAttributes().get(SAMPLER_INTERVAL_KEY));
} else {
assertNull(seenLogData.get());
}
seenLogData.set(null);
}
}
use of io.opentelemetry.instrumentation.api.config.Config in project splunk-otel-java by signalfx.
the class ConfigurationTest method getTLABEnabled_override.
@Test
void getTLABEnabled_override() {
Config config = mock(Config.class);
when(config.getBoolean(Configuration.CONFIG_KEY_MEMORY_ENABLED, Configuration.DEFAULT_MEMORY_ENABLED)).thenReturn(false);
when(config.getBoolean(Configuration.CONFIG_KEY_TLAB_ENABLED, false)).thenReturn(true);
boolean result = Configuration.getTLABEnabled(config);
assertTrue(result);
}
use of io.opentelemetry.instrumentation.api.config.Config in project splunk-otel-java by signalfx.
the class ConfigurationTest method getTLABEnabled_inheritedTrue.
@Test
void getTLABEnabled_inheritedTrue() {
Config config = mock(Config.class);
when(config.getBoolean(Configuration.CONFIG_KEY_MEMORY_ENABLED, Configuration.DEFAULT_MEMORY_ENABLED)).thenReturn(true);
when(config.getBoolean(Configuration.CONFIG_KEY_TLAB_ENABLED, true)).thenReturn(true);
boolean result = Configuration.getTLABEnabled(config);
assertTrue(result);
}
Aggregations