Skip to content

Commit

Permalink
update span event attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
quinna-h authored and emmettbutler committed Feb 10, 2025
1 parent 37ab0e7 commit 2435838
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions ddtrace/_trace/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ def __init__(self, name: str, attributes: Optional[Dict[str, Any]] = None, time_
self.name: str = name
if attributes is None:
self.attributes = {}
elif not isinstance(attributes, dict):
raise TypeError("attributes must be a dictionary")
elif not all(isinstance(k, str) for k in attributes.keys()):
raise TypeError("All attributes keys must be strings")
else:
self.attributes = attributes
if time_unix_nano is None:
Expand All @@ -81,6 +77,11 @@ def __dict__(self):
return d

def __str__(self):
"""
Stringify and return value.
Attribute value can be either str, bool, int/float, list.
"""

def format_value(value: Any) -> str:
if isinstance(value, list):
return f"[{' '.join(map(str, value))}]"
Expand Down
6 changes: 3 additions & 3 deletions ddtrace/contrib/internal/graphql/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ def _get_source_str(obj):


def _set_span_errors(errors: List[GraphQLError], span: Span) -> None:
"""
Set tags on error span and set span events on each error.
"""
if not errors:
# do nothing if the list of graphql errors is empty
return
Expand All @@ -300,9 +303,6 @@ def _set_span_errors(errors: List[GraphQLError], span: Span) -> None:
exc_type_str = "%s.%s" % (GraphQLError.__module__, GraphQLError.__name__)
span.set_tag_str(ERROR_TYPE, exc_type_str)
error_msgs = "\n".join([str(error) for error in errors])
# Since we do not support adding and visualizing multiple tracebacks to one span
# we will not set the error.stack tag on graphql spans. Setting only one traceback
# could be misleading and might obfuscate errors.
span.set_tag_str(ERROR_MSG, error_msgs)
for error in errors:
locations = [f"{loc.formatted['line']}:{loc.formatted['column']}" for loc in error.locations]
Expand Down

0 comments on commit 2435838

Please sign in to comment.