From 8f2f3bb9c798e762abef81a4f56290e59c0b741f Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 13:01:20 +0100 Subject: [PATCH 01/11] updated vscode config --- .vscode/settings.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c167a13dc2..ba2472c4c9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,6 @@ { "python.pythonPath": ".venv/bin/python", - "python.formatting.provider": "black" -} \ No newline at end of file + "python.formatting.provider": "black", + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} From a7963aefdf21ce5b93b5cecd96a4947c7cd8772a Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 13:03:00 +0100 Subject: [PATCH 02/11] Moved code around for better readability --- sentry_sdk/consts.py | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 6d463f3dc5..6fd61d395b 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -44,6 +44,31 @@ DEFAULT_MAX_BREADCRUMBS = 100 +class OP: + DB = "db" + DB_REDIS = "db.redis" + EVENT_DJANGO = "event.django" + FUNCTION = "function" + FUNCTION_AWS = "function.aws" + FUNCTION_GCP = "function.gcp" + HTTP_CLIENT = "http.client" + HTTP_CLIENT_STREAM = "http.client.stream" + HTTP_SERVER = "http.server" + MIDDLEWARE_DJANGO = "middleware.django" + MIDDLEWARE_STARLETTE = "middleware.starlette" + MIDDLEWARE_STARLETTE_RECEIVE = "middleware.starlette.receive" + MIDDLEWARE_STARLETTE_SEND = "middleware.starlette.send" + QUEUE_SUBMIT_CELERY = "queue.submit.celery" + QUEUE_TASK_CELERY = "queue.task.celery" + QUEUE_TASK_RQ = "queue.task.rq" + SUBPROCESS = "subprocess" + SUBPROCESS_WAIT = "subprocess.wait" + SUBPROCESS_COMMUNICATE = "subprocess.communicate" + TEMPLATE_RENDER = "template.render" + VIEW_RENDER = "view.render" + WEBSOCKET_SERVER = "websocket.server" + + # This type exists to trick mypy and PyCharm into thinking `init` and `Client` # take these arguments (even though they take opaque **kwargs) class ClientConstructor(object): @@ -106,28 +131,3 @@ def _get_default_options(): VERSION = "1.11.1" - - -class OP: - DB = "db" - DB_REDIS = "db.redis" - EVENT_DJANGO = "event.django" - FUNCTION = "function" - FUNCTION_AWS = "function.aws" - FUNCTION_GCP = "function.gcp" - HTTP_CLIENT = "http.client" - HTTP_CLIENT_STREAM = "http.client.stream" - HTTP_SERVER = "http.server" - MIDDLEWARE_DJANGO = "middleware.django" - MIDDLEWARE_STARLETTE = "middleware.starlette" - MIDDLEWARE_STARLETTE_RECEIVE = "middleware.starlette.receive" - MIDDLEWARE_STARLETTE_SEND = "middleware.starlette.send" - QUEUE_SUBMIT_CELERY = "queue.submit.celery" - QUEUE_TASK_CELERY = "queue.task.celery" - QUEUE_TASK_RQ = "queue.task.rq" - SUBPROCESS = "subprocess" - SUBPROCESS_WAIT = "subprocess.wait" - SUBPROCESS_COMMUNICATE = "subprocess.communicate" - TEMPLATE_RENDER = "template.render" - VIEW_RENDER = "view.render" - WEBSOCKET_SERVER = "websocket.server" From 76ae08dbfacc2228d51d18608e12d3090c53acd6 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 13:03:52 +0100 Subject: [PATCH 03/11] cleanup --- sentry_sdk/integrations/stdlib.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index 3b81b6c2c5..687d9dd2c1 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -187,7 +187,6 @@ def sentry_patched_popen_init(self, *a, **kw): env = None with hub.start_span(op=OP.SUBPROCESS, description=description) as span: - for k, v in hub.iter_trace_propagation_headers(span): if env is None: env = _init_argument( From ca99978cc16ac241a79c08856c3a420a458c7de3 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 13:13:59 +0100 Subject: [PATCH 04/11] Introduced SENTRY_TRACE_HEADER_NAME variable --- sentry_sdk/integrations/flask.py | 9 ++++++--- sentry_sdk/tracing.py | 14 ++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/sentry_sdk/integrations/flask.py b/sentry_sdk/integrations/flask.py index 52cce0b4b4..67c87b64f6 100644 --- a/sentry_sdk/integrations/flask.py +++ b/sentry_sdk/integrations/flask.py @@ -6,7 +6,7 @@ from sentry_sdk.integrations._wsgi_common import RequestExtractor from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware from sentry_sdk.scope import Scope -from sentry_sdk.tracing import SOURCE_FOR_STYLE +from sentry_sdk.tracing import SENTRY_TRACE_HEADER_NAME, SOURCE_FOR_STYLE from sentry_sdk.utils import ( capture_internal_exceptions, event_from_exception, @@ -101,8 +101,11 @@ def _add_sentry_trace(sender, template, context, **extra): sentry_span = Hub.current.scope.span context["sentry_trace"] = ( Markup( - '' - % (sentry_span.to_traceparent(),) + '' + % ( + SENTRY_TRACE_HEADER_NAME, + sentry_span.to_traceparent(), + ) ) if sentry_span else "" diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index aacb3a5bb3..4b9d8e87d7 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -6,7 +6,6 @@ from datetime import datetime, timedelta import sentry_sdk - from sentry_sdk.utils import logger from sentry_sdk._types import MYPY @@ -25,6 +24,8 @@ from sentry_sdk._types import Event, SamplingContext, MeasurementUnit +SENTRY_TRACE_HEADER_NAME = "sentry-trace" + # Transaction source # see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations TRANSACTION_SOURCE_CUSTOM = "custom" @@ -281,7 +282,9 @@ def continue_from_headers( baggage = Baggage.from_incoming_header(headers.get("baggage")) kwargs.update({"baggage": baggage}) - sentrytrace_kwargs = extract_sentrytrace_data(headers.get("sentry-trace")) + sentrytrace_kwargs = extract_sentrytrace_data( + headers.get(SENTRY_TRACE_HEADER_NAME) + ) if sentrytrace_kwargs is not None: kwargs.update(sentrytrace_kwargs) @@ -308,7 +311,7 @@ def iter_headers(self): `sentry_tracestate` value, this will cause one to be generated and stored. """ - yield "sentry-trace", self.to_traceparent() + yield SENTRY_TRACE_HEADER_NAME, self.to_traceparent() tracestate = self.to_tracestate() if has_tracestate_enabled(self) else None # `tracestate` will only be `None` if there's no client or no DSN @@ -344,7 +347,9 @@ def from_traceparent( if not traceparent: return None - return cls.continue_from_headers({"sentry-trace": traceparent}, **kwargs) + return cls.continue_from_headers( + {SENTRY_TRACE_HEADER_NAME: traceparent}, **kwargs + ) def to_traceparent(self): # type: () -> str @@ -653,6 +658,7 @@ def finish(self, hub=None): # to a concrete decision. if self.sampled is None: logger.warning("Discarding transaction without sampling decision.") + return None finished_spans = [ From 376d08730e86f29907efc7f952565aaf4955ea33 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 13:18:45 +0100 Subject: [PATCH 05/11] Introduced +BAGGAGE_HEADER_NAME variable --- sentry_sdk/tracing.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 4b9d8e87d7..8be9028aa5 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -23,9 +23,10 @@ import sentry_sdk.profiler from sentry_sdk._types import Event, SamplingContext, MeasurementUnit - +BAGGAGE_HEADER_NAME = "baggage" SENTRY_TRACE_HEADER_NAME = "sentry-trace" + # Transaction source # see https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations TRANSACTION_SOURCE_CUSTOM = "custom" @@ -279,8 +280,8 @@ def continue_from_headers( # TODO-neel move away from this kwargs stuff, it's confusing and opaque # make more explicit - baggage = Baggage.from_incoming_header(headers.get("baggage")) - kwargs.update({"baggage": baggage}) + baggage = Baggage.from_incoming_header(headers.get(BAGGAGE_HEADER_NAME)) + kwargs.update({BAGGAGE_HEADER_NAME: baggage}) sentrytrace_kwargs = extract_sentrytrace_data( headers.get(SENTRY_TRACE_HEADER_NAME) @@ -323,7 +324,7 @@ def iter_headers(self): if self.containing_transaction: baggage = self.containing_transaction.get_baggage().serialize() if baggage: - yield "baggage", baggage + yield BAGGAGE_HEADER_NAME, baggage @classmethod def from_traceparent( From 9d3047ee2b11bddce110ea3f38efd7ed1864e0a9 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 13:34:52 +0100 Subject: [PATCH 06/11] Add instrumenter config to switch between Sentry and OTel instrumentation. --- sentry_sdk/api.py | 3 ++- sentry_sdk/client.py | 4 ++++ sentry_sdk/consts.py | 6 +++++ sentry_sdk/hub.py | 17 ++++++++++++-- sentry_sdk/tracing.py | 53 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index cec914aca1..ffa017cfc1 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -4,6 +4,7 @@ from sentry_sdk.scope import Scope from sentry_sdk._types import MYPY +from sentry_sdk.tracing import NoOpSpan if MYPY: from typing import Any @@ -210,5 +211,5 @@ def start_transaction( transaction=None, # type: Optional[Transaction] **kwargs # type: Any ): - # type: (...) -> Transaction + # type: (...) -> Union[Transaction, NoOpSpan] return Hub.current.start_transaction(transaction, **kwargs) diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index bf1e483634..8af7003156 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -20,6 +20,7 @@ from sentry_sdk.transport import make_transport from sentry_sdk.consts import ( DEFAULT_OPTIONS, + INSTRUMENTER, VERSION, ClientConstructor, ) @@ -86,6 +87,9 @@ def _get_options(*args, **kwargs): if rv["server_name"] is None and hasattr(socket, "gethostname"): rv["server_name"] = socket.gethostname() + if rv["instrumenter"] is None: + rv["instrumenter"] = INSTRUMENTER.SENTRY + return rv diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 6fd61d395b..430558c366 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -44,6 +44,11 @@ DEFAULT_MAX_BREADCRUMBS = 100 +class INSTRUMENTER: + SENTRY = "sentry" + OTEL = "otel" + + class OP: DB = "db" DB_REDIS = "db.redis" @@ -82,6 +87,7 @@ def __init__( server_name=None, # type: Optional[str] shutdown_timeout=2, # type: float integrations=[], # type: Sequence[Integration] # noqa: B006 + instrumenter=INSTRUMENTER.SENTRY, # type: Optional[str] in_app_include=[], # type: List[str] # noqa: B006 in_app_exclude=[], # type: List[str] # noqa: B006 default_integrations=True, # type: bool diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 3d4a28d526..b87c88f271 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -5,9 +5,10 @@ from contextlib import contextmanager from sentry_sdk._compat import with_metaclass +from sentry_sdk.consts import INSTRUMENTER from sentry_sdk.scope import Scope from sentry_sdk.client import Client -from sentry_sdk.tracing import Span, Transaction +from sentry_sdk.tracing import NoOpSpan, Span, Transaction from sentry_sdk.session import Session from sentry_sdk.utils import ( exc_info_from_error, @@ -464,6 +465,12 @@ def start_span( for every incoming HTTP request. Use `start_transaction` to start a new transaction when one is not already in progress. """ + instrumenter = kwargs.get("instrumenter", INSTRUMENTER.SENTRY) + configuration_instrumenter = self.client and self.client.options["instrumenter"] + + if instrumenter != configuration_instrumenter: + return NoOpSpan() + # TODO: consider removing this in a future release. # This is for backwards compatibility with releases before # start_transaction existed, to allow for a smoother transition. @@ -496,7 +503,7 @@ def start_transaction( transaction=None, # type: Optional[Transaction] **kwargs # type: Any ): - # type: (...) -> Transaction + # type: (...) -> Union[Transaction, NoOpSpan] """ Start and return a transaction. @@ -519,6 +526,12 @@ def start_transaction( When the transaction is finished, it will be sent to Sentry with all its finished child spans. """ + instrumenter = kwargs.get("instrumenter", INSTRUMENTER.SENTRY) + configuration_instrumenter = self.client and self.client.options["instrumenter"] + + if instrumenter != configuration_instrumenter: + return NoOpSpan() + custom_sampling_context = kwargs.pop("custom_sampling_context", {}) # if we haven't been given a transaction, make one diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 8be9028aa5..5b9fbdfd0d 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -6,6 +6,7 @@ from datetime import datetime, timedelta import sentry_sdk +from sentry_sdk.consts import INSTRUMENTER from sentry_sdk.utils import logger from sentry_sdk._types import MYPY @@ -125,6 +126,7 @@ def __init__( status=None, # type: Optional[str] transaction=None, # type: Optional[str] # deprecated containing_transaction=None, # type: Optional[Transaction] + instrumenter=None, # type: Optional[str] ): # type: (...) -> None self.trace_id = trace_id or uuid.uuid4().hex @@ -215,6 +217,15 @@ def start_child(self, **kwargs): trace id, sampling decision, transaction pointer, and span recorder are inherited from the current span/transaction. """ + hub = self.hub or sentry_sdk.Hub.current + client = hub.client + + instrumenter = kwargs.get("instrumenter", INSTRUMENTER.SENTRY) + configuration_instrumenter = client and client.options["instrumenter"] + + if instrumenter != configuration_instrumenter: + return NoOpSpan() + kwargs.setdefault("sampled", self.sampled) child = Span( @@ -828,6 +839,48 @@ def _set_initial_sampling_decision(self, sampling_context): ) +class NoOpSpan(Span): + def __repr__(self): + # type: () -> Any + return self.__class__.__name__ + + def __enter__(self): + # type: () -> Any + return self + + def __exit__(self, ty, value, tb): + # type: (Any, Any, Any) -> Any + pass + + def start_child(self, **kwargs): + # type: (**Any) -> Any + pass + + def new_span(self, **kwargs): + # type: (**Any) -> Any + pass + + def set_tag(self, key, value): + # type: (Any, Any) -> Any + pass + + def set_data(self, key, value): + # type: (Any, Any) -> Any + pass + + def set_status(self, value): + # type: (Any) -> Any + pass + + def set_http_status(self, http_status): + # type: (Any) -> Any + pass + + def finish(self, hub=None, **kwargs): + # type: (Any, **Any) -> Any + pass + + # Circular imports from sentry_sdk.tracing_utils import ( From 7a8654e8403f4f8e62cbb53c63a16af3e93a2659 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 16:53:10 +0100 Subject: [PATCH 07/11] Add API to set arbitrary context in Transaction. (#1769) * Api for setting arbitrary contexts in transactions. --- sentry_sdk/tracing.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 5b9fbdfd0d..c2dc1ab581 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -561,6 +561,7 @@ class Transaction(Span): # tracestate data from other vendors, of the form `dogs=yes,cats=maybe` "_third_party_tracestate", "_measurements", + "_contexts", "_profile", "_baggage", "_active_thread_id", @@ -586,7 +587,9 @@ def __init__( "instead of Span(transaction=...)." ) name = kwargs.pop("transaction") + Span.__init__(self, **kwargs) + self.name = name self.source = source self.sample_rate = None # type: Optional[float] @@ -597,6 +600,7 @@ def __init__( self._sentry_tracestate = sentry_tracestate self._third_party_tracestate = third_party_tracestate self._measurements = {} # type: Dict[str, Any] + self._contexts = {} # type: Dict[str, Any] self._profile = None # type: Optional[sentry_sdk.profiler.Profile] self._baggage = baggage # for profiling, we want to know on which thread a transaction is started @@ -685,11 +689,15 @@ def finish(self, hub=None): # to be garbage collected self._span_recorder = None + contexts = {} + contexts.update(self._contexts) + contexts.update({"trace": self.get_trace_context()}) + event = { "type": "transaction", "transaction": self.name, "transaction_info": {"source": self.source}, - "contexts": {"trace": self.get_trace_context()}, + "contexts": contexts, "tags": self._tags, "timestamp": self.timestamp, "start_timestamp": self.start_timestamp, @@ -714,6 +722,10 @@ def set_measurement(self, name, value, unit=""): self._measurements[name] = {"value": value, "unit": unit} + def set_context(self, key, value): + # type: (str, Any) -> None + self._contexts[key] = value + def to_json(self): # type: () -> Dict[str, Any] rv = super(Transaction, self).to_json() From 4cb573b9de1eeff5bc58c70ac1da0a6ce367dab1 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 16:54:25 +0100 Subject: [PATCH 08/11] Add API to set custom Span timestamps (#1770) * Add parameter to set `start_timestamp` and `end_timestamp` on Span creation or finishing --- sentry_sdk/tracing.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index c2dc1ab581..bdc5fcf5a5 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -126,6 +126,7 @@ def __init__( status=None, # type: Optional[str] transaction=None, # type: Optional[str] # deprecated containing_transaction=None, # type: Optional[Transaction] + start_timestamp=None, # type: Optional[datetime] instrumenter=None, # type: Optional[str] ): # type: (...) -> None @@ -141,7 +142,7 @@ def __init__( self._tags = {} # type: Dict[str, str] self._data = {} # type: Dict[str, Any] self._containing_transaction = containing_transaction - self.start_timestamp = datetime.utcnow() + self.start_timestamp = start_timestamp or datetime.utcnow() try: # TODO: For Python 3.7+, we could use a clock with ns resolution: # self._start_timestamp_monotonic = time.perf_counter_ns() @@ -472,8 +473,8 @@ def is_success(self): # type: () -> bool return self.status == "ok" - def finish(self, hub=None): - # type: (Optional[sentry_sdk.Hub]) -> Optional[str] + def finish(self, hub=None, end_timestamp=None): + # type: (Optional[sentry_sdk.Hub], Optional[datetime]) -> Optional[str] # XXX: would be type: (Optional[sentry_sdk.Hub]) -> None, but that leads # to incompatible return types for Span.finish and Transaction.finish. if self.timestamp is not None: @@ -483,8 +484,13 @@ def finish(self, hub=None): hub = hub or self.hub or sentry_sdk.Hub.current try: - duration_seconds = time.perf_counter() - self._start_timestamp_monotonic - self.timestamp = self.start_timestamp + timedelta(seconds=duration_seconds) + if end_timestamp: + self.timestamp = end_timestamp + else: + duration_seconds = time.perf_counter() - self._start_timestamp_monotonic + self.timestamp = self.start_timestamp + timedelta( + seconds=duration_seconds + ) except AttributeError: self.timestamp = datetime.utcnow() @@ -634,8 +640,8 @@ def containing_transaction(self): # reference. return self - def finish(self, hub=None): - # type: (Optional[sentry_sdk.Hub]) -> Optional[str] + def finish(self, hub=None, end_timestamp=None): + # type: (Optional[sentry_sdk.Hub], Optional[datetime]) -> Optional[str] if self.timestamp is not None: # This transaction is already finished, ignore. return None @@ -667,7 +673,7 @@ def finish(self, hub=None): ) self.name = "" - Span.finish(self, hub) + Span.finish(self, hub, end_timestamp) if not self.sampled: # At this point a `sampled = None` should have already been resolved @@ -888,8 +894,8 @@ def set_http_status(self, http_status): # type: (Any) -> Any pass - def finish(self, hub=None, **kwargs): - # type: (Any, **Any) -> Any + def finish(self, hub=None, end_timestamp=None): + # type: (Any, Any) -> Any pass From 758680fa18616996697a026a5129748bab5a9bd4 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 30 Nov 2022 17:22:15 +0100 Subject: [PATCH 09/11] Moved new parameter to last position --- sentry_sdk/consts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 430558c366..47d630dee3 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -87,7 +87,6 @@ def __init__( server_name=None, # type: Optional[str] shutdown_timeout=2, # type: float integrations=[], # type: Sequence[Integration] # noqa: B006 - instrumenter=INSTRUMENTER.SENTRY, # type: Optional[str] in_app_include=[], # type: List[str] # noqa: B006 in_app_exclude=[], # type: List[str] # noqa: B006 default_integrations=True, # type: bool @@ -113,6 +112,7 @@ def __init__( send_client_reports=True, # type: bool _experiments={}, # type: Experiments # noqa: B006 proxy_headers=None, # type: Optional[Dict[str, str]] + instrumenter=INSTRUMENTER.SENTRY, # type: Optional[str] ): # type: (...) -> None pass From 0ad75184a8ef483e32c1322f216aa8883b32ae23 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 1 Dec 2022 08:53:10 +0100 Subject: [PATCH 10/11] Made instrumenter parameter explicit. --- sentry_sdk/hub.py | 4 ++-- sentry_sdk/tracing.py | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index b87c88f271..df9de10fe4 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -451,6 +451,7 @@ def add_breadcrumb( def start_span( self, span=None, # type: Optional[Span] + instrumenter=INSTRUMENTER.SENTRY, # type: str **kwargs # type: Any ): # type: (...) -> Span @@ -465,7 +466,6 @@ def start_span( for every incoming HTTP request. Use `start_transaction` to start a new transaction when one is not already in progress. """ - instrumenter = kwargs.get("instrumenter", INSTRUMENTER.SENTRY) configuration_instrumenter = self.client and self.client.options["instrumenter"] if instrumenter != configuration_instrumenter: @@ -501,6 +501,7 @@ def start_span( def start_transaction( self, transaction=None, # type: Optional[Transaction] + instrumenter=INSTRUMENTER.SENTRY, # type: str **kwargs # type: Any ): # type: (...) -> Union[Transaction, NoOpSpan] @@ -526,7 +527,6 @@ def start_transaction( When the transaction is finished, it will be sent to Sentry with all its finished child spans. """ - instrumenter = kwargs.get("instrumenter", INSTRUMENTER.SENTRY) configuration_instrumenter = self.client and self.client.options["instrumenter"] if instrumenter != configuration_instrumenter: diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index bdc5fcf5a5..2b4255468f 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -209,8 +209,8 @@ def containing_transaction(self): # referencing themselves) return self._containing_transaction - def start_child(self, **kwargs): - # type: (**Any) -> Span + def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs): + # type: (str, **Any) -> Span """ Start a sub-span from the current span or transaction. @@ -220,8 +220,6 @@ def start_child(self, **kwargs): """ hub = self.hub or sentry_sdk.Hub.current client = hub.client - - instrumenter = kwargs.get("instrumenter", INSTRUMENTER.SENTRY) configuration_instrumenter = client and client.options["instrumenter"] if instrumenter != configuration_instrumenter: From 3ed3077c24da4377e7f4fab87ad7355bba4c2473 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 1 Dec 2022 09:32:43 +0100 Subject: [PATCH 11/11] Fixed typo --- sentry_sdk/tracing.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 2b4255468f..93d22dc758 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -127,7 +127,6 @@ def __init__( transaction=None, # type: Optional[str] # deprecated containing_transaction=None, # type: Optional[Transaction] start_timestamp=None, # type: Optional[datetime] - instrumenter=None, # type: Optional[str] ): # type: (...) -> None self.trace_id = trace_id or uuid.uuid4().hex @@ -868,8 +867,8 @@ def __exit__(self, ty, value, tb): # type: (Any, Any, Any) -> Any pass - def start_child(self, **kwargs): - # type: (**Any) -> Any + def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs): + # type: (str, **Any) -> Any pass def new_span(self, **kwargs):