Search in sources :

Example 1 with LogDataBuilder

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

the class SdkLogBuilderTest method emitAfterShutdown.

@Test
void emitAfterShutdown() {
    LogEmitterSharedState state = mock(LogEmitterSharedState.class);
    LogDataBuilder delegate = mock(LogDataBuilder.class);
    when(state.hasBeenShutdown()).thenReturn(true);
    SdkLogBuilder builder = new SdkLogBuilder(state, delegate);
    builder.emit();
    verify(state, never()).getLogProcessor();
    verifyNoInteractions(delegate);
}
Also used : LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with LogDataBuilder

use of io.opentelemetry.sdk.logs.data.LogDataBuilder 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)

Example 3 with LogDataBuilder

use of io.opentelemetry.sdk.logs.data.LogDataBuilder in project splunk-otel-java by signalfx.

the class BatchingLogsProcessorTest method setup.

@BeforeEach
void setup() {
    LogDataBuilder builder = LogDataBuilder.create(Resource.getDefault(), InstrumentationLibraryInfo.create("test", "1.2.3"));
    log1 = builder.setAttributes(Attributes.of(AttributeKey.stringKey("one"), "one")).setBody("foo").build();
    log2 = builder.setAttributes(Attributes.of(AttributeKey.stringKey("two"), "two")).setBody("bar").build();
    log3 = builder.setAttributes(Attributes.of(AttributeKey.stringKey("three"), "three")).setBody("baz").build();
    exporter = new MockExporter();
}
Also used : LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with LogDataBuilder

use of io.opentelemetry.sdk.logs.data.LogDataBuilder in project splunk-otel-java by signalfx.

the class StackToSpanLinkageProcessorTest method testProcessor.

@Test
void testProcessor() {
    Instant time = Instant.now();
    StackToSpanLinkage linkedSpan = new StackToSpanLinkage(time, "some stack", "event name", SpanLinkage.NONE);
    LogDataCreator logCreator = mock(LogDataCreator.class);
    BatchingLogsProcessor exportProcessor = mock(BatchingLogsProcessor.class);
    LogDataBuilder builder = LogDataBuilder.create(Resource.getDefault(), InstrumentationLibraryInfo.create("test", "1.2.3"));
    LogData log = builder.setBody("the.body").build();
    when(logCreator.apply(linkedSpan)).thenReturn(log);
    StackToSpanLinkageProcessor processor = new StackToSpanLinkageProcessor(logCreator, exportProcessor);
    processor.accept(linkedSpan);
    verify(exportProcessor).emit(log);
}
Also used : StackToSpanLinkage(com.splunk.opentelemetry.profiler.context.StackToSpanLinkage) BatchingLogsProcessor(com.splunk.opentelemetry.logs.BatchingLogsProcessor) LogData(io.opentelemetry.sdk.logs.data.LogData) Instant(java.time.Instant) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with LogDataBuilder

use of io.opentelemetry.sdk.logs.data.LogDataBuilder in project splunk-otel-java by signalfx.

the class LogDataCreator method apply.

@Override
public LogData apply(StackToSpanLinkage linkedStack) {
    Attributes attributes = commonAttributes.builder(linkedStack).build();
    LogDataBuilder logDataBuilder = LogDataBuilder.create(resource, INSTRUMENTATION_LIBRARY_INFO).setEpoch(linkedStack.getTime()).setBody(linkedStack.getRawStack()).setAttributes(attributes);
    if (linkedStack.hasSpanInfo()) {
        logDataBuilder.setSpanContext(linkedStack.getSpanContext());
    }
    return logDataBuilder.build();
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) LogDataBuilder(io.opentelemetry.sdk.logs.data.LogDataBuilder)

Aggregations

LogDataBuilder (io.opentelemetry.sdk.logs.data.LogDataBuilder)6 Attributes (io.opentelemetry.api.common.Attributes)3 Instant (java.time.Instant)3 Test (org.junit.jupiter.api.Test)3 LogData (io.opentelemetry.sdk.logs.data.LogData)2 BatchingLogsProcessor (com.splunk.opentelemetry.logs.BatchingLogsProcessor)1 StackToSpanLinkage (com.splunk.opentelemetry.profiler.context.StackToSpanLinkage)1 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)1 SpanContext (io.opentelemetry.api.trace.SpanContext)1 Context (io.opentelemetry.context.Context)1 Severity (io.opentelemetry.sdk.logs.data.Severity)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 RecordedStackTrace (jdk.jfr.consumer.RecordedStackTrace)1 RecordedThread (jdk.jfr.consumer.RecordedThread)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1