Skip to content

Commit 6ec18ef

Browse files
committed
chore: add some options
1 parent 67ccb20 commit 6ec18ef

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

sentry_sdk/client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
class Client(object):
1616
def __init__(self, dsn=None, *args, **kwargs):
17+
passed_dsn = dsn
1718
if dsn is NO_DSN:
1819
dsn = None
1920
else:
@@ -26,14 +27,14 @@ def __init__(self, dsn=None, *args, **kwargs):
2627
options = dict(DEFAULT_OPTIONS)
2728
options.update(*args, **kwargs)
2829
self.options = options
29-
if dsn is None:
30-
self._transport = None
31-
else:
30+
self._transport = self.options.pop('transport')
31+
if self._transport is None and dsn is not None:
3232
self._transport = Transport(dsn)
3333
self._transport.start()
34+
elif passed_dsn is not None and self._transport is not None:
35+
raise ValueError("Cannot pass DSN and a custom transport.")
3436

3537
from .integrations import logging as logging_integration
36-
3738
integrations = list(options.pop("integrations") or ())
3839

3940
logging_configured = any(
@@ -68,7 +69,7 @@ def _prepare_event(self, event, scope):
6869
if scope is not None:
6970
scope.apply_to_event(event)
7071

71-
for key in "release", "environment", "server_name":
72+
for key in "release", "environment", "server_name", "repos", "dist":
7273
if event.get(key) is None:
7374
event[key] = self.options[key]
7475
if event.get("sdk") is None:

sentry_sdk/consts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"drain_timeout": 2.0,
1212
"integrations": [],
1313
"default_integrations": True,
14+
'repos': {},
15+
'dist': None,
16+
'transport': None
1417
}
1518

1619
SDK_INFO = {"name": "sentry-python", "version": VERSION}

tests/test_client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
from sentry_sdk import Client
3+
from sentry_sdk.transport import Transport
4+
5+
def test_transport_option(monkeypatch):
6+
dsn = 'https://[email protected]/123'
7+
dsn2 = 'https://[email protected]/124'
8+
assert str(Client(dsn=dsn).dsn) == dsn
9+
assert Client().dsn is None
10+
with pytest.raises(ValueError):
11+
Client(dsn, transport=Transport(dsn2))
12+
with pytest.raises(ValueError):
13+
Client(dsn, transport=Transport(dsn))
14+
assert str(Client(transport=Transport(dsn2)).dsn) == dsn2
15+
16+
monkeypatch.setenv("SENTRY_DSN", dsn)
17+
assert str(Client(transport=Transport(dsn2)).dsn) == dsn2

0 commit comments

Comments
 (0)