0
# Configuration
1
2
SDK initialization and configuration management including DSN setup, sampling rates, integrations, transport options, and environment-specific settings.
3
4
## Capabilities
5
6
### SDK Initialization
7
8
Initialize the Sentry SDK with configuration options including DSN, sampling rates, integrations, and various client settings.
9
10
```python { .api }
11
def init(
12
dsn: Optional[str] = None,
13
integrations: Optional[List[Integration]] = None,
14
default_integrations: bool = True,
15
auto_enabling_integrations: bool = True,
16
disabled_integrations: Optional[List[Union[type, str]]] = None,
17
environment: Optional[str] = None,
18
release: Optional[str] = None,
19
traces_sample_rate: Optional[float] = None,
20
traces_sampler: Optional[Callable[[Dict[str, Any]], float]] = None,
21
profiles_sample_rate: Optional[float] = None,
22
profiles_sampler: Optional[Callable[[Dict[str, Any]], float]] = None,
23
max_breadcrumbs: int = 100,
24
attach_stacktrace: bool = False,
25
send_default_pii: bool = False,
26
in_app_include: Optional[List[str]] = None,
27
in_app_exclude: Optional[List[str]] = None,
28
before_send: Optional[Callable[[Event, Hint], Optional[Event]]] = None,
29
before_send_transaction: Optional[Callable[[Event, Hint], Optional[Event]]] = None,
30
transport: Optional[Transport] = None,
31
http_proxy: Optional[str] = None,
32
https_proxy: Optional[str] = None,
33
shutdown_timeout: int = 2,
34
debug: bool = False,
35
**kwargs
36
) -> None:
37
"""
38
Initialize the Sentry SDK.
39
40
Parameters:
41
- dsn: Data Source Name for your Sentry project
42
- integrations: List of integrations to enable
43
- default_integrations: Enable default integrations (logging, stdlib, etc.)
44
- auto_enabling_integrations: Enable auto-detected integrations (Django, Flask, etc.)
45
- disabled_integrations: List of integration types/names to disable
46
- environment: Environment name (e.g., 'production', 'staging')
47
- release: Release version identifier
48
- traces_sample_rate: Percentage of transactions to capture (0.0 to 1.0)
49
- traces_sampler: Function to determine transaction sampling
50
- profiles_sample_rate: Percentage of transactions to profile (0.0 to 1.0)
51
- profiles_sampler: Function to determine profiling sampling
52
- max_breadcrumbs: Maximum number of breadcrumbs to store
53
- attach_stacktrace: Attach stack traces to non-exception events
54
- send_default_pii: Send personally identifiable information
55
- in_app_include: List of modules to consider "in-app"
56
- in_app_exclude: List of modules to exclude from "in-app"
57
- before_send: Event processor function for events
58
- before_send_transaction: Event processor function for transactions
59
- transport: Custom transport implementation
60
- http_proxy: HTTP proxy URL
61
- https_proxy: HTTPS proxy URL
62
- shutdown_timeout: Timeout for SDK shutdown in seconds
63
- debug: Enable debug logging
64
"""
65
```
66
67
**Usage Example:**
68
69
```python
70
import sentry_sdk
71
from sentry_sdk.integrations.django import DjangoIntegration
72
from sentry_sdk.integrations.redis import RedisIntegration
73
74
sentry_sdk.init(
75
dsn="https://your-dsn@sentry.io/project-id",
76
environment="production",
77
release="my-app@1.0.0",
78
traces_sample_rate=0.1, # 10% of transactions
79
profiles_sample_rate=0.1, # 10% of transactions
80
integrations=[
81
DjangoIntegration(
82
transaction_style='url',
83
middleware_spans=True,
84
signals_spans=True,
85
),
86
RedisIntegration(),
87
],
88
max_breadcrumbs=50,
89
attach_stacktrace=True,
90
send_default_pii=False,
91
before_send=lambda event, hint: event if should_send_event(event) else None,
92
)
93
```
94
95
### Initialization Status
96
97
Check whether the SDK has been properly initialized and is ready to capture events.
98
99
```python { .api }
100
def is_initialized() -> bool:
101
"""
102
Check if Sentry SDK has been initialized.
103
104
Returns:
105
bool: True if SDK is initialized and client is active, False otherwise
106
"""
107
```
108
109
**Usage Example:**
110
111
```python
112
import sentry_sdk
113
114
if not sentry_sdk.is_initialized():
115
sentry_sdk.init(dsn="https://your-dsn@sentry.io/project-id")
116
117
# Now safe to use other SDK functions
118
sentry_sdk.capture_message("SDK is ready!")
119
```
120
121
## Configuration Options
122
123
### DSN (Data Source Name)
124
125
The DSN is the connection string that tells the SDK where to send events. It includes the protocol, public key, server address, and project ID.
126
127
**Format:** `https://{PUBLIC_KEY}@{HOSTNAME}/{PROJECT_ID}`
128
129
### Sampling
130
131
Control what percentage of events and transactions are sent to Sentry to manage volume and costs.
132
133
- **traces_sample_rate**: Float between 0.0 and 1.0 for uniform sampling
134
- **traces_sampler**: Function for custom sampling logic
135
- **profiles_sample_rate**: Float for profiling sampling (requires traces_sample_rate > 0)
136
- **profiles_sampler**: Function for custom profiling sampling logic
137
138
### Event Processing
139
140
- **before_send**: Function to filter or modify events before sending
141
- **before_send_transaction**: Function to filter or modify transactions before sending
142
- **in_app_include/exclude**: Control which modules are considered part of your application
143
144
### Integration Control
145
146
- **default_integrations**: Enable/disable standard integrations (logging, stdlib, etc.)
147
- **auto_enabling_integrations**: Enable/disable automatic framework detection
148
- **integrations**: Explicit list of integrations to enable
149
- **disabled_integrations**: List of integrations to disable
150
151
### Privacy and Security
152
153
- **send_default_pii**: Whether to send personally identifiable information
154
- **attach_stacktrace**: Add stack traces to non-exception events
155
- **max_breadcrumbs**: Limit breadcrumb storage (default: 100)
156
157
### Performance and Reliability
158
159
- **shutdown_timeout**: Time to wait for pending events during shutdown
160
- **transport**: Custom transport implementation for event delivery
161
- **http_proxy/https_proxy**: Proxy configuration for network requests