use of io.opentelemetry.instrumentation.api.appender.internal.LogBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class Log4jHelper method capture.
public static void capture(Logger logger, Level level, Message message, Throwable throwable) {
String instrumentationName = logger.getName();
if (instrumentationName == null || instrumentationName.isEmpty()) {
instrumentationName = "ROOT";
}
LogBuilder builder = AgentLogEmitterProvider.get().logEmitterBuilder(instrumentationName).build().logBuilder();
Map<String, String> contextData = ThreadContext.getImmutableContext();
mapper.mapLogEvent(builder, message, level, throwable, null, contextData);
builder.emit();
}
use of io.opentelemetry.instrumentation.api.appender.internal.LogBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class LoggingEventMapper method emit.
public void emit(LogEmitterProvider logEmitterProvider, ILoggingEvent event) {
String instrumentationName = event.getLoggerName();
if (instrumentationName == null || instrumentationName.isEmpty()) {
instrumentationName = "ROOT";
}
LogBuilder builder = logEmitterProvider.logEmitterBuilder(instrumentationName).build().logBuilder();
mapLoggingEvent(builder, event);
builder.emit();
}
use of io.opentelemetry.instrumentation.api.appender.internal.LogBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class OpenTelemetryAppender method append.
@Override
public void append(LogEvent event) {
String instrumentationName = event.getLoggerName();
if (instrumentationName == null || instrumentationName.isEmpty()) {
instrumentationName = "ROOT";
}
LogBuilder builder = logEmitterProviderHolder.get().logEmitterBuilder(instrumentationName).build().logBuilder();
ReadOnlyStringMap contextData = event.getContextData();
mapper.mapLogEvent(builder, event.getMessage(), event.getLevel(), event.getThrown(), event.getInstant(), contextData);
builder.emit();
}
use of io.opentelemetry.instrumentation.api.appender.internal.LogBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class LogEventMapperTest method testCaptureStructuredDataMessage.
@Test
void testCaptureStructuredDataMessage() {
// given
LogEventMapper<Map<String, String>> mapper = new LogEventMapper<>(ContextDataAccessorImpl.INSTANCE, true, singletonList("*"));
StructuredDataMessage message = new StructuredDataMessage("an id", "a message", "a type");
message.put("key1", "value1");
message.put("message", "value2");
LogBuilder logBuilder = mock(LogBuilder.class);
AttributesBuilder attributes = Attributes.builder();
// when
mapper.captureMessage(logBuilder, attributes, message);
// then
verify(logBuilder).setBody("a message");
assertThat(attributes.build()).containsOnly(entry(AttributeKey.stringKey("key1"), "value1"), entry(AttributeKey.stringKey("message"), "value2"));
}
use of io.opentelemetry.instrumentation.api.appender.internal.LogBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class LogEventMapperTest method testCaptureMapMessageDisabled.
@Test
void testCaptureMapMessageDisabled() {
// given
LogEventMapper<Map<String, String>> mapper = new LogEventMapper<>(ContextDataAccessorImpl.INSTANCE, false, singletonList("*"));
StringMapMessage message = new StringMapMessage();
message.put("key1", "value1");
message.put("message", "value2");
LogBuilder logBuilder = mock(LogBuilder.class);
AttributesBuilder attributes = Attributes.builder();
// when
mapper.captureMessage(logBuilder, attributes, message);
// then
verify(logBuilder).setBody("value2");
assertThat(attributes.build()).isEmpty();
}
Aggregations