Search in sources :

Example 1 with ContextAttached

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());
}
Also used : ContextAttached(com.splunk.opentelemetry.profiler.events.ContextAttached) Test(org.junit.jupiter.api.Test)

Example 2 with ContextAttached

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();
    }
}
Also used : ContextAttached(com.splunk.opentelemetry.profiler.events.ContextAttached) SpanContext(io.opentelemetry.api.trace.SpanContext)

Example 3 with ContextAttached

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();
}
Also used : ContextAttached(com.splunk.opentelemetry.profiler.events.ContextAttached) SpanContext(io.opentelemetry.api.trace.SpanContext) Scope(io.opentelemetry.context.Scope) Test(org.junit.jupiter.api.Test)

Example 4 with ContextAttached

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());
}
Also used : ContextAttached(com.splunk.opentelemetry.profiler.events.ContextAttached) Assertions.fail(org.junit.jupiter.api.Assertions.fail) TraceFlags(io.opentelemetry.api.trace.TraceFlags) Context(io.opentelemetry.context.Context) ContextStorage(io.opentelemetry.context.ContextStorage) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Span(io.opentelemetry.api.trace.Span) SpanId(io.opentelemetry.api.trace.SpanId) Scope(io.opentelemetry.context.Scope) SpanContext(io.opentelemetry.api.trace.SpanContext) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Mockito.when(org.mockito.Mockito.when) Function(java.util.function.Function) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) TraceState(io.opentelemetry.api.trace.TraceState) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TraceId(io.opentelemetry.api.trace.TraceId) ContextAttached(com.splunk.opentelemetry.profiler.events.ContextAttached) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Mockito.mock(org.mockito.Mockito.mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SpanContext(io.opentelemetry.api.trace.SpanContext) Scope(io.opentelemetry.context.Scope) ContextStorage(io.opentelemetry.context.ContextStorage) Test(org.junit.jupiter.api.Test)

Aggregations

ContextAttached (com.splunk.opentelemetry.profiler.events.ContextAttached)4 SpanContext (io.opentelemetry.api.trace.SpanContext)3 Test (org.junit.jupiter.api.Test)3 Scope (io.opentelemetry.context.Scope)2 Span (io.opentelemetry.api.trace.Span)1 SpanId (io.opentelemetry.api.trace.SpanId)1 TraceFlags (io.opentelemetry.api.trace.TraceFlags)1 TraceId (io.opentelemetry.api.trace.TraceId)1 TraceState (io.opentelemetry.api.trace.TraceState)1 Context (io.opentelemetry.context.Context)1 ContextStorage (io.opentelemetry.context.ContextStorage)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Function (java.util.function.Function)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.fail (org.junit.jupiter.api.Assertions.fail)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Mock (org.mockito.Mock)1 Mockito.mock (org.mockito.Mockito.mock)1