Skip to content

Commit 1f537de

Browse files
committed
Add parsed_dsn reference to client
1 parent a76280b commit 1f537de

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

sentry_sdk/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
from sentry_sdk.transport import Transport, Item
7171
from sentry_sdk._log_batcher import LogBatcher
7272
from sentry_sdk._metrics_batcher import MetricsBatcher
73+
from sentry_sdk.utils import Dsn
7374

7475
I = TypeVar("I", bound=Integration) # noqa: E741
7576

@@ -201,6 +202,11 @@ def dsn(self):
201202
# type: () -> Optional[str]
202203
return None
203204

205+
@property
206+
def parsed_dsn(self):
207+
# type: () -> Optional[Dsn]
208+
return None
209+
204210
def should_send_default_pii(self):
205211
# type: () -> bool
206212
return False
@@ -512,6 +518,12 @@ def dsn(self):
512518
"""Returns the configured DSN as string."""
513519
return self.options["dsn"]
514520

521+
@property
522+
def parsed_dsn(self):
523+
# type: () -> Optional[Dsn]
524+
"""Returns the configured parsed DSN object."""
525+
return self.transport.parsed_dsn if self.transport else None
526+
515527
def _prepare_event(
516528
self,
517529
event, # type: Event

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
)
2424
from sentry_sdk.scope import add_global_event_processor
2525
from sentry_sdk.tracing import Transaction, Span as SentrySpan
26-
from sentry_sdk.utils import Dsn
2726

2827
from urllib3.util import parse_url as urlparse
2928

@@ -113,12 +112,7 @@ def on_start(self, otel_span, parent_context=None):
113112
# type: (OTelSpan, Optional[context_api.Context]) -> None
114113
client = get_client()
115114

116-
if not client.dsn:
117-
return
118-
119-
try:
120-
_ = Dsn(client.dsn)
121-
except Exception:
115+
if not client.parsed_dsn:
122116
return
123117

124118
if client.options["instrumenter"] != INSTRUMENTER.OTEL:
@@ -233,10 +227,8 @@ def _is_sentry_span(self, otel_span):
233227
otel_span_url = otel_span.attributes.get(SpanAttributes.HTTP_URL)
234228
otel_span_url = cast("Optional[str]", otel_span_url)
235229

236-
dsn_url = None
237-
client = get_client()
238-
if client.dsn:
239-
dsn_url = Dsn(client.dsn).netloc
230+
parsed_dsn = get_client().parsed_dsn
231+
dsn_url = parsed_dsn.netloc if parsed_dsn else None
240232

241233
if otel_span_url and dsn_url and dsn_url in otel_span_url:
242234
return True

sentry_sdk/tracing_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ def from_options(cls, scope):
664664
if options.get("release"):
665665
sentry_items["release"] = options["release"]
666666

667-
if options.get("dsn"):
668-
sentry_items["public_key"] = Dsn(options["dsn"]).public_key
667+
if client.parsed_dsn:
668+
sentry_items["public_key"] = client.parsed_dsn.public_key
669669

670670
if options.get("traces_sample_rate"):
671671
sentry_items["sample_rate"] = str(options["traces_sample_rate"])
@@ -696,8 +696,8 @@ def populate_from_transaction(cls, transaction):
696696
if options.get("release"):
697697
sentry_items["release"] = options["release"]
698698

699-
if options.get("dsn"):
700-
sentry_items["public_key"] = Dsn(options["dsn"]).public_key
699+
if client.parsed_dsn:
700+
sentry_items["public_key"] = client.parsed_dsn.public_key
701701

702702
if (
703703
transaction.name

0 commit comments

Comments
 (0)