Skip to content

Commit 080d31c

Browse files
committed
First tracing fix, and more tracing
1 parent b0a0ab1 commit 080d31c

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

tracekit/providers/ridewithgps/ridewithgps_provider.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,32 @@ def __init__(self, config: dict[str, Any] | None = None):
2525
self.password = (self.config or {}).get("password", "")
2626
self.apikey = (self.config or {}).get("apikey", "")
2727

28-
self.client = RideWithGPS(apikey=self.apikey, cache=True)
28+
self._client: RideWithGPS | None = None
29+
self._userid = None
30+
self._user_info = None
31+
32+
def _ensure_authenticated(self):
33+
"""Authenticate lazily — only when a live API call is actually needed."""
34+
if self._client is None:
35+
self._client = RideWithGPS(apikey=self.apikey, cache=True)
36+
user_info = self._client.authenticate(self.username, self.password)
37+
self._userid = getattr(user_info, "id", None)
38+
self._user_info = user_info
2939

30-
user_info = self.client.authenticate(self.username, self.password)
31-
self.userid = getattr(user_info, "id", None)
32-
self.user_info = user_info
40+
@property
41+
def client(self) -> RideWithGPS:
42+
self._ensure_authenticated()
43+
return self._client # type: ignore[return-value]
44+
45+
@property
46+
def userid(self):
47+
self._ensure_authenticated()
48+
return self._userid
49+
50+
@property
51+
def user_info(self):
52+
self._ensure_authenticated()
53+
return self._user_info
3354

3455
@property
3556
def provider_name(self) -> str:

tracekit/worker.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,25 @@
2222
# initialized by main.py — re-initializing here would clobber settings like
2323
# enable_logs=True and traces_sampler that are set there.
2424
if not sentry_sdk.get_client().is_active():
25+
_integrations = [CeleryIntegration(monitor_beat_tasks=True)]
26+
try:
27+
from sentry_sdk.integrations.psycopg2 import Psycopg2Integration
28+
29+
_integrations.append(Psycopg2Integration())
30+
except ImportError:
31+
pass # psycopg2 not installed (dev/SQLite)
32+
2533
sentry_sdk.init(
2634
dsn=_sentry_dsn,
35+
release=os.getenv("SENTRY_RELEASE"),
2736
environment=os.getenv("SENTRY_ENV", "production"),
28-
send_default_pii=True,
2937
traces_sample_rate=1.0,
30-
integrations=[CeleryIntegration(monitor_beat_tasks=True)],
38+
profile_lifecycle="trace",
39+
profile_session_sample_rate=1.0,
40+
enable_logs=True,
41+
send_default_pii=True,
42+
debug=os.getenv("SENTRY_DEBUG", "false").lower() == "true",
43+
integrations=_integrations,
3144
)
3245

3346
from celery import Celery

0 commit comments

Comments
 (0)