From e00886faca7bc5dad125e1de0a3c56c868c391c4 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Wed, 20 Sep 2023 08:44:42 +0200 Subject: [PATCH] Python: Getting Started socket (#7859) * Getting Started: socket * style(lint): Auto commit lint changes * Made socket title caps --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> --- .../configuration/integrations/index.mdx | 2 +- .../configuration/integrations/socket.mdx | 31 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/platforms/python/common/configuration/integrations/index.mdx b/src/platforms/python/common/configuration/integrations/index.mdx index 3787c103b76f4..46c3882134202 100644 --- a/src/platforms/python/common/configuration/integrations/index.mdx +++ b/src/platforms/python/common/configuration/integrations/index.mdx @@ -46,7 +46,7 @@ If you don't want integrations to be enabled automatically, set the `default_int - [Cloud Resource Context](cloudresourcecontext/) - [Enhanced Locals](pure_eval/) - [GNU Backtrace](gnu_backtrace/) -- [SOCKET](socket/) +- [Socket](socket/) - [WSGI](wsgi/) ## Web Frameworks diff --git a/src/platforms/python/common/configuration/integrations/socket.mdx b/src/platforms/python/common/configuration/integrations/socket.mdx index a830ab15f369e..be5795b68a08d 100644 --- a/src/platforms/python/common/configuration/integrations/socket.mdx +++ b/src/platforms/python/common/configuration/integrations/socket.mdx @@ -1,14 +1,18 @@ --- -title: SOCKET +title: Socket description: "Learn about the Socket integration and how it adds support network actions." sidebar_order: 90 --- -Use this integration to create spans for dns resolves and connection creations. +Use this integration to create spans for DNS resolves and socket connection creations. ## Install -`socket` is included by default in CPython +Install `sentry-sdk`` from PyPI. + +```bash +pip install --upgrade 'sentry-sdk' +``` ## Configure @@ -22,12 +26,33 @@ from sentry_sdk.integrations.socket import SocketIntegration sentry_sdk.init( dsn="___PUBLIC_DSN___", + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + traces_sample_rate=1.0, integrations=[ SocketIntegration(), ], ) ``` +## Verify + +```python +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](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 - Python: 2.7+