Search in sources :

Example 1 with StackToSpanLinkage

use of com.splunk.opentelemetry.profiler.context.StackToSpanLinkage in project splunk-otel-java by signalfx.

the class LogDataCreatorTest method testCreate.

@Test
void testCreate() {
    Instant time = Instant.now();
    String stack = "the.stack";
    SpanContext spanContext = SpanContext.create("deadbeefdeadbeefdeadbeefdeadbeef", "0123012301230123", TraceFlags.getSampled(), TraceState.getDefault());
    Context context = Context.root().with(Span.wrap(spanContext));
    long threadId = 987L;
    String eventName = "GoodEventHere";
    EventPeriods periods = mock(EventPeriods.class);
    when(periods.getDuration(eventName)).thenReturn(Duration.ofMillis(606));
    SpanLinkage linkage = new SpanLinkage(spanContext, threadId);
    Resource resource = Resource.getDefault();
    Attributes attributes = Attributes.of(SOURCE_EVENT_NAME, eventName, SOURCE_EVENT_PERIOD, 606L, SOURCE_TYPE, "otel.profiling");
    LogData expected = LogDataBuilder.create(resource, INSTRUMENTATION_LIBRARY_INFO).setContext(context).setBody(stack).setEpoch(time).setAttributes(attributes).build();
    StackToSpanLinkage linkedSpan = new StackToSpanLinkage(time, "the.stack", eventName, linkage);
    LogDataCreator creator = new LogDataCreator(new LogDataCommonAttributes(periods), Resource.getDefault());
    LogData result = creator.apply(linkedSpan);
    assertEquals(expected, result);
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) EventPeriods(com.splunk.opentelemetry.profiler.events.EventPeriods) LogData(io.opentelemetry.sdk.logs.data.LogData) StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) SpanContext(io.opentelemetry.api.trace.SpanContext) StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) SpanLinkage(com.splunk.opentelemetry.profiler.context.SpanLinkage) Instant(java.time.Instant) Resource(io.opentelemetry.sdk.resources.Resource) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 2 with StackToSpanLinkage

use of com.splunk.opentelemetry.profiler.context.StackToSpanLinkage in project splunk-otel-java by signalfx.

the class ThreadDumpProcessorTest method testFilterStacksWithoutSpans.

@Test
void testFilterStacksWithoutSpans() {
    SpanContextualizer contextualizer = new SpanContextualizer();
    sampleThreadsFromDump.forEach(it -> contextualizer.updateContext(threadContextStartEvent(it.threadId)));
    String threadDump = readDumpFromResource("thread-dump1.txt");
    List<StackToSpanLinkage> results = collectResults(contextualizer, threadDump, true);
    assertEquals(sampleThreadsFromDump.size(), results.size());
    sampleThreadsFromDump.forEach(sample -> assertThat(results).anyMatch(stack -> stack.getRawStack().contains(sample.threadName)));
}
Also used : TraceFlags(io.opentelemetry.api.trace.TraceFlags) Arrays(java.util.Arrays) SpanContext(io.opentelemetry.api.trace.SpanContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Consumer(java.util.function.Consumer) RecordedEvent(jdk.jfr.consumer.RecordedEvent) Test(org.junit.jupiter.api.Test) TraceState(io.opentelemetry.api.trace.TraceState) List(java.util.List) ThreadDumpRegionTest.readDumpFromResource(com.splunk.opentelemetry.profiler.ThreadDumpRegionTest.readDumpFromResource) Stream(java.util.stream.Stream) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RecordedThread(jdk.jfr.consumer.RecordedThread) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ContextAttached(com.splunk.opentelemetry.profiler.events.ContextAttached) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EventType(jdk.jfr.EventType) Mockito.mock(org.mockito.Mockito.mock) StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Test(org.junit.jupiter.api.Test)

Example 3 with StackToSpanLinkage

use of com.splunk.opentelemetry.profiler.context.StackToSpanLinkage in project splunk-otel-java by signalfx.

the class ThreadDumpProcessorTest method testProcessEvent.

@Test
void testProcessEvent() {
    SpanContextualizer contextualizer = new SpanContextualizer();
    long idOfThreadRunningTheSpan = 3L;
    SpanContext expectedContext = SpanContext.create(traceId, spanId, TraceFlags.fromByte(traceFlags), TraceState.getDefault());
    contextualizer.updateContext(threadContextStartEvent(idOfThreadRunningTheSpan));
    String threadDump = readDumpFromResource("thread-dump2.txt");
    List<StackToSpanLinkage> results = collectResults(contextualizer, threadDump, false);
    assertEquals(3, results.size());
    assertFalse(results.get(0).hasSpanInfo());
    assertTrue(results.get(0).getRawStack().contains("at java.lang.ref.Reference$ReferenceHandler"));
    assertTrue(results.get(1).hasSpanInfo());
    assertEquals(expectedContext, results.get(1).getSpanContext());
    assertEquals(idOfThreadRunningTheSpan, results.get(1).getSpanStartThread());
    assertTrue(results.get(1).getRawStack().contains("AwesomeThinger.overHereDoingSpanThings"));
    assertFalse(results.get(2).hasSpanInfo());
    assertTrue(results.get(2).getRawStack().contains("0x0000000625152778"));
}
Also used : StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) SpanContext(io.opentelemetry.api.trace.SpanContext) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Test(org.junit.jupiter.api.Test)

Example 4 with StackToSpanLinkage

use of com.splunk.opentelemetry.profiler.context.StackToSpanLinkage in project splunk-otel-java by signalfx.

the class ThreadDumpProcessorTest method testFilterInternalStacks.

@Test
void testFilterInternalStacks() {
    SpanContextualizer contextualizer = new SpanContextualizer();
    String threadDump = readDumpFromResource("thread-dump1.txt");
    List<StackToSpanLinkage> results = collectResults(contextualizer, threadDump, false);
    assertEquals(28, results.size());
    Stream.of(StackTraceFilter.UNWANTED_PREFIXES).forEach(prefix -> {
        assertThat(results).noneMatch(stack -> stack.getRawStack().contains(prefix));
    });
}
Also used : StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Test(org.junit.jupiter.api.Test)

Example 5 with StackToSpanLinkage

use of com.splunk.opentelemetry.profiler.context.StackToSpanLinkage in project splunk-otel-java by signalfx.

the class ThreadDumpProcessorBenchmark method buildOldThreadDumpProcessor.

private static com.splunk.opentelemetry.profiler.old.ThreadDumpProcessor buildOldThreadDumpProcessor() {
    SpanContextualizer contextualizer = new SpanContextualizer();
    Consumer<StackToSpanLinkage> processor = x -> {
    };
    Predicate<String> filter = new AgentInternalsFilter();
    return new com.splunk.opentelemetry.profiler.old.ThreadDumpProcessor(contextualizer, processor, filter);
}
Also used : Setup(org.openjdk.jmh.annotations.Setup) RecordingFile(jdk.jfr.consumer.RecordingFile) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) Scope(org.openjdk.jmh.annotations.Scope) State(org.openjdk.jmh.annotations.State) Benchmark(org.openjdk.jmh.annotations.Benchmark) ArrayList(java.util.ArrayList) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer) Consumer(java.util.function.Consumer) RecordedEvent(jdk.jfr.consumer.RecordedEvent) AgentInternalsFilter(com.splunk.opentelemetry.profiler.old.AgentInternalsFilter) List(java.util.List) Level(org.openjdk.jmh.annotations.Level) Path(java.nio.file.Path) AgentInternalsFilter(com.splunk.opentelemetry.profiler.old.AgentInternalsFilter) StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) SpanContextualizer(com.splunk.opentelemetry.profiler.context.SpanContextualizer)

Aggregations

StackToSpanLinkage (com.splunk.opentelemetry.profiler.context.StackToSpanLinkage)9 SpanContextualizer (com.splunk.opentelemetry.profiler.context.SpanContextualizer)5 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)4 RecordedEvent (jdk.jfr.consumer.RecordedEvent)4 SpanContext (io.opentelemetry.api.trace.SpanContext)3 List (java.util.List)3 Consumer (java.util.function.Consumer)3 SpanLinkage (com.splunk.opentelemetry.profiler.context.SpanLinkage)2 AgentInternalsFilter (com.splunk.opentelemetry.profiler.old.AgentInternalsFilter)2 LogData (io.opentelemetry.sdk.logs.data.LogData)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Instant (java.time.Instant)2 Predicate (java.util.function.Predicate)2 EventType (jdk.jfr.EventType)2 RecordingFile (jdk.jfr.consumer.RecordingFile)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 Level (org.openjdk.jmh.annotations.Level)2 Scope (org.openjdk.jmh.annotations.Scope)2