Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder;
import io.opentelemetry.api.logs.LogRecordBuilder;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.concurrent.TimeUnit;
import java.util.logging.Formatter;
import java.util.logging.Level;
Expand Down Expand Up @@ -85,13 +83,8 @@ private static void mapLogRecord(LogRecordBuilder builder, LogRecord logRecord)
// throwable
Throwable throwable = logRecord.getThrown();
if (throwable != null) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
// this cast is safe within java agent instrumentation
((ExtendedLogRecordBuilder) builder).setException(throwable);
}

if (captureExperimentalAttributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder;
import io.opentelemetry.api.logs.LogRecordBuilder;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.internal.cache.Cache;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
import org.jboss.logmanager.ExtLogRecord;
Expand Down Expand Up @@ -81,13 +79,8 @@ public void capture(Logger logger, ExtLogRecord record) {

Throwable throwable = record.getThrown();
if (throwable != null) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
// this cast is safe within java agent instrumentation
((ExtendedLogRecordBuilder) builder).setException(throwable);
}
captureMdcAttributes(attributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder;
import io.opentelemetry.api.logs.LogRecordBuilder;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -101,13 +102,15 @@ public void capture(

// throwable
if (throwable != null) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
if (builder instanceof ExtendedLogRecordBuilder) {
((ExtendedLogRecordBuilder) builder).setException(throwable);
} else {
attributes.put(ExceptionAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
}
}

captureMdcAttributes(attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder;
import io.opentelemetry.api.logs.LogRecordBuilder;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void mapLogEvent(
}

if (throwable != null) {
setThrowable(attributes, throwable);
setThrowable(builder, attributes, throwable);
}

captureContextDataAttributes(attributes, contextData);
Expand Down Expand Up @@ -233,14 +234,17 @@ public static AttributeKey<String> getMapMessageAttributeKey(String key) {
key, k -> AttributeKey.stringKey("log4j.map_message." + k));
}

private static void setThrowable(AttributesBuilder attributes, Throwable throwable) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
private static void setThrowable(
LogRecordBuilder builder, AttributesBuilder attributes, Throwable throwable) {
if (builder instanceof ExtendedLogRecordBuilder) {
((ExtendedLogRecordBuilder) builder).setException(throwable);
} else {
attributes.put(ExceptionAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
}
}

private static Severity levelToSeverity(Level level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.incubator.logs.ExtendedLogRecordBuilder;
import io.opentelemetry.api.logs.LogRecordBuilder;
import io.opentelemetry.api.logs.LoggerProvider;
import io.opentelemetry.api.logs.Severity;
Expand Down Expand Up @@ -147,7 +148,7 @@ private void mapLoggingEvent(
throwable = ((ThrowableProxy) throwableProxy).getThrowable();
}
if (throwable != null) {
setThrowable(attributes, throwable);
setThrowable(builder, attributes, throwable);
}

captureMdcAttributes(attributes, loggingEvent.getMDCPropertyMap());
Expand Down Expand Up @@ -269,14 +270,17 @@ public static AttributeKey<String> getMdcAttributeKey(String key) {
return mdcAttributeKeys.computeIfAbsent(key, AttributeKey::stringKey);
}

private static void setThrowable(AttributesBuilder attributes, Throwable throwable) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
private static void setThrowable(
LogRecordBuilder builder, AttributesBuilder attributes, Throwable throwable) {
if (builder instanceof ExtendedLogRecordBuilder) {
((ExtendedLogRecordBuilder) builder).setException(throwable);
} else {
attributes.put(ExceptionAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
StringWriter writer = new StringWriter();
throwable.printStackTrace(new PrintWriter(writer));
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
}
}

private static Severity levelToSeverity(Level level) {
Expand Down