-
Notifications
You must be signed in to change notification settings - Fork 306
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
Error in span does not cause entire request to report error in APM #723
Comments
I'm not sure to understand exactly the expected behavior. Are you trying to add an error to a specific span, or add an error to the root span of the tracer? Or are you trying to add an error to the root span whenever there is another span that has an error? |
Thanks for the quick reply. I am trying to add an error to the root span of the tracer. |
Are errors reported as |
Another question: do you expect any error on any span to flag the trace with an error, or only specific ones? |
|
Ok, then it should be possible to flag the request and use that on the request span in a hook. It would look like this: // right after tracer.init()
tracer.use('express', {
hooks: {
request: (span, req, res) => {
// assuming somewhere in your app you set req.error = true
if (req.error) {
span.setTag('error', req.error)
}
}
}
}) You could also set the error to an actual Please let me know if that helps! |
Trying that right now. Thank you. |
Seems to be working great. Request is showing up as an error. And I can inspect the spans to find the actual error. Only issue I see is that some code paths where I may want to 'noticeError' may not currently have access to the req. I'm currently attempting to search through the spans in the express middleware to find my error span. I'll keep you posted! Thanks again. |
It's also possible to access the request span from any span at any time during the request lifecycle, but there is no public API to do it yet so you would have to rely on private properties. If this is something you are comfortable with, it would look like this: // anywhere during the request lifecycle
const span = tracer.scope().active()
if (span) {
span.context()._trace.started[0].setTag('error', true)
} |
I think that is exactly what I need. Having to use private props is not ideal but I think I can work with it for now. Should I open another issue to request that as a first party feature? |
Sure thing! This is definitely something that is on our radar but we want to make sure the API will cover all uses cases, which is why it hasn't landed yet. |
I found this issue when trying to figure out how to get APM Error tracking working. I may be missing something, but since the Error Tracking view only shows errors that are attached to root-level spans, it basically never shows any error that occurred during a request, even if that request returned a 500. When the built-in error handling of express (or in my case, NestJS) catches the uncaught error and sets up the 500 response, that means there's no "automatically" captured error that will show up in error tracking. It seems like the only way to use error tracking correctly in this case is with the above workaround to manually attach the error to the request span in a custom error handling middleware? @rochdev does that sound right? |
@ajwootto Sounds right. If there is an error object available we could capture that is available and we don't currently capture it's definitely something we should add. Otherwise it has to be done in a hook. |
I actually am having trouble getting this working even with the above workaround. It seems that something later up in the chain is overriding the error tag to just be "true". Edit: I managed to get it working eventually. While the errors now show up in error tracking, this does feel like I'm using APM "incorrectly" in order to make the error tracking work. I was under the impression that it would be somewhat of a replacement for Sentry or Rollbar and automatically catch and group any errors causing 5xx errors in our API, and that unfortunately does not seem to be the case without "tricking" it into having the error present on the root span. |
Here is a workaround my team just implemented that should work without messing with the spans directly. This might be an option for the library to expose this functionality. #1944 (comment) Haven't pushed it to production yet but early testing seems to work. |
I am having an issue with getting an error in a span to propagate up and cause the entire trace to be marked as a failure.
I want to provide my team with the ability to notice a critical error in an http request (even if the code catches that error and handles it graceful). To achieve this I am create a span and causing it to error out. This works. However, the trace created by the express plugin (and I assume the http plugins as well) does not seem to care about a failed.
I think I must be missing something. But I can't find any clear examples or documentation on how to achieve this.
example code:
Environment
OSX 10.14.3
v11.15.0
dd-trace@0.15.4
6.14.1
The text was updated successfully, but these errors were encountered: