Skip to content

Commit

Permalink
chore: modify graphql span event traceback (#12324)
Browse files Browse the repository at this point in the history
Modify graphql span event `error.stack` formatting for consistency with
`exception.stacktrace` as here:
#12185

If these are not exactly the same, this might lead to issues with error
tracking.

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
quinna-h authored Feb 19, 2025
1 parent a04ffb0 commit ebf46d0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ddtrace/contrib/internal/graphql/patch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from io import StringIO
import os
import re
import sys
Expand Down Expand Up @@ -339,13 +340,13 @@ def _set_span_errors(errors: List[GraphQLError], span: Span) -> None:
}

if error.__traceback__:
stacktrace = "\n".join(
traceback.format_exception(
type(error), error, error.__traceback__, limit=config._span_traceback_max_size
)
)
attributes["stacktrace"] = stacktrace
span.set_tag_str(ERROR_STACK, stacktrace)
exc_type, exc_val, exc_tb = type(error), error, error.__traceback__
buff = StringIO()
traceback.print_exception(exc_type, exc_val, exc_tb, file=buff, limit=config._span_traceback_max_size)
tb = buff.getvalue()

attributes["stacktrace"] = tb
span.set_tag_str(ERROR_STACK, tb)

if error.path is not None:
path = ",".join([str(path_obj) for path_obj in error.path])
Expand Down

0 comments on commit ebf46d0

Please sign in to comment.