Search in sources :

Example 1 with ContextStorage

use of io.opentelemetry.context.ContextStorage in project splunk-otel-java by signalfx.

the class JfrContextStorageTest method testCurrentSimplyDelegates.

@Test
void testCurrentSimplyDelegates() {
    Context expected = mock(Context.class);
    ContextStorage delegate = mock(ContextStorage.class);
    when(delegate.current()).thenReturn(expected);
    JfrContextStorage contextStorage = new JfrContextStorage(delegate);
    Context result = contextStorage.current();
    assertEquals(expected, result);
}
Also used : Context(io.opentelemetry.context.Context) SpanContext(io.opentelemetry.api.trace.SpanContext) ContextStorage(io.opentelemetry.context.ContextStorage) Test(org.junit.jupiter.api.Test)

Example 2 with ContextStorage

use of io.opentelemetry.context.ContextStorage in project opentelemetry-java-instrumentation by open-telemetry.

the class InstrumentationExtension method afterEach.

@Override
public void afterEach(ExtensionContext context) throws Exception {
    ContextStorage storage = ContextStorage.get();
    ContextStorageCloser.close(storage);
}
Also used : ContextStorage(io.opentelemetry.context.ContextStorage)

Example 3 with ContextStorage

use of io.opentelemetry.context.ContextStorage 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

ContextStorage (io.opentelemetry.context.ContextStorage)3 SpanContext (io.opentelemetry.api.trace.SpanContext)2 Context (io.opentelemetry.context.Context)2 Test (org.junit.jupiter.api.Test)2 ContextAttached (com.splunk.opentelemetry.profiler.events.ContextAttached)1 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 Scope (io.opentelemetry.context.Scope)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