-
Notifications
You must be signed in to change notification settings - Fork 67
Isolate telemetry to garth's session using hooks instead of global instrumentation #181
Copy link
Copy link
Closed
Description
Problem
The current telemetry implementation has two issues:
- Global logfire configuration:
logfire.configure()sets up the global OpenTelemetry provider, potentially overwriting the user's existing configuration - Global request instrumentation:
logfire.instrument_requests()monkey-patches allrequests.Sessionusage application-wide, not just garth's
This means garth's telemetry conflicts with applications that have their own logfire/OpenTelemetry setup.
Proposed Solution
Use requests.Session hooks instead of global instrumentation:
- Attach a response hook directly to garth's session instance
- Send telemetry data to logfire cloud via HTTP API (not via OpenTelemetry SDK)
- Keep the same environment variables as defaults:
GARTH_TELEMETRY=true/falseLOGFIRE_TOKENGARTH_TELEMETRY_SERVICE_NAME
Benefits
- Isolation: Only garth's requests are logged, no global side effects
- No conflicts: Works alongside existing logfire/OpenTelemetry setups
- Same defaults: Logfire cloud remains the default destination with same env vars
- Customizable: Users can provide their own callback for custom destinations
API Design
# Default: sends to logfire cloud (same as today)
garth.configure(telemetry_enabled=True)
# Custom callback for alternative destinations
garth.configure(
telemetry_enabled=True,
telemetry_callback=lambda data: my_logger.info("garth", **data)
)Implementation Notes
- Remove
logfire.configure()andlogfire.instrument_requests()calls - Add
session.hooks['response'].append(...)inClient.__init__orconfigure() - Default callback sends sanitized data to logfire cloud via their HTTP ingest API
- Keep all existing sanitization logic
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels