use of com.splunk.opentelemetry.profiler.context.SpanLinkage 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.SpanLinkage 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 com.splunk.opentelemetry.profiler.context.SpanLinkage in project splunk-otel-java by signalfx.
the class ThreadDumpProcessor method accept.
public void accept(RecordedEvent event) {
String eventName = event.getEventType().getName();
logger.debug("Processing JFR event {}", eventName);
String wallOfStacks = event.getString("result");
ThreadDumpRegion stack = new ThreadDumpRegion(wallOfStacks, 0, 0);
while (stack.findNextStack()) {
if (!stackTraceFilter.test(stack)) {
continue;
}
SpanLinkage linkage = contextualizer.link(stack);
if (onlyTracingSpans && !linkage.getSpanContext().isValid()) {
continue;
}
StackToSpanLinkage spanWithLinkage = new StackToSpanLinkage(event.getStartTime(), stack.getCurrentRegion(), eventName, linkage);
processor.accept(spanWithLinkage);
}
}
Aggregations