Socket

Learn about the Socket integration and how it adds support network actions.

Use this integration to create spans for DNS resolves and socket connection creations.

Install

Install `sentry-sdk`` from PyPI.

Copied
pip install "sentry-sdk"

Configure

Add SocketIntegration() to your integrations list:

In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling.

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

Copied
import sentry_sdk
from sentry_sdk.integrations.socket import SocketIntegration

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0
example-org / example-project
"
,
# Add data like request headers and IP for users, if applicable; # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info send_default_pii=True, # performance # Set traces_sample_rate to 1.0 to capture 100% # of transactions for tracing. traces_sample_rate=1.0, # performance # profiling # To collect profiles for all profile sessions, # set `profile_session_sample_rate` to 1.0. profile_session_sample_rate=1.0, # Profiles will be automatically collected while # there is an active span. profile_lifecycle="trace", # profiling integrations=[ SocketIntegration(), ], )

Verify

Copied
import socket

def main():
    sentry_init(...)  # same as above
    with sentry_sdk.start_transaction(name="testing_sentry"):
        timeout = 10
        socket.getaddrinfo("sentry.io", 443)
        socket.create_connection(("sentry.io", 443), timeout, None)
main()

This example will create a transaction called testing_sentry in the Performance section of sentry.io, and create spans for the socket commands.

It takes a couple of moments for the data to appear in sentry.io.

Supported Versions

  • Python: 3.6+

The versions above apply for the current major version of the Python SDK. If you're looking to use Sentry with older Python or framework versions, consider using an older major version of the SDK.

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").