Skip to content

Commit

Permalink
update error extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
quinna-h committed Feb 5, 2025
1 parent 450121e commit b7fe47f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions ddtrace/contrib/internal/graphql/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,30 +288,23 @@ def _get_source_str(obj):


def _validate_error_extensions(error: GraphQLError, extensions: Optional[str], attributes: Dict) -> Tuple[Dict, Dict]:
# Validate user-provided extensions
"""Validate user-provided extensions
All extensions values MUST be stringified, EXCEPT for numeric values and
boolean values, which remain in their original type.
"""

if not extensions:
return {}, attributes

fields = [e.strip() for e in extensions.split(",")]
error_extensions = {}
for field in fields:
if field in error.extensions:
# validate extensions formatting
# All extensions values MUST be stringified, EXCEPT for numeric values and
# boolean values, which remain in their original type.
if isinstance(error.extensions[field], (int, float, bool)):
error_extensions[field] = error.extensions[field]
else:
# q: could this be `None`?
error_extensions[field] = str(error.extensions[field])

# Additional validation for Apollo Server attributes
if field == "stacktrace":
attributes["type"] = error.extensions[field].split(":")[0]
attributes["stacktrace"] = "\n".join(error.extensions[field])
elif field == "code":
attributes["code"] = error.extensions[field]

return error_extensions, attributes


Expand Down

0 comments on commit b7fe47f

Please sign in to comment.