API Docs

sentry_sdk.Scope

alias of PotelScope

class sentry_sdk.Client(dsn=None, *, max_breadcrumbs=100, release=None, environment=None, server_name=None, shutdown_timeout=2, integrations=[], in_app_include=[], in_app_exclude=[], default_integrations=True, dist=None, transport=None, transport_queue_size=100, sample_rate=1.0, send_default_pii=None, http_proxy=None, https_proxy=None, ignore_errors=[], max_request_body_size='medium', socket_options=None, keep_alive=None, before_send=None, before_breadcrumb=None, debug=None, attach_stacktrace=False, ca_certs=None, traces_sample_rate=None, traces_sampler=None, profiles_sample_rate=None, profiles_sampler=None, profiler_mode=None, profile_lifecycle='manual', profile_session_sample_rate=None, auto_enabling_integrations=True, disabled_integrations=None, auto_session_tracking=True, send_client_reports=True, _experiments={}, proxy_headers=None, before_send_transaction=None, project_root=None, include_local_variables=True, include_source_context=True, trace_propagation_targets=['.*'], functions_to_trace=[], event_scrubber=None, max_value_length=1024, enable_backpressure_handling=True, error_sampler=None, enable_db_query_source=True, db_query_source_threshold_ms=100, spotlight=None, cert_file=None, key_file=None, custom_repr=None, add_full_stack=False, max_stack_frames=100)[source]
class sentry_sdk.client.BaseClient(options=None)[source]

Added in version 2.0.0.

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

is_active()[source]
Return type:

bool

Added in version 2.0.0.

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

class sentry_sdk.client.NonRecordingClient(options=None)[source]

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)[source]

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)[source]

Captures an event.

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

  • hint (Optional[Dict[str, Any]]) – 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)[source]

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

Return type:

None

property dsn: str | None

Returns the configured DSN as string.

flush(timeout=None, callback=None)[source]

Wait for the current events to be sent.

Parameters:
  • timeout (Optional[float]) – Wait for at most timeout seconds. If no timeout is provided, the shutdown_timeout option value is used.

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

Return type:

None

get_integration(name_or_class)[source]

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

Return type:

Optional[Integration]

is_active()[source]
Return type:

bool

Added in version 2.0.0.

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

should_send_default_pii()[source]
Return type:

bool

Added in version 2.0.0.

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

class sentry_sdk.Transport(options=None)[source]

Baseclass for all transports.

A transport is used to send an event to sentry.

abstract capture_envelope(envelope)[source]

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

flush(timeout, callback=None)[source]

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()[source]

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)[source]

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)[source]
sentry_sdk.tracing.Transaction

alias of Span

class sentry_sdk.tracing.Span(*, op=None, description=None, status=None, sampled=None, start_timestamp=None, origin=None, name=None, source=TransactionSource.CUSTOM, attributes=None, only_if_parent=False, parent_span=None, otel_span=None, span=None)[source]

OTel span wrapper providing compatibility with the old span interface.

property status: str | None

Return the Sentry SPANSTATUS corresponding to the underlying OTel status. Because differences in possible values in OTel StatusCode and Sentry SPANSTATUS it can not be guaranteed that the status set in set_status() will be the same as the one returned here.

to_json()[source]

Only meant for testing. Not used internally anymore.

Return type:

dict[str, Any]

class sentry_sdk.profiler.transaction_profiler.Profile(sampled, start_ns, scheduler=None)[source]
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')[source]
class sentry_sdk.attachments.Attachment(bytes=None, filename=None, path=None, content_type=None, add_to_transactions=False)[source]

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 (Union[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 (Optional[str]) – The filename of the attachment. Must be provided unless path is provided.

  • path (Optional[str]) – Path to a file to attach. Must be provided unless bytes is provided.

  • content_type (Optional[str]) – 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()[source]

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)[source]
scrub_dict(d)[source]

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)[source]

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)[source]

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()[source]

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)[source]

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)[source]
get_event()[source]

Returns an error event if there is one.

Return type:

Optional[Event]