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