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