-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: Add error attributes to logging #12685
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
Changes from 9 commits
86b9e94
04bcc1f
a062871
944d05c
f33bbdd
7d35ea9
0148485
8426daf
c36d985
7ef71c2
31f8c9a
381405a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,6 +182,47 @@ void testRecordActionableError_logsErrorInfo() { | |
| attributesMap.get(ObservabilityAttributes.ERROR_METADATA_ATTRIBUTE_PREFIX + "test_key")); | ||
| } | ||
|
|
||
| @Test | ||
| void testRecordActionableError_logsExceptionDetails() { | ||
| ApiTracerContext context = ApiTracerContext.empty(); | ||
| LoggingTracer tracer = new LoggingTracer(context); | ||
|
|
||
| Exception error = new RuntimeException("test error message"); | ||
| tracer.recordActionableError(error); | ||
|
|
||
| Map<String, ?> attributesMap = getAttributesMap(); | ||
|
|
||
| assertTrue(attributesMap != null && !attributesMap.isEmpty()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can this be broken into two assert: IIRC, the error message for assertTrue isn't as clear when indicating which condition failed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I was following the existing pattern but I don't think these assertions are needed anymore. Because |
||
| assertEquals( | ||
| "java.lang.RuntimeException", | ||
| attributesMap.get(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE)); | ||
| assertEquals("test error message", attributesMap.get("exception.message")); | ||
| } | ||
|
|
||
| @Test | ||
| void testRecordActionableError_logsHttpStatus() { | ||
| ApiTracerContext context = | ||
| ApiTracerContext.empty().toBuilder().setTransport(ApiTracerContext.Transport.HTTP).build(); | ||
| LoggingTracer tracer = new LoggingTracer(context); | ||
|
|
||
| Exception error = | ||
| ApiExceptionFactory.createException( | ||
| "test error message", | ||
| new RuntimeException("cause"), | ||
| FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), | ||
| false); | ||
|
|
||
| tracer.recordActionableError(error); | ||
|
|
||
| Map<String, ?> attributesMap = getAttributesMap(); | ||
|
|
||
| assertTrue(attributesMap != null && !attributesMap.isEmpty()); | ||
| assertEquals( | ||
| "INVALID_ARGUMENT", | ||
| attributesMap.get(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE)); | ||
| assertEquals(400L, attributesMap.get(ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE)); | ||
| } | ||
|
|
||
| private Map<String, ?> getAttributesMap() { | ||
| if (!testLogger.getMDCMap().isEmpty()) { | ||
| return testLogger.getMDCMap(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.