# API Docs

class sentry_sdk.Hub(client_or_hub=None, scope=None)

  Deprecated since version 2.0.0: The Hub is deprecated. Its functionality will be merged into `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.

  add_breadcrumb(crumb=None, hint=None, **kwargs)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.add_breadcrumb()` instead.

    Adds a breadcrumb.

    Parameters:

      - crumb (Optional[Breadcrumb]) – Dictionary with the data as the sentry v7/v8 protocol expects.

      - hint (Optional[BreadcrumbHint]) – An optional value that can be used by before_breadcrumb to customize the breadcrumbs that are emitted.

    Return type:

      `None`

  bind_client(new)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.set_client()` instead.

    Binds a new client to the hub.

    Return type:

      `None`

  capture_event(event, hint=None, scope=None, **scope_kwargs)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.capture_event()` instead.

    Captures an event.

    Alias of `sentry_sdk.Scope.capture_event()`.

    Parameters:

      - event (Event) – A ready-made event that can be directly sent to Sentry.

      - hint (Optional[Hint]) – Contains metadata about the event that can be read from before_send, such as the original exception object or a HTTP request object.

      - scope (Optional[Scope]) – An optional `sentry_sdk.Scope` to apply to events. The scope and scope_kwargs parameters are mutually exclusive.

      - scope_kwargs (Any) – Optional data to apply to event. For supported **scope_kwargs see `sentry_sdk.Scope.update_from_kwargs()`. The scope and scope_kwargs parameters are mutually exclusive.

    Return type:

      Optional[str]

  capture_exception(error=None, scope=None, **scope_kwargs)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.capture_exception()` instead.

    Captures an exception.

    Alias of `sentry_sdk.Scope.capture_exception()`.

    Parameters:

      - error (Optional[Union[BaseException, ExcInfo]]) – An exception to capture. If None, sys.exc_info() will be used.

      - scope (Optional[Scope]) – An optional `sentry_sdk.Scope` to apply to events. The scope and scope_kwargs parameters are mutually exclusive.

      - scope_kwargs (Any) – Optional data to apply to event. For supported **scope_kwargs see `sentry_sdk.Scope.update_from_kwargs()`. The scope and scope_kwargs parameters are mutually exclusive.

    Return type:

      Optional[str]

    Returns:

      An event_id if the SDK decided to send the event (see `sentry_sdk.client._Client.capture_event()`).

  capture_message(message, level=None, scope=None, **scope_kwargs)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.capture_message()` instead.

    Captures a message.

    Alias of `sentry_sdk.Scope.capture_message()`.

    Parameters:

      - message (`str`) – The string to send as the message to Sentry.

      - level (Optional[LogLevelStr]) – If no level is provided, the default level is info.

      - scope (Optional[Scope]) – An optional `sentry_sdk.Scope` to apply to events. The scope and scope_kwargs parameters are mutually exclusive.

      - scope_kwargs (Any) – Optional data to apply to event. For supported **scope_kwargs see `sentry_sdk.Scope.update_from_kwargs()`. The scope and scope_kwargs parameters are mutually exclusive.

    Return type:

      Optional[str]

    Returns:

      An event_id if the SDK decided to send the event (see `sentry_sdk.client._Client.capture_event()`).

  property client: BaseClient | None

    Deprecated since version 2.0.0: This property is deprecated and will be removed in a future release. Please use `sentry_sdk.api.get_client()` instead.

    Returns the current client on the hub.

  configure_scope(callback=None, continue_trace=True)
    Overloads:

      - self, callback (Optional[None]) → ContextManager[Scope]

      - self, callback (Callable[[Scope], None]) → None

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release.

    Reconfigures the scope.

    Parameters:

      callback (Optional[Callable[[Scope], None]]) – If provided, call the callback with the current scope.

    Returns:

      If no callback is provided, returns a context manager that returns the scope.

  continue_trace(environ_or_headers, op=None, name=None, source=None)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.continue_trace()` instead.

    Sets the propagation context from environment or headers and returns a transaction.

    Return type:

      `Transaction`

  end_session()

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.end_session()` instead.

    Ends the current session if there is one.

    Return type:

      `None`

  flush(timeout=None, callback=None)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.client._Client.flush()` instead.

    Alias for `sentry_sdk.client._Client.flush()`

    Return type:

      `None`

  get_baggage()

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.get_baggage()` instead.

    Returns Baggage either from the active span or from the scope.

    Return type:

      `str` | `None`

  get_integration(name_or_class)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `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 type:

      Any

  get_traceparent()

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.get_traceparent()` instead.

    Returns the traceparent either from the active span or from the scope.

    Return type:

      `str` | `None`

  iter_trace_propagation_headers(span=None)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `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 type:

      `Generator`[`Tuple`[`str`, `str`], `None`, `None`]

  last_event_id()

    Returns the last event ID.

    Deprecated since version 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.

    Return type:

      `str` | `None`

  pop_scope_unsafe()

    Deprecated since version 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 `push_scope()` instead.

    Return type:

      Tuple[Optional[Client], Scope]

  push_scope(callback=None, continue_trace=True)
    Overloads:

      - self, callback (Optional[None]) → ContextManager[Scope]

      - self, callback (Callable[[Scope], None]) → None

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release.

    Pushes a new layer on the scope stack.

    Parameters:

      callback (Optional[Callable[[Scope], None]]) – 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.

  resume_auto_session_tracking()

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `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.

    Return type:

      `None`

  run(callback)

    Deprecated since version 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.

    Return type:

      T

  property scope: Scope

    Deprecated since version 2.0.0: This property is deprecated and will be removed in a future release. Returns the current scope on the hub.

  start_session(session_mode='application')

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.start_session()` instead.

    Starts a new session.

    Return type:

      `None`

  start_span(instrumenter='sentry', **kwargs)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `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 `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 `sentry_sdk.start_transaction()` to start a new transaction when one is not already in progress.

    For supported **kwargs see `sentry_sdk.tracing.Span`.

    Return type:

      `Span`

  start_transaction(transaction=None, instrumenter='sentry', custom_sampling_context=None, **kwargs)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `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 `sentry_sdk.tracing.Transaction`.

    Return type:

      Union[Transaction, NoOpSpan]

  stop_auto_session_tracking()

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `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.

    Return type:

      `None`

  trace_propagation_meta(span=None)

    Deprecated since version 2.0.0: This function is deprecated and will be removed in a future release. Please use `sentry_sdk.Scope.trace_propagation_meta()` instead.

    Return meta tags which should be injected into HTML templates to allow propagation of trace information.

    Return type:

      `str`

class sentry_sdk.Scope(ty=None, client=None)

  The scope holds extra information that should be sent with all events that belong to it.

  add_attachment(bytes=None, filename=None, path=None, content_type=None, add_to_transactions=False)

    Adds an attachment to future events sent from this scope.

    The parameters are the same as for the `sentry_sdk.attachments.Attachment` constructor.

    Return type:

      `None`

  add_breadcrumb(crumb=None, hint=None, **kwargs)

    Adds a breadcrumb.

    Parameters:

      - crumb (Optional[Breadcrumb]) – Dictionary with the data as the sentry v7/v8 protocol expects.

      - hint (Optional[BreadcrumbHint]) – An optional value that can be used by before_breadcrumb to customize the breadcrumbs that are emitted.

    Return type:

      `None`

  add_error_processor(func, cls=None)

    Register a scope local error processor on the scope.

    Parameters:

      - func (ErrorProcessor) – A callback that works similar to an event processor but is invoked with the original exception info triple as second argument.

      - cls (Optional[Type[BaseException]]) – Optionally, only process exceptions of this type.

    Return type:

      `None`

  add_event_processor(func)

    Register a scope local event processor on the scope.

    Parameters:

      func (EventProcessor) – This function behaves like before_send.

    Return type:

      `None`

  apply_to_event(event, hint, options=None)

    Applies the information contained on the scope to the given event.

    Return type:

      Optional[Event]

  capture_event(event, hint=None, scope=None, **scope_kwargs)

    Captures an event.

    Merges given scope data and calls `sentry_sdk.client._Client.capture_event()`.

    Parameters:

      - event (Event) – A ready-made event that can be directly sent to Sentry.

      - hint (Optional[Hint]) – Contains metadata about the event that can be read from before_send, such as the original exception object or a HTTP request object.

      - scope (Optional[Scope]) – An optional `sentry_sdk.Scope` to apply to events. The scope and scope_kwargs parameters are mutually exclusive.

      - scope_kwargs (Any) – Optional data to apply to event. For supported **scope_kwargs see `sentry_sdk.Scope.update_from_kwargs()`. The scope and scope_kwargs parameters are mutually exclusive.

    Return type:

      Optional[str]

    Returns:

      An event_id if the SDK decided to send the event (see `sentry_sdk.client._Client.capture_event()`).

  capture_exception(error=None, scope=None, **scope_kwargs)

    Captures an exception.

    Parameters:

      - error (Optional[Union[BaseException, ExcInfo]]) – An exception to capture. If None, sys.exc_info() will be used.

      - scope (Optional[Scope]) – An optional `sentry_sdk.Scope` to apply to events. The scope and scope_kwargs parameters are mutually exclusive.

      - scope_kwargs (Any) – Optional data to apply to event. For supported **scope_kwargs see `sentry_sdk.Scope.update_from_kwargs()`. The scope and scope_kwargs parameters are mutually exclusive.

    Return type:

      Optional[str]

    Returns:

      An event_id if the SDK decided to send the event (see `sentry_sdk.client._Client.capture_event()`).

  capture_message(message, level=None, scope=None, **scope_kwargs)

    Captures a message.

    Parameters:

      - message (`str`) – The string to send as the message.

      - level (Optional[LogLevelStr]) – If no level is provided, the default level is info.

      - scope (Optional[Scope]) – An optional `sentry_sdk.Scope` to apply to events. The scope and scope_kwargs parameters are mutually exclusive.

      - scope_kwargs (Any) – Optional data to apply to event. For supported **scope_kwargs see `sentry_sdk.Scope.update_from_kwargs()`. The scope and scope_kwargs parameters are mutually exclusive.

    Return type:

      Optional[str]

    Returns:

      An event_id if the SDK decided to send the event (see `sentry_sdk.client._Client.capture_event()`).

  clear()

    Clears the entire scope.

    Return type:

      `None`

  clear_breadcrumbs()

    Clears breadcrumb buffer.

    Return type:

      `None`

  continue_trace(environ_or_headers, op=None, name=None, source=None, origin='manual')

    Sets the propagation context from environment or headers and returns a transaction.

    Return type:

      `Transaction`

  end_session(*args, **kwargs)

    Ends the current session if there is one.

    Return type:

      `None`

  property fingerprint

    When set this overrides the default fingerprint.

  fork()

    Added in version 2.0.0.

    Returns a fork of this scope.

    Return type:

      `Scope`

  generate_propagation_context(incoming_data=None)

    Makes sure the propagation context is set on the scope. If there is incoming_data overwrite existing propagation context. If there is no incoming_data create new propagation context, but do NOT overwrite if already existing.

    Return type:

      `None`

  get_baggage(*args, **kwargs)

    Returns the Sentry “baggage” header containing trace information from the currently active span or the scopes Propagation Context.

    Return type:

      `Baggage` | `None`

  classmethod get_client()

    Added in version 2.0.0.

    Returns the currently used `sentry_sdk.Client`. This checks the current scope, the isolation scope and the global scope for a client. If no client is available a `sentry_sdk.client.NonRecordingClient` is returned.

    Return type:

      `BaseClient`

  get_conversation_id()

    Gets the conversation ID for gen_ai spans.

    Return type:

      `str` | `None`

    Returns:

      The conversation ID, or None if not set.

  classmethod get_current_scope()

    Added in version 2.0.0.

    Returns the current scope.

    Return type:

      `Scope`

  get_dynamic_sampling_context()

    Returns the Dynamic Sampling Context from the Propagation Context. If not existing, creates a new one.

    Deprecated: Logic moved to PropagationContext, don’t use directly.

    Return type:

      `Dict`[`str`, `str`] | `None`

  classmethod get_global_scope()

    Added in version 2.0.0.

    Returns the global scope.

    Return type:

      `Scope`

  classmethod get_isolation_scope()

    Added in version 2.0.0.

    Returns the isolation scope.

    Return type:

      `Scope`

  get_trace_context()

    Returns the Sentry “trace” context from the Propagation Context.

    Return type:

      `Dict`[`str`, `Any`]

  get_traceparent(*args, **kwargs)

    Returns the Sentry “sentry-trace” header (aka the traceparent) from the currently active span or the scopes Propagation Context.

    Return type:

      `str` | `None`

  iter_headers()

    Creates a generator which returns the sentry-trace and baggage headers from the Propagation Context. Deprecated: use PropagationContext.iter_headers instead.

    Return type:

      `Iterator`[`Tuple`[`str`, `str`]]

  iter_trace_propagation_headers(*args, **kwargs)

    Return HTTP headers which allow propagation of trace data.

    If a span is given, the trace data will taken from the span. If no span is given, the trace data is taken from the scope.

    Return type:

      `Generator`[`Tuple`[`str`, `str`], `None`, `None`]

  classmethod last_event_id()

    Added in version 2.2.0.

    Returns event ID of the event most recently captured by the isolation scope, or None if no event has been captured. We do not consider events that are dropped, e.g. by a before_send hook. Transactions also are not considered events in this context.

    The event corresponding to the returned event ID is NOT guaranteed to actually be sent to Sentry; whether the event is sent depends on the transport. The event could be sent later or not at all. Even a sent event could fail to arrive in Sentry due to network issues, exhausted quotas, or various other reasons.

    Return type:

      `str` | `None`

  property level

    When set this overrides the level.

    Deprecated since version 1.0.0: Use `set_level()` instead.

    Parameters:

      value – The level to set.

  remove_attribute(attribute)

    Remove an attribute if set on the scope. No-op if there is no such attribute.

    Return type:

      `None`

  remove_context(key)

    Removes a context.

    Return type:

      `None`

  remove_conversation_id()

    Removes the conversation ID.

    Return type:

      `None`

  remove_extra(key)

    Removes a specific extra key.

    Return type:

      `None`

  remove_tag(key)

    Removes a specific tag.

    Parameters:

      key (`str`) – Key of the tag to remove.

    Return type:

      `None`

  resume_auto_session_tracking()

    Resumes automatic session tracking for the current scope if disabled earlier. This requires that generally automatic session tracking is enabled.

    Return type:

      `None`

  run_error_processors(event, hint)

    Runs the error processors on the event and returns the modified event.

    Return type:

      Optional[Event]

  run_event_processors(event, hint)

    Runs the event processors on the event and returns the modified event.

    Return type:

      Optional[Event]

  set_attribute(attribute, value)

    Set an attribute on the scope.

    Any attributes-based telemetry (logs, metrics) captured while this scope is active will inherit attributes set on the scope.

    Return type:

      `None`

  set_client(client=None)

    Added in version 2.0.0.

    Sets the client for this scope.

    Parameters:

      client (`BaseClient` | `None`) – The client to use in this scope. If None the client of the scope will be replaced by a `sentry_sdk.NonRecordingClient`.

    Return type:

      `None`

  set_context(key, value)

    Binds a context at a certain key to a specific value.

    Return type:

      `None`

  set_conversation_id(conversation_id)

    Sets the conversation ID for gen_ai spans.

    Parameters:

      conversation_id (`str`) – The conversation ID to set.

    Return type:

      `None`

  classmethod set_current_scope(new_current_scope)

    Added in version 2.0.0.

    Sets the given scope as the new current scope overwriting the existing current scope. :type new_current_scope: `Scope` :param new_current_scope: The scope to set as the new current scope.

    Return type:

      `None`

  set_extra(key, value)

    Sets an extra key to a specific value.

    Return type:

      `None`

  classmethod set_isolation_scope(new_isolation_scope)

    Added in version 2.0.0.

    Sets the given scope as the new isolation scope overwriting the existing isolation scope. :type new_isolation_scope: `Scope` :param new_isolation_scope: The scope to set as the new isolation scope.

    Return type:

      `None`

  set_level(value)

    Sets the level for the scope.

    Parameters:

      value (LogLevelStr) – The level to set.

    Return type:

      `None`

  set_new_propagation_context()

    Creates a new propagation context and sets it as _propagation_context. Overwriting existing one.

    Return type:

      `None`

  set_tag(key, value)

    Sets a tag for a key to a specific value.

    Parameters:

      - key (`str`) – Key of the tag to set.

      - value (`Any`) – Value of the tag to set.

    Return type:

      `None`

  set_tags(tags)

    Sets multiple tags at once.

    This method updates multiple tags at once. The tags are passed as a dictionary or other mapping type.

    Calling this method is equivalent to calling set_tag on each key-value pair in the mapping. If a tag key already exists in the scope, its value will be updated. If the tag key does not exist in the scope, the key-value pair will be added to the scope.

    This method only modifies tag keys in the tags mapping passed to the method. scope.set_tags({}) is, therefore, a no-op.

    Parameters:

      tags (`Mapping`[`str`, `object`]) – A mapping of tag keys to tag values to set.

    Return type:

      `None`

  set_transaction_name(name, source=None)

    Set the transaction name and optionally the transaction source.

    Return type:

      `None`

  set_user(value)

    Sets a user for the scope.

    Return type:

      `None`

  property span: Span | None

    Get/set current tracing span or transaction.

  start_session(*args, **kwargs)

    Starts a new session.

    Return type:

      `None`

  start_span(instrumenter='sentry', **kwargs)

    Start a span whose parent is the currently active span or transaction, if any.

    The return value is a `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 `sentry_sdk.start_transaction()` to start a new transaction when one is not already in progress.

    For supported **kwargs see `sentry_sdk.tracing.Span`.

    The instrumenter parameter is deprecated for user code, and it will be removed in the next major version. Going forward, it should only be used by the SDK itself.

    Return type:

      `Span`

  start_transaction(transaction=None, instrumenter='sentry', custom_sampling_context=None, **kwargs)

    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.

    Parameters:

      - transaction (Optional[Transaction]) – The transaction to start. If omitted, we create and start a new transaction.

      - instrumenter (`str`) – This parameter is meant for internal use only. It will be removed in the next major version.

      - custom_sampling_context (Optional[SamplingContext]) – The transaction’s custom sampling context.

      - kwargs (Unpack[TransactionKwargs]) – Optional keyword arguments to be passed to the Transaction constructor. See `sentry_sdk.tracing.Transaction` for available arguments.

    Return type:

      Union[Transaction, NoOpSpan]

  stop_auto_session_tracking(*args, **kwargs)

    Stops automatic session tracking.

    This temporarily session tracking for the current scope when called. To resume session tracking call resume_auto_session_tracking.

    Return type:

      `None`

  property streamed_span: StreamedSpan | None

    Get/set current tracing span.

  trace_propagation_meta(*args, **kwargs)

    Return meta tags which should be injected into HTML templates to allow propagation of trace information.

    Return type:

      `str`

  property transaction: Any

    Return the transaction (root span) in the scope, if any.

  update_from_kwargs(user=None, level=None, extras=None, contexts=None, tags=None, fingerprint=None, attributes=None)

    Update the scope’s attributes.

    Return type:

      `None`

  update_from_scope(scope)

    Update the scope with another scope’s data.

    Return type:

      `None`

  property user

    When set a specific user is bound to the scope. Deprecated in favor of set_user.

