-
Notifications
You must be signed in to change notification settings - Fork 935
Configurable exception.* attribute resolution #7266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jack-berg
merged 11 commits into
open-telemetry:main
from
jack-berg:exception-attribute-resolver
Jun 5, 2025
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9f2ecde
Add ExtendedLogRecordBuilder#setException, make exception.* resolutio…
jack-berg 1b0a28e
Use System.lineSeparator() instead of \n to fix build
jack-berg 7a62f68
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg daa8e38
Remove ExtendedLogRecordBuilder#setException
jack-berg 64ea76d
Restore werror
jack-berg bf7ab7d
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg c31ba99
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
jack-berg 8c5e2f6
Consolidate to single ExceptionAttributeResolver method
jack-berg 84d78c7
cleanup
jack-berg 06f974d
More cleanup
jack-berg 09b99a5
feedback
jack-berg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...common/src/main/java/io/opentelemetry/sdk/internal/DefaultExceptionAttributeResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.internal; | ||
|
|
||
| import java.io.PrintWriter; | ||
| import java.io.StringWriter; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * This class is internal and experimental. Its APIs are unstable and can change at any time. Its | ||
| * APIs (or a version of them) may be promoted to the public stable API in the future, but no | ||
| * guarantees are made. | ||
| */ | ||
| public final class DefaultExceptionAttributeResolver implements ExceptionAttributeResolver { | ||
|
|
||
| private static final DefaultExceptionAttributeResolver INSTANCE = | ||
| new DefaultExceptionAttributeResolver(); | ||
|
|
||
| private DefaultExceptionAttributeResolver() {} | ||
|
|
||
| public static ExceptionAttributeResolver getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public String getExceptionType(Throwable throwable, int maxAttributeLength) { | ||
| return throwable.getClass().getCanonicalName(); | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public String getExceptionMessage(Throwable throwable, int maxAttributeLength) { | ||
| return throwable.getMessage(); | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public String getExceptionStacktrace(Throwable throwable, int maxAttributeLength) { | ||
| StringWriter stringWriter = new StringWriter(); | ||
| try (PrintWriter printWriter = new PrintWriter(stringWriter)) { | ||
| throwable.printStackTrace(printWriter); | ||
| } | ||
| return stringWriter.toString(); | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
sdk/common/src/main/java/io/opentelemetry/sdk/internal/ExceptionAttributeResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.internal; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Implementations resolve {@code exception.*} attributes attached to span events, logs, etc. | ||
| * | ||
| * <p>This class is internal and experimental. Its APIs are unstable and can change at any time. Its | ||
| * APIs (or a version of them) may be promoted to the public stable API in the future, but no | ||
| * guarantees are made. | ||
| */ | ||
| public interface ExceptionAttributeResolver { | ||
|
|
||
| AttributeKey<String> EXCEPTION_TYPE = AttributeKey.stringKey("exception.type"); | ||
| AttributeKey<String> EXCEPTION_MESSAGE = AttributeKey.stringKey("exception.message"); | ||
| AttributeKey<String> EXCEPTION_STACKTRACE = AttributeKey.stringKey("exception.stacktrace"); | ||
|
|
||
| /** | ||
| * Resolve the {@link #EXCEPTION_TYPE} attribute from the {@code throwable}, or {@code null} if no | ||
| * value should be set. | ||
| * | ||
| * @param throwable the throwable | ||
| * @param maxAttributeLength the max attribute length that will be retained by the SDK. Responses | ||
| * are not required to conform to this limit, but implementations may incorporate this limit | ||
| * to avoid unnecessary compute. | ||
| */ | ||
| @Nullable | ||
| String getExceptionType(Throwable throwable, int maxAttributeLength); | ||
|
|
||
| /** | ||
| * Resolve the {@link #EXCEPTION_MESSAGE} attribute from the {@code throwable}, or {@code null} if | ||
| * no value should be set. | ||
| * | ||
| * @param throwable the throwable | ||
| * @param maxAttributeLength the max attribute length that will be retained by the SDK. Responses | ||
| * are not required to conform to this limit, but implementations may incorporate this limit | ||
| * to avoid unnecessary compute. | ||
| */ | ||
| @Nullable | ||
| String getExceptionMessage(Throwable throwable, int maxAttributeLength); | ||
|
|
||
| /** | ||
| * Resolve the {@link #EXCEPTION_STACKTRACE} attribute from the {@code throwable}, or {@code null} | ||
| * if no value should be set. | ||
| * | ||
| * @param throwable the throwable | ||
| * @param maxAttributeLength the max attribute length that will be retained by the SDK. Responses | ||
| * are not required to conform to this limit, but implementations may incorporate this limit | ||
| * to avoid unnecessary compute. | ||
| */ | ||
| @Nullable | ||
| String getExceptionStacktrace(Throwable throwable, int maxAttributeLength); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.