Skip to content

Commit ebf46d0

Browse files
authored
chore: modify graphql span event traceback (#12324)
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)
1 parent a04ffb0 commit ebf46d0

File tree

1 file changed

+8
-7
lines changed
  • ddtrace/contrib/internal/graphql

1 file changed

+8
-7
lines changed

ddtrace/contrib/internal/graphql/patch.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from io import StringIO
12
import os
23
import re
34
import sys
@@ -339,13 +340,13 @@ def _set_span_errors(errors: List[GraphQLError], span: Span) -> None:
339340
}
340341

341342
if error.__traceback__:
342-
stacktrace = "\n".join(
343-
traceback.format_exception(
344-
type(error), error, error.__traceback__, limit=config._span_traceback_max_size
345-
)
346-
)
347-
attributes["stacktrace"] = stacktrace
348-
span.set_tag_str(ERROR_STACK, stacktrace)
343+
exc_type, exc_val, exc_tb = type(error), error, error.__traceback__
344+
buff = StringIO()
345+
traceback.print_exception(exc_type, exc_val, exc_tb, file=buff, limit=config._span_traceback_max_size)
346+
tb = buff.getvalue()
347+
348+
attributes["stacktrace"] = tb
349+
span.set_tag_str(ERROR_STACK, tb)
349350

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

0 commit comments

Comments
 (0)