-
Notifications
You must be signed in to change notification settings - Fork 514
/
hub.py
778 lines (608 loc) · 26.3 KB
/
hub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
from contextlib import contextmanager
from sentry_sdk._compat import with_metaclass
from sentry_sdk.consts import INSTRUMENTER
from sentry_sdk.scope import Scope, _ScopeManager
from sentry_sdk.client import Client
from sentry_sdk.tracing import (
NoOpSpan,
Span,
Transaction,
)
from sentry_sdk.utils import (
logger,
ContextVar,
)
from sentry_sdk._types import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Any
from typing import Callable
from typing import ContextManager
from typing import Dict
from typing import Generator
from typing import List
from typing import Optional
from typing import overload
from typing import Tuple
from typing import Type
from typing import TypeVar
from typing import Union
from typing_extensions import Unpack
from sentry_sdk.client import BaseClient
from sentry_sdk.integrations import Integration
from sentry_sdk._types import (
Event,
Hint,
Breadcrumb,
BreadcrumbHint,
ExcInfo,
LogLevelStr,
)
from sentry_sdk.consts import ClientConstructor
from sentry_sdk.scope import StartTransactionKwargs
T = TypeVar("T")
else:
def overload(x):
# type: (T) -> T
return x
_local = ContextVar("sentry_current_hub")
def _should_send_default_pii():
# type: () -> bool
# TODO: Migrate existing code to `scope.should_send_default_pii()` and remove this function.
# New code should not use this function!
client = Hub.current.client
if not client:
return False
return client.should_send_default_pii()
class _InitGuard:
def __init__(self, client):
# type: (Client) -> None
self._client = client
def __enter__(self):
# type: () -> _InitGuard
return self
def __exit__(self, exc_type, exc_value, tb):
# type: (Any, Any, Any) -> None
c = self._client
if c is not None:
c.close()
def _check_python_deprecations():
# type: () -> None
# Since we're likely to deprecate Python versions in the future, I'm keeping
# this handy function around. Use this to detect the Python version used and
# to output logger.warning()s if it's deprecated.
pass
def _init(*args, **kwargs):
# type: (*Optional[str], **Any) -> ContextManager[Any]
"""Initializes the SDK and optionally integrations.
This takes the same arguments as the client constructor.
"""
client = Client(*args, **kwargs) # type: ignore
Hub.current.bind_client(client)
_check_python_deprecations()
rv = _InitGuard(client)
return rv
from sentry_sdk._types import TYPE_CHECKING
if TYPE_CHECKING:
# Make mypy, PyCharm and other static analyzers think `init` is a type to
# have nicer autocompletion for params.
#
# Use `ClientConstructor` to define the argument types of `init` and
# `ContextManager[Any]` to tell static analyzers about the return type.
class init(ClientConstructor, _InitGuard): # noqa: N801
pass
else:
# Alias `init` for actual usage. Go through the lambda indirection to throw
# PyCharm off of the weakly typed signature (it would otherwise discover
# both the weakly typed signature of `_init` and our faked `init` type).
init = (lambda: _init)()
class HubMeta(type):
@property
def current(cls):
# type: () -> Hub
"""Returns the current instance of the hub."""
rv = _local.get(None)
if rv is None:
rv = Hub(GLOBAL_HUB)
_local.set(rv)
return rv
@property
def main(cls):
# type: () -> Hub
"""Returns the main instance of the hub."""
return GLOBAL_HUB
class Hub(with_metaclass(HubMeta)): # type: ignore
"""
.. deprecated:: 2.0.0
The Hub is deprecated. Its functionality will be merged into :py:class:`sentry_sdk.scope.Scope`.
The hub wraps the concurrency management of the SDK. Each thread has
its own hub but the hub might transfer with the flow of execution if
context vars are available.
If the hub is used with a with statement it's temporarily activated.
"""
_stack = None # type: List[Tuple[Optional[Client], Scope]]
_scope = None # type: Optional[Scope]
# Mypy doesn't pick up on the metaclass.
if TYPE_CHECKING:
current = None # type: Hub
main = None # type: Hub
def __init__(
self,
client_or_hub=None, # type: Optional[Union[Hub, Client]]
scope=None, # type: Optional[Any]
):
# type: (...) -> None
current_scope = None
if isinstance(client_or_hub, Hub):
client = Scope.get_client()
if scope is None:
# hub cloning is going on, we use a fork of the current/isolation scope for context manager
scope = Scope.get_isolation_scope().fork()
current_scope = Scope.get_current_scope().fork()
else:
client = client_or_hub # type: ignore
Scope.get_global_scope().set_client(client)
if scope is None: # so there is no Hub cloning going on
# just the current isolation scope is used for context manager
scope = Scope.get_isolation_scope()
current_scope = Scope.get_current_scope()
if current_scope is None:
# just the current current scope is used for context manager
current_scope = Scope.get_current_scope()
self._stack = [(client, scope)] # type: ignore
self._last_event_id = None # type: Optional[str]
self._old_hubs = [] # type: List[Hub]
self._old_current_scopes = [] # type: List[Scope]
self._old_isolation_scopes = [] # type: List[Scope]
self._current_scope = current_scope # type: Scope
self._scope = scope # type: Scope
def __enter__(self):
# type: () -> Hub
self._old_hubs.append(Hub.current)
_local.set(self)
current_scope = Scope.get_current_scope()
self._old_current_scopes.append(current_scope)
scope._current_scope.set(self._current_scope)
isolation_scope = Scope.get_isolation_scope()
self._old_isolation_scopes.append(isolation_scope)
scope._isolation_scope.set(self._scope)
return self
def __exit__(
self,
exc_type, # type: Optional[type]
exc_value, # type: Optional[BaseException]
tb, # type: Optional[Any]
):
# type: (...) -> None
old = self._old_hubs.pop()
_local.set(old)
old_current_scope = self._old_current_scopes.pop()
scope._current_scope.set(old_current_scope)
old_isolation_scope = self._old_isolation_scopes.pop()
scope._isolation_scope.set(old_isolation_scope)
def run(
self, callback # type: Callable[[], T]
):
# type: (...) -> T
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Runs a callback in the context of the hub. Alternatively the
with statement can be used on the hub directly.
"""
with self:
return callback()
def get_integration(
self, name_or_class # type: Union[str, Type[Integration]]
):
# type: (...) -> Any
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.client._Client.get_integration` instead.
Returns the integration for this hub by name or class. If there
is no client bound or the client does not have that integration
then `None` is returned.
If the return value is not `None` the hub is guaranteed to have a
client attached.
"""
return Scope.get_client().get_integration(name_or_class)
@property
def client(self):
# type: () -> Optional[BaseClient]
"""
.. deprecated:: 2.0.0
This property is deprecated and will be removed in a future release.
Please use :py:func:`sentry_sdk.api.get_client` instead.
Returns the current client on the hub.
"""
client = Scope.get_client()
if not client.is_active():
return None
return client
@property
def scope(self):
# type: () -> Scope
"""
.. deprecated:: 2.0.0
This property is deprecated and will be removed in a future release.
Returns the current scope on the hub.
"""
return Scope.get_isolation_scope()
def last_event_id(self):
# type: () -> Optional[str]
"""
Returns the last event ID.
.. deprecated:: 1.40.5
This function is deprecated and will be removed in a future release. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly.
"""
logger.warning(
"Deprecated: last_event_id is deprecated. This will be removed in the future. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly."
)
return self._last_event_id
def bind_client(
self, new # type: Optional[BaseClient]
):
# type: (...) -> None
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.set_client` instead.
Binds a new client to the hub.
"""
Scope.get_global_scope().set_client(new)
def capture_event(self, event, hint=None, scope=None, **scope_kwargs):
# type: (Event, Optional[Hint], Optional[Scope], Any) -> Optional[str]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.capture_event` instead.
Captures an event.
Alias of :py:meth:`sentry_sdk.Scope.capture_event`.
:param event: A ready-made event that can be directly sent to Sentry.
:param hint: Contains metadata about the event that can be read from `before_send`, such as the original exception object or a HTTP request object.
:param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
The `scope` and `scope_kwargs` parameters are mutually exclusive.
:param scope_kwargs: Optional data to apply to event.
For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
The `scope` and `scope_kwargs` parameters are mutually exclusive.
"""
last_event_id = Scope.get_current_scope().capture_event(
event, hint, scope=scope, **scope_kwargs
)
is_transaction = event.get("type") == "transaction"
if last_event_id is not None and not is_transaction:
self._last_event_id = last_event_id
return last_event_id
def capture_message(self, message, level=None, scope=None, **scope_kwargs):
# type: (str, Optional[LogLevelStr], Optional[Scope], Any) -> Optional[str]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.capture_message` instead.
Captures a message.
Alias of :py:meth:`sentry_sdk.Scope.capture_message`.
:param message: The string to send as the message to Sentry.
:param level: If no level is provided, the default level is `info`.
:param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
The `scope` and `scope_kwargs` parameters are mutually exclusive.
:param scope_kwargs: Optional data to apply to event.
For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
The `scope` and `scope_kwargs` parameters are mutually exclusive.
:returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
"""
last_event_id = Scope.get_current_scope().capture_message(
message, level=level, scope=scope, **scope_kwargs
)
if last_event_id is not None:
self._last_event_id = last_event_id
return last_event_id
def capture_exception(self, error=None, scope=None, **scope_kwargs):
# type: (Optional[Union[BaseException, ExcInfo]], Optional[Scope], Any) -> Optional[str]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.capture_exception` instead.
Captures an exception.
Alias of :py:meth:`sentry_sdk.Scope.capture_exception`.
:param error: An exception to capture. If `None`, `sys.exc_info()` will be used.
:param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events.
The `scope` and `scope_kwargs` parameters are mutually exclusive.
:param scope_kwargs: Optional data to apply to event.
For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`.
The `scope` and `scope_kwargs` parameters are mutually exclusive.
:returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`).
"""
last_event_id = Scope.get_current_scope().capture_exception(
error, scope=scope, **scope_kwargs
)
if last_event_id is not None:
self._last_event_id = last_event_id
return last_event_id
def _capture_internal_exception(
self, exc_info # type: Any
):
# type: (...) -> Any
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.client._Client._capture_internal_exception` instead.
Capture an exception that is likely caused by a bug in the SDK
itself.
Duplicated in :py:meth:`sentry_sdk.client._Client._capture_internal_exception`.
These exceptions do not end up in Sentry and are just logged instead.
"""
logger.error("Internal error in sentry_sdk", exc_info=exc_info)
def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
# type: (Optional[Breadcrumb], Optional[BreadcrumbHint], Any) -> None
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.add_breadcrumb` instead.
Adds a breadcrumb.
:param crumb: Dictionary with the data as the sentry v7/v8 protocol expects.
:param hint: An optional value that can be used by `before_breadcrumb`
to customize the breadcrumbs that are emitted.
"""
Scope.get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
# type: (str, Any) -> Span
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.start_span` instead.
Start a span whose parent is the currently active span or transaction, if any.
The return value is a :py:class:`sentry_sdk.tracing.Span` instance,
typically used as a context manager to start and stop timing in a `with`
block.
Only spans contained in a transaction are sent to Sentry. Most
integrations start a transaction at the appropriate time, for example
for every incoming HTTP request. Use
:py:meth:`sentry_sdk.start_transaction` to start a new transaction when
one is not already in progress.
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
"""
scope = Scope.get_current_scope()
return scope.start_span(instrumenter=instrumenter, **kwargs)
def start_transaction(
self, transaction=None, instrumenter=INSTRUMENTER.SENTRY, **kwargs
):
# type: (Optional[Transaction], str, Unpack[StartTransactionKwargs]) -> Union[Transaction, NoOpSpan]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.start_transaction` instead.
Start and return a transaction.
Start an existing transaction if given, otherwise create and start a new
transaction with kwargs.
This is the entry point to manual tracing instrumentation.
A tree structure can be built by adding child spans to the transaction,
and child spans to other spans. To start a new child span within the
transaction or any span, call the respective `.start_child()` method.
Every child span must be finished before the transaction is finished,
otherwise the unfinished spans are discarded.
When used as context managers, spans and transactions are automatically
finished at the end of the `with` block. If not using context managers,
call the `.finish()` method.
When the transaction is finished, it will be sent to Sentry with all its
finished child spans.
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Transaction`.
"""
scope = Scope.get_current_scope()
# For backwards compatibility, we allow passing the scope as the hub.
# We need a major release to make this nice. (if someone searches the code: deprecated)
# Type checking disabled for this line because deprecated keys are not allowed in the type signature.
kwargs["hub"] = scope # type: ignore
return scope.start_transaction(
transaction=transaction, instrumenter=instrumenter, **kwargs
)
def continue_trace(self, environ_or_headers, op=None, name=None, source=None):
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str]) -> Transaction
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.continue_trace` instead.
Sets the propagation context from environment or headers and returns a transaction.
"""
return Scope.get_isolation_scope().continue_trace(
environ_or_headers=environ_or_headers, op=op, name=name, source=source
)
@overload
def push_scope(
self, callback=None # type: Optional[None]
):
# type: (...) -> ContextManager[Scope]
pass
@overload
def push_scope( # noqa: F811
self, callback # type: Callable[[Scope], None]
):
# type: (...) -> None
pass
def push_scope( # noqa
self,
callback=None, # type: Optional[Callable[[Scope], None]]
continue_trace=True, # type: bool
):
# type: (...) -> Optional[ContextManager[Scope]]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Pushes a new layer on the scope stack.
:param callback: If provided, this method pushes a scope, calls
`callback`, and pops the scope again.
:returns: If no `callback` is provided, a context manager that should
be used to pop the scope again.
"""
if callback is not None:
with self.push_scope() as scope:
callback(scope)
return None
return _ScopeManager(self)
def pop_scope_unsafe(self):
# type: () -> Tuple[Optional[Client], Scope]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Pops a scope layer from the stack.
Try to use the context manager :py:meth:`push_scope` instead.
"""
rv = self._stack.pop()
assert self._stack, "stack must have at least one layer"
return rv
@overload
def configure_scope(
self, callback=None # type: Optional[None]
):
# type: (...) -> ContextManager[Scope]
pass
@overload
def configure_scope( # noqa: F811
self, callback # type: Callable[[Scope], None]
):
# type: (...) -> None
pass
def configure_scope( # noqa
self,
callback=None, # type: Optional[Callable[[Scope], None]]
continue_trace=True, # type: bool
):
# type: (...) -> Optional[ContextManager[Scope]]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Reconfigures the scope.
:param callback: If provided, call the callback with the current scope.
:returns: If no callback is provided, returns a context manager that returns the scope.
"""
scope = Scope.get_isolation_scope()
if continue_trace:
scope.generate_propagation_context()
if callback is not None:
# TODO: used to return None when client is None. Check if this changes behavior.
callback(scope)
return None
@contextmanager
def inner():
# type: () -> Generator[Scope, None, None]
yield scope
return inner()
def start_session(
self, session_mode="application" # type: str
):
# type: (...) -> None
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.start_session` instead.
Starts a new session.
"""
Scope.get_isolation_scope().start_session(
session_mode=session_mode,
)
def end_session(self):
# type: (...) -> None
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.end_session` instead.
Ends the current session if there is one.
"""
Scope.get_isolation_scope().end_session()
def stop_auto_session_tracking(self):
# type: (...) -> None
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.stop_auto_session_tracking` instead.
Stops automatic session tracking.
This temporarily session tracking for the current scope when called.
To resume session tracking call `resume_auto_session_tracking`.
"""
Scope.get_isolation_scope().stop_auto_session_tracking()
def resume_auto_session_tracking(self):
# type: (...) -> None
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.resume_auto_session_tracking` instead.
Resumes automatic session tracking for the current scope if
disabled earlier. This requires that generally automatic session
tracking is enabled.
"""
Scope.get_isolation_scope().resume_auto_session_tracking()
def flush(
self,
timeout=None, # type: Optional[float]
callback=None, # type: Optional[Callable[[int, float], None]]
):
# type: (...) -> None
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.client._Client.flush` instead.
Alias for :py:meth:`sentry_sdk.client._Client.flush`
"""
return Scope.get_client().flush(timeout=timeout, callback=callback)
def get_traceparent(self):
# type: () -> Optional[str]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.get_traceparent` instead.
Returns the traceparent either from the active span or from the scope.
"""
current_scope = Scope.get_current_scope()
traceparent = current_scope.get_traceparent()
if traceparent is None:
isolation_scope = Scope.get_isolation_scope()
traceparent = isolation_scope.get_traceparent()
return traceparent
def get_baggage(self):
# type: () -> Optional[str]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.get_baggage` instead.
Returns Baggage either from the active span or from the scope.
"""
current_scope = Scope.get_current_scope()
baggage = current_scope.get_baggage()
if baggage is None:
isolation_scope = Scope.get_isolation_scope()
baggage = isolation_scope.get_baggage()
if baggage is not None:
return baggage.serialize()
return None
def iter_trace_propagation_headers(self, span=None):
# type: (Optional[Span]) -> Generator[Tuple[str, str], None, None]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.iter_trace_propagation_headers` instead.
Return HTTP headers which allow propagation of trace data. Data taken
from the span representing the request, if available, or the current
span on the scope if not.
"""
return Scope.get_current_scope().iter_trace_propagation_headers(
span=span,
)
def trace_propagation_meta(self, span=None):
# type: (Optional[Span]) -> str
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Please use :py:meth:`sentry_sdk.Scope.trace_propagation_meta` instead.
Return meta tags which should be injected into HTML templates
to allow propagation of trace information.
"""
if span is not None:
logger.warning(
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
)
return Scope.get_current_scope().trace_propagation_meta(
span=span,
)
GLOBAL_HUB = Hub()
_local.set(GLOBAL_HUB)
# Circular imports
from sentry_sdk import scope