Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

incident.io 6 min read How-to mediumAdept

Tracing Gorm queries with OpenCensus & Google Cloud Tracing

Gorm's Callbacks API can wrap every Postgres query in an OpenCensus span that feeds Google Cloud Tracing: a before-callback starts the span only when a parent span exists, and an after-callback ends it. The after-callback sets the span status, mapping ErrRecordNotFound to NotFound. Spans are enriched with the table name, a pg_query_go query fingerprint in the span name, the calling source line found by walking runtime.Caller past gorm frames, rows affected, the SQL string and bound vars. Query vars can contain sensitive data, so record them only for SELECT queries or sanitise them first.

Related posts

  • Observability as a superpower

    incident.io mediumAdept

    Distributed tracing with OpenTelemetry lets incident.io engineers spot bugs before customers report them, by showing each request's route as a tree of timed spans that exposes slow steps, N+1 queries and duplicate calls. The team gets spans for free from instrumented database and HTTP clients, follows a consistent span naming convention, and tags spans with metadata such as table names, row counts, query fingerprints and org IDs. In Go, an internal library plus a defer-with-named-return pattern records errors on spans automatically. Traces go to Cloud Trace locally and to Grafana Tempo in production, where TraceQL queries power debugging. Trace URLs are threaded into logs, Sentry errors and response headers, with a caution that span and attribute volume drives storage cost.

  • Zero-config Debugging with Deno and OpenTelemetry

    Deno mediumAdept

    Deno's built-in OpenTelemetry support (enabled with --unstable-otel) automatically correlates console.log output with trace IDs, creates spans for incoming and outgoing HTTP requests, propagates W3C tracecontext headers across services, and records request-count and latency metrics by status code, all without code changes. The walkthrough shows why interleaved logs need request correlation and how spans and parent span IDs build a trace. It provides a withSpan helper around startActiveSpan for adding custom spans such as database calls, and contrasts automatic propagation with manually injecting traceparent headers.

  • How we used ClickHouse to store OpenTelemetry Traces and up our Observability Game

    ClickHouse mediumAdept

    Resmo stores over 300 million unsampled OpenTelemetry spans per day in a self-hosted ClickHouse node, after dropping S3/Parquet/Athena because of its 2-3 second query startup and delayed data. A single c7g.xlarge with 400 GB EBS holds more than 4 billion spans at about 92% compression (275 GiB vs 3.4 TiB). LowCardinality materialized columns for tenant and user IDs speed up common queries, and joins to Aurora Postgres add account names. The post shares SQL for latency percentiles, SpanAttributes key analysis, spans-per-trace histograms and exception-message search with hasToken.

  • Building an Observability Solution with ClickHouse - Part 2 - Traces

    ClickHouse mediumAdept

    Trace data from OpenTelemetry-instrumented services can be stored and queried in ClickHouse, treating spans as rows in a single analytics table and visualizing them in Grafana. The walkthrough uses a ClickHouse fork of the OpenTelemetry Demo, configuring the OTEL Collector's contrib ClickHouse exporter with batching (5s or 100k spans), retries, TTL-based retention and secure endpoints, deployable via Docker Compose or Helm. Practical caveats include the exporter's hard-coded schema (pre-create tables to control types and codecs), its alpha status, and the need to pre-create non-default databases, followed by tips on schema optimization for the otel_traces table.

  • Logs and tracing: not just for production, local development too

    incident.io mediumAdept

    A small team wired its Go app to Google Cloud Trace via the OpenCensus Stackdriver exporter, then teed zap logs to both STDERR and Cloud Logging with trace and span IDs attached, so logs appear inline with traces. The same setup runs in local development: every log line carries a clickable Cloud Trace URL, letting developers jump from one interleaved log line to the full trace of a concurrent request or Pub/Sub handler. The payoff is faster local debugging plus fluency with the production tooling, for a small investment that avoids running any tracing infrastructure.

The quest for software engineering knowledge.

Look:
Layout: