Skip to content
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

Use Span.recordException for logging throwable #813

Merged
merged 8 commits into from
Jul 28, 2020

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Jul 27, 2020

I found some quirks on the way

Note the removal of tags from some server spans is expected - the new attributes are only for exceptions, we don't map HTTP errors onto them anymore.

I expected this PR to take a while but was even more digging than I expected :) Filed some other issues along the way.

In the process, looks like I fixed the null assertions everywhere, so fixes #806

@anuraaga anuraaga force-pushed the use-record-exception branch from ad49556 to 2059831 Compare July 27, 2020 10:11
StringWriter errorString = new StringWriter();
throwable.printStackTrace(new PrintWriter(errorString));
span.setAttribute(MoreAttributes.ERROR_STACK, errorString.toString());
span.recordException(throwable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉


@Override
boolean testException() {
// TODO(anuraaga): https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/807
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines -129 to -133
if (endpoint.errored) {
"error.msg" { it == null || it == EXCEPTION.body }
"error.type" { it == null || it == Exception.name }
"error.stack" { it == null || it instanceof String }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no replacement for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so - the exception is recorded in the handler span so isn't on this one. Not sure if this is an issue with the instrumentation or expected though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, makes sense, i think this is expected

@@ -68,6 +68,12 @@ class VertxRxHttpServerTest extends HttpServerTest<Vertx> {
return false
}

@Override
boolean testException() {
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/807
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just helping with the future search 😄

Suggested change
// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/807
// TODO(anuraaga): https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/807

Comment on lines 107 to 112
event(0) {
eventName(SemanticAttributes.EXCEPTION_EVENT_NAME)
attributes {
"${SemanticAttributes.EXCEPTION_TYPE.key()}" errorClass.name
"${SemanticAttributes.EXCEPTION_MESSAGE.key()}" ~/Connection refused:( no further information:)? \/127.0.0.1:$UNUSABLE_PORT/
"${SemanticAttributes.EXCEPTION_STACKTRACE.key()}" String
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a few places that look like they could use errorEvent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's because the message is matched using regex. I could make errorevent more powerful but didn't find enough of these places to warrant it yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like you are using errorEvent in other places with regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah didn't even notice - message is the only one in my function without a type parameter mostly by accident :D Yeah I'll use it then

Comment on lines -129 to -133
if (endpoint.errored) {
"error.msg" { it == null || it == EXCEPTION.body }
"error.type" { it == null || it == Exception.name }
"error.stack" { it == null || it instanceof String }
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so - the exception is recorded in the handler span so isn't on this one. Not sure if this is an issue with the instrumentation or expected though.

Comment on lines 107 to 112
event(0) {
eventName(SemanticAttributes.EXCEPTION_EVENT_NAME)
attributes {
"${SemanticAttributes.EXCEPTION_TYPE.key()}" errorClass.name
"${SemanticAttributes.EXCEPTION_MESSAGE.key()}" ~/Connection refused:( no further information:)? \/127.0.0.1:$UNUSABLE_PORT/
"${SemanticAttributes.EXCEPTION_STACKTRACE.key()}" String
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's because the message is matched using regex. I could make errorevent more powerful but didn't find enough of these places to warrant it yet.

event(0) {
eventName(SemanticAttributes.EXCEPTION_EVENT_NAME)
attributes {
"${SemanticAttributes.EXCEPTION_TYPE.key()}" { it == null || it == Exception.name }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I'll update

Anuraag Agrawal added 2 commits July 28, 2020 13:47
…cTests.groovy

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@anuraaga anuraaga merged commit f6594e1 into open-telemetry:master Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suspicious assertion - "error.*" { it == null || foo }
3 participants