Search in sources :

Example 1 with TraceId

use of io.opentelemetry.api.trace.TraceId 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)1 Span (io.opentelemetry.api.trace.Span)1 SpanContext (io.opentelemetry.api.trace.SpanContext)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 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 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Mock (org.mockito.Mock)1 Mockito.mock (org.mockito.Mockito.mock)1