From 243583810d1aa7200e45f646a8c8189c10431fe1 Mon Sep 17 00:00:00 2001 From: quinna-h Date: Thu, 6 Feb 2025 11:24:36 -0500 Subject: [PATCH] update span event attribute --- ddtrace/_trace/span.py | 9 +++++---- ddtrace/contrib/internal/graphql/patch.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ddtrace/_trace/span.py b/ddtrace/_trace/span.py index cbdec364e7b..a3cef893a8c 100644 --- a/ddtrace/_trace/span.py +++ b/ddtrace/_trace/span.py @@ -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: @@ -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))}]" diff --git a/ddtrace/contrib/internal/graphql/patch.py b/ddtrace/contrib/internal/graphql/patch.py index 1155b391d1c..b4c67a0338e 100644 --- a/ddtrace/contrib/internal/graphql/patch.py +++ b/ddtrace/contrib/internal/graphql/patch.py @@ -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 @@ -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]