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);
}
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)));
}
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"));
}
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));
});
}
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);
}
Aggregations