use of com.splunk.opentelemetry.profiler.events.ContextAttached in project splunk-otel-java by signalfx.
the class JfrContextStorageTest method testNewEvent.
@Test
void testNewEvent() {
ContextAttached result = JfrContextStorage.newEvent(spanContext);
assertEquals(traceId, result.getTraceId());
assertEquals(spanId, result.getSpanId());
}
use of com.splunk.opentelemetry.profiler.events.ContextAttached in project splunk-otel-java by signalfx.
the class JfrContextStorage method generateEvent.
private void generateEvent(Span span) {
SpanContext context = span.getSpanContext();
ContextAttached event = newEvent.apply(context);
event.begin();
if (event.shouldCommit()) {
event.commit();
}
}
use of com.splunk.opentelemetry.profiler.events.ContextAttached in project splunk-otel-java by signalfx.
the class JfrContextStorageTest method testAttachLifecycle.
@Test
void testAttachLifecycle() {
ContextAttached inEvent = mock(ContextAttached.class);
ContextAttached outEvent = mock(ContextAttached.class);
Function<SpanContext, ContextAttached> newEvent = mock(Function.class);
when(delegate.attach(newContext)).thenReturn(delegatedScope);
when(inEvent.shouldCommit()).thenReturn(true);
when(outEvent.shouldCommit()).thenReturn(true);
when(newEvent.apply(spanContext)).thenReturn(inEvent);
when(newEvent.apply(SpanContext.getInvalid())).thenReturn(outEvent);
JfrContextStorage contextStorage = new JfrContextStorage(delegate, newEvent);
Scope resultScope = contextStorage.attach(newContext);
verify(inEvent).begin();
verify(inEvent).commit();
verify(outEvent, never()).begin();
verify(outEvent, never()).commit();
verify(delegatedScope, never()).close();
// returns back to the initial/default span
resultScope.close();
verify(outEvent).begin();
verify(outEvent).commit();
verify(delegatedScope).close();
}
use of com.splunk.opentelemetry.profiler.events.ContextAttached in project splunk-otel-java by signalfx.
the class JfrContextStorageTest method testNotSampled.
@Test
void testNotSampled() {
Scope scope = mock(Scope.class);
ContextStorage delegate = mock(ContextStorage.class);
spanContext = SpanContext.create(traceId, spanId, TraceFlags.getDefault(), TraceState.getDefault());
span = Span.wrap(spanContext);
newContext = Context.root().with(span);
when(delegate.attach(newContext)).thenReturn(scope);
AtomicBoolean newEventWasCalled = new AtomicBoolean(false);
Function<SpanContext, ContextAttached> newEvent = x -> {
newEventWasCalled.set(true);
return null;
};
JfrContextStorage contextStorage = new JfrContextStorage(delegate, newEvent);
Scope result = contextStorage.attach(newContext);
assertEquals(scope, result);
assertFalse(newEventWasCalled.get());
}
Aggregations