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);
}
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);
}
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();
}
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);
}
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();
}
Aggregations