---
title: "Socket"
description: "Learn about the Socket integration and how it adds support network actions."
url: https://docs.sentry.io/platforms/python/integrations/socket/
---

# Socket for Python

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

In SDK `3.x`, and in stream mode in SDK `2.x`, this page's references to "transaction" apply to service spans instead. See [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md) for more information.

## [Install](https://docs.sentry.io/platforms/python/integrations/socket.md#install)

Install \`sentry-sdk\`\` from PyPI.

```bash
pip install "sentry-sdk"
```

*Other available variations of the above snippet: uv*

## [Configure](https://docs.sentry.io/platforms/python/integrations/socket.md#configure)

Add `SocketIntegration()` to your `integrations` list:

In addition to capturing errors, you can follow requests, jobs, and [agent runs](https://docs.sentry.io/product/agents.md) across services by [enabling tracing](https://docs.sentry.io/concepts/key-terms/tracing.md), and see where they fail or slow down. You can also collect and analyze performance profiles from real users with [profiling](https://docs.sentry.io/product/profiling.md).

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

Error Monitoring\[ ]Tracing\[ ]Profiling

```python
import sentry_sdk
from sentry_sdk.integrations.socket import SocketIntegration

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "user_info": True,
    },
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of service spans for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ 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",
    # ___PRODUCT_OPTION_END___ profiling
    integrations=[
        SocketIntegration(),
    ],
)
```

## [Verify](https://docs.sentry.io/platforms/python/integrations/socket.md#verify)

```python
import socket

def main():
    sentry_init(...)  # same as above

    # In SDK 2.x, use sentry_sdk.start_transaction(name="testing_sentry") instead
    with sentry_sdk.start_span(name="testing_sentry"):
        timeout = 10
        socket.getaddrinfo("sentry.io", 443)
        socket.create_connection(("sentry.io", 443), timeout, None)
main()
```

This example will create a service span called `testing_sentry` in the Traces section of [sentry.io](https://sentry.io), and create spans for the socket commands.

It takes a couple of moments for the data to appear in [sentry.io](https://sentry.io).

## [Supported Versions](https://docs.sentry.io/platforms/python/integrations/socket.md#supported-versions)

* Python:

  * 3.6+ (SDK <3.0)
  * 3.7+ (SDK 3.0+)

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

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
