Skip to content

Commit

Permalink
stable exception attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge committed Apr 9, 2024
1 parent fed4ff8 commit 509fdf2
Show file tree
Hide file tree
Showing 28 changed files with 123 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import java.util.Locale;

/**
Expand Down Expand Up @@ -96,8 +96,8 @@ public InstrumentationContext<ExecutionResult> beginExecution(
for (GraphQLError error : result.getErrors()) {
AttributesBuilder attributes = Attributes.builder();
attributes.put(
ExceptionIncubatingAttributes.EXCEPTION_TYPE, String.valueOf(error.getErrorType()));
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, error.getMessage());
ExceptionAttributes.EXCEPTION_TYPE, String.valueOf(error.getErrorType()));
attributes.put(ExceptionAttributes.EXCEPTION_MESSAGE, error.getMessage());

span.addEvent("exception", attributes.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.sdk.trace.data.StatusData;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
Expand Down Expand Up @@ -207,10 +207,10 @@ void parseError() {
.hasName("exception")
.hasAttributesSatisfyingExactly(
equalTo(
ExceptionIncubatingAttributes.EXCEPTION_TYPE,
ExceptionAttributes.EXCEPTION_TYPE,
"InvalidSyntax"),
satisfies(
ExceptionIncubatingAttributes.EXCEPTION_MESSAGE,
ExceptionAttributes.EXCEPTION_MESSAGE,
message ->
message.startsWithIgnoringCase(
"Invalid Syntax"))))));
Expand Down Expand Up @@ -249,10 +249,10 @@ void validationError() {
.hasName("exception")
.hasAttributesSatisfyingExactly(
equalTo(
ExceptionIncubatingAttributes.EXCEPTION_TYPE,
ExceptionAttributes.EXCEPTION_TYPE,
"ValidationError"),
satisfies(
ExceptionIncubatingAttributes.EXCEPTION_MESSAGE,
ExceptionAttributes.EXCEPTION_MESSAGE,
message ->
message.startsWith("Validation error"))))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes.EXCEPTION_MESSAGE;
import static io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE;
import static io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes.EXCEPTION_TYPE;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_MESSAGE;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_STACKTRACE;
import static io.opentelemetry.semconv.ExceptionAttributes.EXCEPTION_TYPE;
import static org.junit.jupiter.api.Named.named;

import io.opentelemetry.api.common.AttributeKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -87,11 +87,11 @@ private static void mapLogRecord(LogRecordBuilder builder, LogRecord logRecord)
if (throwable != null) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
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(ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE, writer.toString());
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
}

if (captureExperimentalAttributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -117,12 +117,10 @@ private static void test(
.hasAttributesSatisfyingExactly(
equalTo(ThreadIncubatingAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(ThreadIncubatingAttributes.THREAD_ID, Thread.currentThread().getId()),
equalTo(
ExceptionIncubatingAttributes.EXCEPTION_TYPE,
IllegalStateException.class.getName()),
equalTo(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, "hello"),
equalTo(ExceptionAttributes.EXCEPTION_TYPE, IllegalStateException.class.getName()),
equalTo(ExceptionAttributes.EXCEPTION_MESSAGE, "hello"),
satisfies(
ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE,
ExceptionAttributes.EXCEPTION_STACKTRACE,
v -> v.contains(JavaUtilLoggingTest.class.getName())));
} else {
assertThat(log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.internal.cache.Cache;
import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -83,11 +83,11 @@ public void capture(Logger logger, ExtLogRecord record) {
if (throwable != null) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
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(ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE, writer.toString());
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
}
captureMdcAttributes(attributes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.time.Instant;
import java.util.stream.Stream;
Expand Down Expand Up @@ -143,12 +143,10 @@ private static void test(
.hasAttributesSatisfyingExactly(
equalTo(ThreadIncubatingAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(ThreadIncubatingAttributes.THREAD_ID, Thread.currentThread().getId()),
equalTo(
ExceptionIncubatingAttributes.EXCEPTION_TYPE,
IllegalStateException.class.getName()),
equalTo(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, "hello"),
equalTo(ExceptionAttributes.EXCEPTION_TYPE, IllegalStateException.class.getName()),
equalTo(ExceptionAttributes.EXCEPTION_MESSAGE, "hello"),
satisfies(
ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE,
ExceptionAttributes.EXCEPTION_STACKTRACE,
v -> v.contains(JbossLogmanagerTest.class.getName())));
} else {
assertThat(log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.instrumentation.test.utils.PortUtils
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes
import io.opentelemetry.semconv.ExceptionAttributes
import io.opentelemetry.semconv.ServerAttributes
import io.opentelemetry.semconv.ClientAttributes
import io.opentelemetry.semconv.UserAgentAttributes
Expand Down Expand Up @@ -260,13 +260,13 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
event(0) {
eventName("exception")
attributes {
"$ExceptionIncubatingAttributes.EXCEPTION_TYPE" { String tagExceptionType ->
"$ExceptionAttributes.EXCEPTION_TYPE" { String tagExceptionType ->
return tagExceptionType == exceptionClass.getName() || tagExceptionType.contains(exceptionClass.getSimpleName())
}
"$ExceptionIncubatingAttributes.EXCEPTION_MESSAGE" { String tagErrorMsg ->
"$ExceptionAttributes.EXCEPTION_MESSAGE" { String tagErrorMsg ->
return errorMessageOptional || tagErrorMsg instanceof String
}
"$ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE" String
"$ExceptionAttributes.EXCEPTION_STACKTRACE" String
}
}
attributes {
Expand Down Expand Up @@ -300,13 +300,13 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification {
event(0) {
eventName("exception")
attributes {
"$ExceptionIncubatingAttributes.EXCEPTION_TYPE" { String tagExceptionType ->
"$ExceptionAttributes.EXCEPTION_TYPE" { String tagExceptionType ->
return tagExceptionType == exceptionClass.getName() || tagExceptionType.contains(exceptionClass.getSimpleName())
}
"$ExceptionIncubatingAttributes.EXCEPTION_MESSAGE" { String tagErrorMsg ->
"$ExceptionAttributes.EXCEPTION_MESSAGE" { String tagErrorMsg ->
return errorMessageOptional || tagErrorMsg instanceof String
}
"$ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE" String
"$ExceptionAttributes.EXCEPTION_STACKTRACE" String
}
}
attributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.internal.cache.Cache;
import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -89,11 +89,11 @@ public void capture(Category logger, Priority level, Object message, Throwable t
if (throwable != null) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
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(ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE, writer.toString());
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
}

captureMdcAttributes(attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.lang.reflect.Field;
import java.time.Instant;
Expand Down Expand Up @@ -114,12 +114,10 @@ private static void test(
.hasAttributesSatisfyingExactly(
equalTo(ThreadIncubatingAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(ThreadIncubatingAttributes.THREAD_ID, Thread.currentThread().getId()),
equalTo(
ExceptionIncubatingAttributes.EXCEPTION_TYPE,
IllegalStateException.class.getName()),
equalTo(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, "hello"),
equalTo(ExceptionAttributes.EXCEPTION_TYPE, IllegalStateException.class.getName()),
equalTo(ExceptionAttributes.EXCEPTION_MESSAGE, "hello"),
satisfies(
ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE,
ExceptionAttributes.EXCEPTION_STACKTRACE,
v -> v.contains(Log4j1Test.class.getName())));
} else {
assertThat(log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.time.Instant;
import java.util.stream.Stream;
Expand Down Expand Up @@ -103,12 +103,10 @@ private static void test(
.hasAttributesSatisfyingExactly(
equalTo(ThreadIncubatingAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(ThreadIncubatingAttributes.THREAD_ID, Thread.currentThread().getId()),
equalTo(
ExceptionIncubatingAttributes.EXCEPTION_TYPE,
IllegalStateException.class.getName()),
equalTo(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, "hello"),
equalTo(ExceptionAttributes.EXCEPTION_TYPE, IllegalStateException.class.getName()),
equalTo(ExceptionAttributes.EXCEPTION_MESSAGE, "hello"),
satisfies(
ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE,
ExceptionAttributes.EXCEPTION_STACKTRACE,
v -> v.contains(Log4j2Test.class.getName())));
} else {
assertThat(log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -92,12 +92,10 @@ private static void test(
.hasAttributesSatisfyingExactly(
equalTo(ThreadIncubatingAttributes.THREAD_NAME, Thread.currentThread().getName()),
equalTo(ThreadIncubatingAttributes.THREAD_ID, Thread.currentThread().getId()),
equalTo(
ExceptionIncubatingAttributes.EXCEPTION_TYPE,
IllegalStateException.class.getName()),
equalTo(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, "hello"),
equalTo(ExceptionAttributes.EXCEPTION_TYPE, IllegalStateException.class.getName()),
equalTo(ExceptionAttributes.EXCEPTION_MESSAGE, "hello"),
satisfies(
ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE,
ExceptionAttributes.EXCEPTION_STACKTRACE,
v -> v.contains(Slf4jToLog4jTest.class.getName())));
} else {
assertThat(log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.internal.cache.Cache;
import io.opentelemetry.semconv.incubating.ExceptionIncubatingAttributes;
import io.opentelemetry.semconv.ExceptionAttributes;
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes;
import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -188,11 +188,11 @@ public static AttributeKey<String> getMapMessageAttributeKey(String key) {
private static void setThrowable(AttributesBuilder attributes, Throwable throwable) {
// TODO (trask) extract method for recording exception into
// io.opentelemetry:opentelemetry-api
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_TYPE, throwable.getClass().getName());
attributes.put(ExceptionIncubatingAttributes.EXCEPTION_MESSAGE, throwable.getMessage());
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(ExceptionIncubatingAttributes.EXCEPTION_STACKTRACE, writer.toString());
attributes.put(ExceptionAttributes.EXCEPTION_STACKTRACE, writer.toString());
}

private static Severity levelToSeverity(Level level) {
Expand Down
Loading

0 comments on commit 509fdf2

Please sign in to comment.