@@ -282,6 +282,7 @@ class Span:
282282 "_flags" ,
283283 "_flags_capacity" ,
284284 "_mode" ,
285+ "attributes" ,
285286 )
286287
287288 def __init__ (
@@ -300,6 +301,7 @@ def __init__(
300301 scope = None , # type: Optional[sentry_sdk.Scope]
301302 origin = "manual" , # type: str
302303 name = None , # type: Optional[str]
304+ attributes = None , # type: Optional[dict]
303305 ):
304306 # type: (...) -> None
305307 self ._trace_id = trace_id
@@ -319,6 +321,8 @@ def __init__(
319321 self ._containing_transaction = containing_transaction
320322 self ._flags = {} # type: Dict[str, bool]
321323 self ._flags_capacity = 10
324+ self .attributes = attributes or {}
325+ # TODO[span-first]: fill attributes
322326
323327 if hub is not None :
324328 warnings .warn (
@@ -676,22 +680,7 @@ def is_success(self):
676680 # type: () -> bool
677681 return self .status == "ok"
678682
679- def finish (self , scope = None , end_timestamp = None ):
680- # type: (Optional[sentry_sdk.Scope], Optional[Union[float, datetime]]) -> Optional[str]
681- """
682- Sets the end timestamp of the span.
683-
684- Additionally it also creates a breadcrumb from the span,
685- if the span represents a database or HTTP request.
686-
687- :param scope: The scope to use for this transaction.
688- If not provided, the current scope will be used.
689- :param end_timestamp: Optional timestamp that should
690- be used as timestamp instead of the current time.
691-
692- :return: Always ``None``. The type is ``Optional[str]`` to match
693- the return value of :py:meth:`sentry_sdk.tracing.Transaction.finish`.
694- """
683+ def _finish (self , scope = None , end_timestamp = None ):
695684 if self .timestamp is not None :
696685 # This span is already finished, ignore.
697686 return None
@@ -712,12 +701,31 @@ def finish(self, scope=None, end_timestamp=None):
712701 scope = scope or sentry_sdk .get_current_scope ()
713702 maybe_create_breadcrumbs_from_span (scope , self )
714703
704+ def finish (self , scope = None , end_timestamp = None ):
705+ # type: (Optional[sentry_sdk.Scope], Optional[Union[float, datetime]]) -> Optional[str]
706+ """
707+ Sets the end timestamp of the span.
708+
709+ Additionally it also creates a breadcrumb from the span,
710+ if the span represents a database or HTTP request.
711+
712+ :param scope: The scope to use for this transaction.
713+ If not provided, the current scope will be used.
714+ :param end_timestamp: Optional timestamp that should
715+ be used as timestamp instead of the current time.
716+
717+ :return: Always ``None``. The type is ``Optional[str]`` to match
718+ the return value of :py:meth:`sentry_sdk.tracing.Transaction.finish`.
719+ """
720+ self ._finish (scope , end_timestamp )
721+
715722 client = sentry_sdk .get_client ()
716723 if client .is_active ():
717724 if (
718725 has_span_streaming_enabled (client .options )
719726 and self .containing_transaction .sampled
720727 ):
728+ logger .debug (f"[Tracing] Adding span { self .span_id } to buffer" )
721729 client ._span_batcher .add (self )
722730
723731 return None
@@ -1048,11 +1056,12 @@ def finish(
10481056 )
10491057 self .name = "<unlabeled transaction>"
10501058
1051- super ().finish (scope , end_timestamp )
1059+ super ()._finish (scope , end_timestamp )
10521060
10531061 status_code = self ._data .get (SPANDATA .HTTP_STATUS_CODE )
10541062 if (
1055- status_code is not None
1063+ self ._mode == "static"
1064+ and status_code is not None
10561065 and status_code in client .options ["trace_ignore_status_codes" ]
10571066 ):
10581067 logger .debug (
@@ -1084,6 +1093,11 @@ def finish(
10841093
10851094 return None
10861095
1096+ if self ._mode == "stream" and self .containing_transaction .sampled :
1097+ logger .debug (f"[Tracing] Adding span { self .span_id } to buffer" )
1098+ client ._span_batcher .add (self )
1099+ return
1100+
10871101 finished_spans = [
10881102 span .to_json ()
10891103 for span in self ._span_recorder .spans
0 commit comments