explaingit

mstryoda/pgtrace

Analysis updated 2026-05-18

17RustAudience · developerComplexity · 4/5LicenseSetup · hard

TLDR

A Rust-based PostgreSQL extension that traces individual SQL queries and connects them to your application's existing OpenTelemetry traces.

Mindmap

mindmap
  root((pgtrace))
    What it does
      Traces SQL queries
      Links to app traces
    Tech stack
      Rust
      PostgreSQL
      OpenTelemetry
    Use cases
      Diagnose slow queries
      End-to-end tracing
      Adjustable sampling
    Audience
      Developers
      Database operators

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

See how long PostgreSQL spends planning and executing a query as part of a full end-to-end request trace.

USE CASE 2

Diagnose slow database queries by connecting them to the application traces already flowing through Jaeger or Tempo.

USE CASE 3

Sample only a fraction of production queries to keep tracing overhead low.

What is it built with?

RustPostgreSQLOpenTelemetryDockerGo

How does it compare?

mstryoda/pgtraceatelico/gdstyleathxrvx/spear
Stars171717
LanguageRustRustRust
Setup difficultyhardeasymoderate
Complexity4/52/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · hard Time to first run · 1h+

Requires building a Rust extension against Postgres dev headers, or using the Docker demo whose first build takes 5 to 15 minutes.

In plain English

pgtrace, published as pg_otel_tracer, is a PostgreSQL extension written in Rust that plugs into the database's internal query hooks so every SQL statement can be tracked as part of a larger distributed trace. OpenTelemetry, or OTEL, is an open standard for recording and passing traces across service boundaries. pgtrace bridges the gap between your application's existing trace and what happens inside PostgreSQL itself. Here is how it works: your application embeds a W3C traceparent identifier inside a SQL comment when it sends a query to PostgreSQL. The extension reads that identifier and creates timed spans covering each phase of the query's life, including the planning phase, the execution start, and the data retrieval phase. These spans are collected in a shared memory ring buffer and exported asynchronously by a background worker process every 500 milliseconds via OTLP over HTTP. You can then view the full end to end trace in tools like Jaeger or Tempo, seeing how long PostgreSQL spent on each query alongside your application's other service calls. The extension is designed to be safe for production. It drops spans rather than blocking the database if the export queue fills up, supports an adjustable sampling rate so you can trace a fraction of queries rather than all of them, and provides a live switch SQL function to disable tracing without a database restart. A status function reports the current version, whether tracing is enabled, the sampling rate, and how many spans are queued or dropped. Installation requires preloading the extension via postgresql.conf and running a single CREATE EXTENSION command, or you can try it quickly with the included Docker setup that starts Postgres, an OTEL Collector, Jaeger, and a Go demo application together. The project is licensed under Apache-2.0.

Copy-paste prompts

Prompt 1
Help me install this Postgres extension and preload it in postgresql.conf.
Prompt 2
Show me how to inject a traceparent into my app's SQL queries so pgtrace can pick it up.
Prompt 3
Explain how to adjust the sampling rate in production without restarting the database.
Prompt 4
Walk me through the included Docker demo so I can see traces in Jaeger.

Frequently asked questions

What is pgtrace?

A Rust-based PostgreSQL extension that traces individual SQL queries and connects them to your application's existing OpenTelemetry traces.

What language is pgtrace written in?

Mainly Rust. The stack also includes Rust, PostgreSQL, OpenTelemetry.

How hard is pgtrace to set up?

Setup difficulty is rated hard, with roughly 1h+ to a first successful run.

Who is pgtrace for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.