Search in sources :

Example 1 with RecordedStackTrace

use of jdk.jfr.consumer.RecordedStackTrace in project splunk-otel-java by signalfx.

the class TLABProcessorTest method createMockEvent.

private RecordedEvent createMockEvent(StackSerializer serializer, Instant now, Long tlabSize) {
    String stackAsString = "i am a serialized stack believe me";
    RecordedEvent event = mock(RecordedEvent.class);
    RecordedStackTrace stack = mock(RecordedStackTrace.class);
    EventType eventType = mock(EventType.class);
    RecordedThread mockThread = mock(RecordedThread.class);
    when(event.getStartTime()).thenReturn(now);
    when(event.getStackTrace()).thenReturn(stack);
    when(event.getEventType()).thenReturn(eventType);
    when(event.getLong("allocationSize")).thenReturn(ONE_MB);
    when(event.getThread()).thenReturn(mockThread);
    when(mockThread.getJavaThreadId()).thenReturn(THREAD_ID);
    when(mockThread.getJavaName()).thenReturn("mockingbird");
    when(event.hasField("tlabSize")).thenReturn(tlabSize != null);
    if (tlabSize == null) {
        when(event.getLong("tlabSize")).thenThrow(NullPointerException.class);
    } else {
        when(event.getLong("tlabSize")).thenReturn(tlabSize);
    }
    when(eventType.getName()).thenReturn("tee-lab");
    when(serializer.serialize(stack)).thenReturn(stackAsString);
    return event;
}
Also used : EventType(jdk.jfr.EventType) RecordedEvent(jdk.jfr.consumer.RecordedEvent) RecordedStackTrace(jdk.jfr.consumer.RecordedStackTrace) RecordedThread(jdk.jfr.consumer.RecordedThread)

Example 2 with RecordedStackTrace

use of jdk.jfr.consumer.RecordedStackTrace in project splunk-otel-java by signalfx.

the class StackSerializerTest method limitDepth.

@Test
void limitDepth() {
    StackSerializer serializer = new StackSerializer(2);
    RecordedStackTrace stack = mock(RecordedStackTrace.class);
    when(stack.getFrames()).thenReturn(frames);
    String result = serializer.serialize(stack);
    String expected = "\tat io.test.MyClass.silver(unknown:456)\n" + "\tat io.test.Framewerk.root(unknown:66)";
    assertEquals(expected, result);
}
Also used : RecordedStackTrace(jdk.jfr.consumer.RecordedStackTrace) Test(org.junit.jupiter.api.Test)

Example 3 with RecordedStackTrace

use of jdk.jfr.consumer.RecordedStackTrace in project splunk-otel-java by signalfx.

the class StackSerializerTest method serialize.

@Test
void serialize() {
    StackSerializer serializer = new StackSerializer();
    RecordedStackTrace stack = mock(RecordedStackTrace.class);
    when(stack.getFrames()).thenReturn(frames);
    String result = serializer.serialize(stack);
    String expected = "\tat io.test.MyClass.action(unknown:123)\n" + "\tat io.test.MyClass.silver(unknown:456)\n" + "\tat io.test.Framewerk.root(unknown:66)";
    assertEquals(expected, result);
}
Also used : RecordedStackTrace(jdk.jfr.consumer.RecordedStackTrace) Test(org.junit.jupiter.api.Test)

Example 4 with RecordedStackTrace

use of jdk.jfr.consumer.RecordedStackTrace in project splunk-otel-java by signalfx.

the class TLABProcessor method accept.

@Override
public void accept(RecordedEvent event) {
    // them because JFR sends all enabled events to all recordings, if that is the case ignore them.
    if (!enabled) {
        return;
    }
    RecordedStackTrace stackTrace = event.getStackTrace();
    if (stackTrace == null) {
        return;
    }
    // Discard events not chosen by the sampling strategy
    if (sampler != null && !sampler.shouldSample(event)) {
        return;
    }
    Instant time = event.getStartTime();
    String body = buildBody(event, stackTrace);
    AttributesBuilder builder = commonAttributes.builder(event.getEventType().getName()).put(ALLOCATION_SIZE_KEY, event.getLong("allocationSize"));
    if (sampler != null) {
        sampler.addAttributes(builder);
    }
    Attributes attributes = builder.build();
    LogDataBuilder logDataBuilder = LogDataBuilder.create(resource, INSTRUMENTATION_LIBRARY_INFO).setEpoch(time).setBody(body).setAttributes(attributes);
    RecordedThread thread = event.getThread();
    if (thread != null) {
        SpanContext spanContext = spanContextualizer.link(thread.getJavaThreadId()).getSpanContext();
        if (spanContext.isValid()) {
            logDataBuilder.setSpanContext(spanContext);
        }
    }
    logProcessor.emit(logDataBuilder.build());
}
Also used : SpanContext(io.opentelemetry.api.trace.SpanContext) Instant(java.time.Instant) Attributes(io.opentelemetry.api.common.Attributes) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) RecordedStackTrace(jdk.jfr.consumer.RecordedStackTrace) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) RecordedThread(jdk.jfr.consumer.RecordedThread)

Example 5 with RecordedStackTrace

use of jdk.jfr.consumer.RecordedStackTrace in project splunk-otel-java by signalfx.

the class StackSerializerTest method serializeWithNullMethod.

@Test
void serializeWithNullMethod() {
    StackSerializer serializer = new StackSerializer();
    RecordedStackTrace stack = mock(RecordedStackTrace.class);
    when(stack.getFrames()).thenReturn(framesWithNullMethod);
    String result = serializer.serialize(stack);
    String expected = "\tat io.test.MyClass.action(unknown:123)\n" + "\tat unknown.unknown(unknown)\n" + "\tat io.test.Framewerk.root(unknown:66)";
    assertEquals(expected, result);
}
Also used : RecordedStackTrace(jdk.jfr.consumer.RecordedStackTrace) Test(org.junit.jupiter.api.Test)

Aggregations

RecordedStackTrace (jdk.jfr.consumer.RecordedStackTrace)5 Test (org.junit.jupiter.api.Test)3 RecordedThread (jdk.jfr.consumer.RecordedThread)2 Attributes (io.opentelemetry.api.common.Attributes)1 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)1 SpanContext (io.opentelemetry.api.trace.SpanContext)1 LogDataBuilder (io.opentelemetry.sdk.logs.data.LogDataBuilder)1 Instant (java.time.Instant)1 EventType (jdk.jfr.EventType)1 RecordedEvent (jdk.jfr.consumer.RecordedEvent)1