sentry_sdk.Client

  alias of `_Client`

class sentry_sdk.client.BaseClient(options=None)

  Added in version 2.0.0.

  The basic definition of a client that is used for sending data to Sentry.

  is_active()

    Added in version 2.0.0.

    Returns whether the client is active (able to send data to Sentry)

    Return type:

      `bool`

class sentry_sdk.client.NonRecordingClient(options=None)

  Added in version 2.0.0.

  A client that does not send any events to Sentry. This is used as a fallback when the Sentry SDK is not yet initialized.

class sentry_sdk.client._Client(*args, **kwargs)

  The client is internally responsible for capturing the events and forwarding them to sentry through the configured transport. It takes the client options as keyword arguments and optionally the DSN as first argument.

  Alias of `sentry_sdk.Client`. (Was created for better intelisense support)

  capture_event(event, hint=None, scope=None)

    Captures an event.

    Parameters:

      - event (Event) – A ready-made event that can be directly sent to Sentry.

      - hint (Optional[Hint]) – Contains metadata about the event that can be read from before_send, such as the original exception object or a HTTP request object.

      - scope (Optional[Scope]) – An optional `sentry_sdk.Scope` to apply to events.

    Return type:

      Optional[str]

    Returns:

      An event ID. May be None if there is no DSN set or of if the SDK decided to discard the event for other reasons. In such situations setting debug=True on init() may help.

  close(timeout=None, callback=None)

    Close the client and shut down the transport. Arguments have the same semantics as `Client.flush()`.

    Return type:

      `None`

  async close_async(timeout=None, callback=None)

    Asynchronously close the client and shut down the transport. Arguments have the same semantics as `Client.flush_async()`.

    Return type:

      `None`

  property dsn: str | None

    Returns the configured DSN as string.

  flush(timeout=None, callback=None)

    Wait for the current events to be sent.

    Parameters:

      - timeout (`float` | `None`) – Wait for at most timeout seconds. If no timeout is provided, the shutdown_timeout option value is used.

      - callback (`Callable`[[`int`, `float`], `None`] | `None`) – Is invoked with the number of pending events and the configured timeout.

    Return type:

      `None`

  async flush_async(timeout=None, callback=None)

    Asynchronously wait for the current events to be sent.

    Parameters:

      - timeout (`float` | `None`) – Wait for at most timeout seconds. If no timeout is provided, the shutdown_timeout option value is used.

      - callback (`Callable`[[`int`, `float`], `None`] | `None`) – Is invoked with the number of pending events and the configured timeout.

    Return type:

      `None`

  get_integration(name_or_class)
    Overloads:

      - self, name_or_class (str) → Optional[Integration]

      - self, name_or_class (type[I]) → Optional[I]

    Returns the integration for this client by name or class. If the client does not have that integration then None is returned.

  is_active()

    Added in version 2.0.0.

    Returns whether the client is active (able to send data to Sentry)

    Return type:

      `bool`

  property parsed_dsn: Dsn | None

    Returns the configured parsed DSN object.

  should_send_default_pii()

    Added in version 2.0.0.

    Returns whether the client should send default PII (Personally Identifiable Information) data to Sentry.

    Return type:

      `bool`

