Distributed Tracing¶
PGQueuer supports distributed tracing through optional integrations with Logfire and Sentry. These tools allow you to visualize job execution and measure performance across producer and consumer boundaries.
Installing Optional Dependencies¶
You can install both extras simultaneously if you need to switch between them.
Using Logfire¶
Configure Logfire before running your producers and consumers, then register the tracer with PGQueuer:
import logfire
from pgqueuer import tracing
logfire.configure()
tracing.set_tracing_class(tracing.LogfireTracing())
With this setup, trace context is added to job headers when you enqueue messages. Consumers automatically attach these headers to each span so that Logfire can correlate producer and consumer activity.
Refer to Logfire's manual tracing guide for more details about configuring spans and logging.
Using Sentry¶
Initialise the Sentry SDK with your DSN, then set the tracer class:
import sentry_sdk
from pgqueuer import tracing
sentry_sdk.init(
dsn="https://<key>@o1.ingest.sentry.io/<project>",
traces_sample_rate=1.0,
)
tracing.set_tracing_class(tracing.SentryTracing())
Job headers will include Sentry tracing information so that consumer spans are linked to the producing transaction. See the Sentry Python documentation for advanced configuration options.
Switching Tracers¶
Only one tracer can be active at a time. Call tracing.set_tracing_class() with the
desired tracer implementation before starting producers or consumers.