Network & Cloud Sinks
Logger reference

Sentry Sink

SentryLogger sends log messages to Sentry using the official sentry-sdk.

1. Behavior and Context

The sink initializes global Sentry SDK state via sentry_sdk.init(...), then forwards log entries as Sentry messages with level mapping and extra fields.

Behavior highlights:

  • dependency imported lazily in initialize()
  • scope-based enrichment using push_scope()
  • level translation from logger levels to Sentry levels
  • shared handling for all levels through capture_message

2. Purpose

  • Error Tracking Integration: Push application logs into Sentry event pipeline.
  • Context Enrichment: Include structured extras for debugging.
  • Simple Setup: Minimal DSN + environment config.

3. High-Level API & Examples

Example 1: Basic Setup

python
from jazzmine.logging.sinks.sentry_sink import SentryLogger

sink = SentryLogger(
    sink_config={
        "type": "sentry",
        "dsn": "https://<public>@o0.ingest.sentry.io/0",
        "environment": "production",
        "traces_sample_rate": 0.1,
    },
    logger_name="payments",
    level="INFO",
    use_json=True,
)
sink.initialize()
sink.error("payment capture failed", order_id="o-77", amount=42.5)
sink.shutdown()

Example 2: Async Invocation

python
import asyncio

async def send_async(sink):
    await sink.alog("warning", "retry threshold reached", retries=3)

# alog delegates to sync log() in this implementation.

4. Detailed Class Functionality

initialize()

  • Imports sentry_sdk.
  • Raises LoggerDependencyError if missing.
  • Reads config fields: dsn, environment, traces_sample_rate.
  • Calls sentry_sdk.init(...) and marks sink initialized.

log(level, msg, **kwargs)

  • Maps level to Sentry-compatible value (critical -> fatal).
  • Opens temporary scope with push_scope().
  • Sets scope level and attaches all kwargs with set_extra.
  • Captures message with capture_message.

shutdown()

Flushes pending Sentry events via self.sentry.flush().

alog(...)

Delegates directly to log(...).

5. Error Handling

  • LoggerDependencyError if sentry-sdk is not installed.
  • Runtime send failures are not re-raised by this sink.

6. Remarks

  • Because Sentry SDK initialization is global, coordinate configuration when multiple Sentry integrations coexist in the same process.
  • Set traces_sample_rate thoughtfully to avoid high event volume in large deployments.