class sentry_sdk.Transport(options=None)

  Baseclass for all transports.

  A transport is used to send an event to sentry.

  abstractmethod capture_envelope(envelope)

    Send an envelope to Sentry.

    Envelopes are a data container format that can hold any type of data submitted to Sentry. We use it to send all event data (including errors, transactions, crons check-ins, etc.) to Sentry.

    Return type:

      `None`

  capture_event(event)

    DEPRECATED: Please use capture_envelope instead.

    This gets invoked with the event dictionary when an event should be sent to sentry.

    Return type:

      `None`

  flush(timeout, callback=None)

    Wait timeout seconds for the current events to be sent out.

    The default implementation is a no-op, since this method may only be relevant to some transports. Subclasses should override this method if necessary.

    Return type:

      `None`

  kill()

    Forcefully kills the transport.

    The default implementation is a no-op, since this method may only be relevant to some transports. Subclasses should override this method if necessary.

    Return type:

      `None`

  record_lost_event(reason, data_category=None, item=None, *, quantity=1)

    This increments a counter for event loss by reason and data category by the given positive-int quantity (default 1).

    If an item is provided, the data category and quantity are extracted from the item, and the values passed for data_category and quantity are ignored.

    When recording a lost transaction via data_category=”transaction”, the calling code should also record the lost spans via this method. When recording lost spans, quantity should be set to the number of contained spans, plus one for the transaction itself. When passing an Item containing a transaction via the item parameter, this method automatically records the lost spans.

    Return type:

      `None`

class sentry_sdk.HttpTransport(options)

class sentry_sdk.tracing.Transaction(name='', parent_sampled=None, baggage=None, source=TransactionSource.CUSTOM, **kwargs)

  The Transaction is the root element that holds all the spans for Sentry performance instrumentation.

  Parameters:

    - name (`str`) – Identifier of the transaction. Will show up in the Sentry UI.

    - parent_sampled (Optional[bool]) – Whether the parent transaction was sampled. If True this transaction will be kept, if False it will be discarded.

    - baggage (Optional[Baggage]) – The W3C baggage header value. (see https://www.w3.org/TR/baggage/)

    - source (`str`) – A string describing the source of the transaction name. This will be used to determine the transaction’s type. See https://develop.sentry.dev/sdk/event-payloads/transaction/#transaction-annotations for more information. Default “custom”.

    - kwargs (Unpack[SpanKwargs]) – Additional arguments to be passed to the Span constructor. See `sentry_sdk.tracing.Span` for available arguments.

  property containing_transaction: Transaction

    The root element of the span tree. In the case of a transaction it is the transaction itself.

  finish(scope=None, end_timestamp=None, *, hub=None)

    Finishes the transaction and sends it to Sentry. All finished spans in the transaction will also be sent to Sentry.

    Parameters:

      - scope (`Scope` | `None`) – The Scope to use for this transaction. If not provided, the current Scope will be used.

      - end_timestamp (`float` | `datetime` | `None`) – Optional timestamp that should be used as timestamp instead of the current time.

      - hub (`Hub` | `None`) – The hub to use for this transaction. This argument is DEPRECATED. Please use the scope parameter, instead.

    Return type:

      `str` | `None`

    Returns:

      The event ID if the transaction was sent to Sentry, otherwise None.

  get_baggage()

    Returns the `Baggage` associated with the Transaction.

    The first time a new baggage with Sentry items is made, it will be frozen.

    Return type:

      `Baggage`

  set_context(key, value)

    Sets a context. Transactions can have multiple contexts and they should follow the format described in the “Contexts Interface” documentation.

    Parameters:

      - key (`str`) – The name of the context.

      - value (`dict`[`str`, `Any`]) – The information about the context.

    Return type:

      `None`

  set_http_status(http_status)

    Sets the status of the Transaction according to the given HTTP status.

    Parameters:

      http_status (`int`) – The HTTP status code.

    Return type:

      `None`

  set_measurement(name, value, unit='')

    Deprecated since version 2.28.0: This function is deprecated and will be removed in the next major release.

    Return type:

      `None`

  to_json()

    Returns a JSON-compatible representation of the transaction.

    Return type:

      `Dict`[`str`, `Any`]

class sentry_sdk.tracing.Span(trace_id=None, span_id=None, parent_span_id=None, same_process_as_parent=True, sampled=None, op=None, description=None, hub=None, status=None, containing_transaction=None, start_timestamp=None, scope=None, origin='manual', name=None)

  A span holds timing information of a block of code. Spans can have multiple child spans thus forming a span tree.

  Parameters:

    - trace_id (`str` | `None`) – The trace ID of the root span. If this new span is to be the root span, omit this parameter, and a new trace ID will be generated.

    - span_id (`str` | `None`) – The span ID of this span. If omitted, a new span ID will be generated.

    - parent_span_id (`str` | `None`) – The span ID of the parent span, if applicable.

    - same_process_as_parent (`bool`) – Whether this span is in the same process as the parent span.

    - sampled (`bool` | `None`) – Whether the span should be sampled. Overrides the default sampling decision for this span when provided.

    - op (`str` | `None`) – The span’s operation. A list of recommended values is available here: https://develop.sentry.dev/sdk/performance/span-operations/

    - description (`str` | `None`) –

      A description of what operation is being performed within the span.

      Deprecated since version 2.15.0: Please use the name parameter, instead.

    - name (`str` | `None`) – A string describing what operation is being performed within the span.

    - hub (`Hub` | `None`) –

      The hub to use for this span.

      Deprecated since version 2.0.0: Please use the scope parameter, instead.

    - status (`str` | `None`) – The span’s status. Possible values are listed at https://develop.sentry.dev/sdk/event-payloads/span/

    - containing_transaction (`Transaction` | `None`) – The transaction that this span belongs to.

    - start_timestamp (`float` | `datetime` | `None`) – The timestamp when the span started. If omitted, the current time will be used.

    - scope (`Scope` | `None`) – The scope to use for this span. If not provided, we use the current scope.

  property containing_transaction: Transaction | None

    The `Transaction` that this span belongs to. The `Transaction` is the root of the span tree, so one could also think of this `Transaction` as the “root span”.

  classmethod continue_from_environ(environ, **kwargs)

    DEPRECATED: Use `sentry_sdk.continue_trace()`.

    Create a Transaction with the given params, then add in data pulled from the `sentry-trace` and `baggage` headers from the environ (if any) before returning the Transaction.

    This is different from `continue_from_headers()` in that it assumes header names in the form `HTTP_HEADER_NAME` - such as you would get from a WSGI/ASGI environ - rather than the form `header-name`.

    Parameters:

      environ (`Mapping`[`str`, `str`]) – The ASGI/WSGI environ to pull information from.

    Return type:

      `Transaction`

  classmethod continue_from_headers(headers, *, _sample_rand=None, **kwargs)

    DEPRECATED: Use `sentry_sdk.continue_trace()`.

    Create a transaction with the given params (including any data pulled from the `sentry-trace` and `baggage` headers).

    Parameters:

      - headers (`Mapping`[`str`, `str`]) – The dictionary with the HTTP headers to pull information from.

      - _sample_rand (`str` | `None`) – If provided, we override the sample_rand value from the incoming headers with this value. (internal use only)

    Return type:

      `Transaction`

  finish(scope=None, end_timestamp=None)

    Sets the end timestamp of the span.

    Additionally it also creates a breadcrumb from the span, if the span represents a database or HTTP request.

    Parameters:

      - scope (`Scope` | `None`) – The scope to use for this transaction. If not provided, the current scope will be used.

      - end_timestamp (`float` | `datetime` | `None`) – Optional timestamp that should be used as timestamp instead of the current time.

    Return type:

      `str` | `None`

    Returns:

      Always `None`. The type is `Optional[str]` to match the return value of `sentry_sdk.tracing.Transaction.finish()`.

  classmethod from_traceparent(traceparent, **kwargs)

    DEPRECATED: Use `sentry_sdk.continue_trace()`.

    Create a `Transaction` with the given params, then add in data pulled from the given `sentry-trace` header value before returning the `Transaction`.

    Return type:

      `Transaction` | `None`

  iter_headers()

    Creates a generator which returns the span’s `sentry-trace` and `baggage` headers. If the span’s containing transaction doesn’t yet have a `baggage` value, this will cause one to be generated and stored.

    Return type:

      `Iterator`[`Tuple`[`str`, `str`]]

  set_measurement(name, value, unit='')

    Deprecated since version 2.28.0: This function is deprecated and will be removed in the next major release.

    Return type:

      `None`

  start_child(instrumenter='sentry', **kwargs)

    Start a sub-span from the current span or transaction.

    Takes the same arguments as the initializer of `Span`. The trace id, sampling decision, transaction pointer, and span recorder are inherited from the current span/transaction.

    The instrumenter parameter is deprecated for user code, and it will be removed in the next major version. Going forward, it should only be used by the SDK itself.

    Return type:

      `Span`

  timestamp: datetime | None

    End timestamp of span

  to_baggage()

    Returns the `Baggage` associated with this `Span`, if any. (Taken from the root of the span tree.)

    Return type:

      `Baggage` | `None`

  to_json()

    Returns a JSON-compatible representation of the span.

    Return type:

      `Dict`[`str`, `Any`]

class sentry_sdk.profiler.transaction_profiler.Profile(sampled, start_ns, hub=None, scheduler=None)

class sentry_sdk.session.Session(sid=None, did=None, timestamp=None, started=None, duration=None, status=None, release=None, environment=None, user_agent=None, ip_address=None, errors=None, user=None, session_mode='application')

class sentry_sdk.attachments.Attachment(bytes=None, filename=None, path=None, content_type=None, add_to_transactions=False)

  Additional files/data to send along with an event.

  This class stores attachments that can be sent along with an event. Attachments are files or other data, e.g. config or log files, that are relevant to an event. Attachments are set on the `Scope`, and are sent along with all non-transaction events (or all events including transactions if `add_to_transactions` is `True`) that are captured within the `Scope`.

  To add an attachment to a `Scope`, use `sentry_sdk.Scope.add_attachment()`. The parameters for `add_attachment` are the same as the parameters for this class’s constructor.

  Parameters:

    - bytes (`None` | `bytes` | `Callable`[[], `bytes`]) – Raw bytes of the attachment, or a function that returns the raw bytes. Must be provided unless `path` is provided.

    - filename (`str` | `None`) – The filename of the attachment. Must be provided unless `path` is provided.

    - path (`str` | `None`) – Path to a file to attach. Must be provided unless `bytes` is provided.

    - content_type (`str` | `None`) – The content type of the attachment. If not provided, it will be guessed from the `filename` parameter, if available, or the `path` parameter if `filename` is `None`.

    - add_to_transactions (`bool`) – Whether to add this attachment to transactions. Defaults to `False`.

  to_envelope_item()

    Returns an envelope item for this attachment.

    Return type:

      `Item`

class sentry_sdk.scrubber.EventScrubber(denylist=None, recursive=False, send_default_pii=False, pii_denylist=None)
  scrub_dict(d)

    If a dictionary is passed to this method, the method scrubs the dictionary of any sensitive data. The method calls itself recursively on any nested dictionaries ( including dictionaries nested in lists) if self.recursive is True. This method does nothing if the parameter passed to it is not a dictionary.

    Return type:

      `None`

  scrub_list(lst)

    If a list is passed to this method, the method recursively searches the list and any nested lists for any dictionaries. The method calls scrub_dict on all dictionaries it finds. If the parameter passed to this method is not a list, the method does nothing.

    Return type:

      `None`

class sentry_sdk.monitor.Monitor(transport, interval=10)

  Performs health checks in a separate thread once every interval seconds and updates the internal state. Other parts of the SDK only read this state and act accordingly.

  check_health()

    Perform the actual health checks, currently only checks if the transport is rate-limited. TODO: augment in the future with more checks.

    Return type:

      `None`

class sentry_sdk.envelope.Envelope(headers=None, items=None)

  Represents a Sentry Envelope. The calling code is responsible for adhering to the constraints documented in the Sentry docs: https://develop.sentry.dev/sdk/envelopes/#data-model. In particular, each envelope may have at most one Item with type “event” or “transaction” (but not both).

class sentry_sdk.envelope.Item(payload, headers=None, type=None, content_type=None, filename=None)
  get_event()

    Returns an error event if there is one.

    Return type:

      Optional[Event]