Search in sources :

Example 1 with RecordedThread

use of jdk.jfr.consumer.RecordedThread 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 RecordedThread

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

the class ThreadDumpProcessorTest method threadContextStartEvent.

private static RecordedEvent threadContextStartEvent(long threadId) {
    RecordedEvent event = mock(RecordedEvent.class);
    EventType type = mock(EventType.class);
    when(type.getName()).thenReturn(ContextAttached.EVENT_NAME);
    when(event.getEventType()).thenReturn(type);
    when(event.getString("traceId")).thenReturn(traceId);
    when(event.getString("spanId")).thenReturn(spanId);
    when(event.getByte("traceFlags")).thenReturn(traceFlags);
    RecordedThread thread = mock(RecordedThread.class);
    when(thread.getJavaThreadId()).thenReturn(threadId);
    when(event.getThread()).thenReturn(thread);
    return event;
}
Also used : EventType(jdk.jfr.EventType) RecordedEvent(jdk.jfr.consumer.RecordedEvent) RecordedThread(jdk.jfr.consumer.RecordedThread)

Example 3 with RecordedThread

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

the class SpanContextualizerTest method contextEvent.

private static RecordedEvent contextEvent(String traceId, String spanId, long threadId) {
    RecordedEvent event = mock(RecordedEvent.class);
    EventType type = mock(EventType.class);
    when(type.getName()).thenReturn(ContextAttached.EVENT_NAME);
    when(event.getEventType()).thenReturn(type);
    when(event.getString("traceId")).thenReturn(traceId);
    when(event.getString("spanId")).thenReturn(spanId);
    RecordedThread thread = mock(RecordedThread.class);
    when(thread.getJavaThreadId()).thenReturn(threadId);
    when(event.getThread()).thenReturn(thread);
    return event;
}
Also used : EventType(jdk.jfr.EventType) RecordedEvent(jdk.jfr.consumer.RecordedEvent) RecordedThread(jdk.jfr.consumer.RecordedThread)

Example 4 with RecordedThread

use of jdk.jfr.consumer.RecordedThread 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 RecordedThread

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

the class TLABProcessor method buildBody.

private String buildBody(RecordedEvent event, RecordedStackTrace stackTrace) {
    String stack = stackSerializer.serialize(stackTrace);
    RecordedThread thread = event.getThread();
    String name = thread == null ? "unknown" : thread.getJavaName();
    long id = thread == null ? 0 : thread.getJavaThreadId();
    return "\"" + name + "\"" + " #" + id + "\n" + "   java.lang.Thread.State: UNKNOWN\n" + stack;
}
Also used : RecordedThread(jdk.jfr.consumer.RecordedThread)

Aggregations

RecordedThread (jdk.jfr.consumer.RecordedThread)5 EventType (jdk.jfr.EventType)3 RecordedEvent (jdk.jfr.consumer.RecordedEvent)3 RecordedStackTrace (jdk.jfr.consumer.RecordedStackTrace)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