Search in sources :

Example 1 with Severity

use of io.opentelemetry.sdk.logs.data.Severity in project opentelemetry-java by open-telemetry.

the class SdkLogBuilderTest method buildAndEmit.

@Test
// test deprecated setName method
@SuppressWarnings("deprecation")
void buildAndEmit() {
    Instant now = Instant.now();
    String name = "skippy";
    String bodyStr = "body";
    String sevText = "sevText";
    Severity severity = Severity.DEBUG3;
    Attributes attrs = Attributes.empty();
    AtomicReference<LogData> seenLog = new AtomicReference<>();
    LogProcessor logProcessor = seenLog::set;
    LogEmitterSharedState state = mock(LogEmitterSharedState.class);
    LogDataBuilder delegate = mock(LogDataBuilder.class);
    LogData logData = mock(LogData.class);
    Context context = mock(Context.class);
    when(state.getLogLimits()).thenReturn(LogLimits.getDefault());
    when(state.getLogProcessor()).thenReturn(logProcessor);
    when(delegate.build()).thenReturn(logData);
    SdkLogBuilder builder = new SdkLogBuilder(state, delegate);
    builder.setBody(bodyStr);
    verify(delegate).setBody(bodyStr);
    builder.setEpoch(123, TimeUnit.SECONDS);
    verify(delegate).setEpoch(123, TimeUnit.SECONDS);
    builder.setEpoch(now);
    verify(delegate).setEpoch(now);
    builder.setAttributes(attrs);
    verify(delegate).setAttributes(attrs);
    builder.setContext(context);
    verify(delegate).setContext(context);
    builder.setName(name);
    verify(delegate).setName(name);
    builder.setSeverity(severity);
    verify(delegate).setSeverity(severity);
    builder.setSeverityText(sevText);
    verify(delegate).setSeverityText(sevText);
    builder.emit();
    assertThat(seenLog.get()).isSameAs(logData);
}
Also used : Context(io.opentelemetry.context.Context) LogData(io.opentelemetry.sdk.logs.data.LogData) Instant(java.time.Instant) Attributes(io.opentelemetry.api.common.Attributes) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) Severity(io.opentelemetry.sdk.logs.data.Severity) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Aggregations

Attributes (io.opentelemetry.api.common.Attributes)1 Context (io.opentelemetry.context.Context)1 LogData (io.opentelemetry.sdk.logs.data.LogData)1 LogDataBuilder (io.opentelemetry.sdk.logs.data.LogDataBuilder)1 Severity (io.opentelemetry.sdk.logs.data.Severity)1 Instant (java.time.Instant)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.jupiter.api.Test)1