# Trace linkage: connect the dots between your app traces and database queries

DevFeed: [Trace linkage: connect the dots between your app traces and database queries](<https://devfeed.tech/articles/trace-linkage-connect-the-dots-between-your-app-traces-and-database-queries-116281.md>)

Original publisher: [Read original article](<https://grafana.com/blog/trace-linkage-connect-the-dots-between-your-app-traces-and-database-queries/>)

Author: Shirley

Published: 2026-11-03T15:05:03Z

Content type: release

Language: en

Sources: [Grafana Labs](<https://devfeed.tech/sources/grafana-labs-blog-on-grafana-labs.md>)

Topics: [observability](<https://devfeed.tech/topics/observability.md>), [OpenTelemetry](<https://devfeed.tech/topics/opentelemetry.md>), [telemetry](<https://devfeed.tech/topics/telemetry.md>), [Grafana Alloy](<https://devfeed.tech/topics/grafana-alloy.md>), [Grafana Cloud](<https://devfeed.tech/topics/grafana-cloud.md>)

Tags: [alloy](<https://devfeed.tech/tags/alloy.md>), [analytics](<https://devfeed.tech/tags/analytics.md>), [application](<https://devfeed.tech/tags/application.md>), [database](<https://devfeed.tech/tags/database.md>), [database-observability](<https://devfeed.tech/tags/database-observability.md>), [execution](<https://devfeed.tech/tags/execution.md>), [explain](<https://devfeed.tech/tags/explain.md>), [grafana](<https://devfeed.tech/tags/grafana.md>), [grafana-cloud](<https://devfeed.tech/tags/grafana-cloud.md>), [history](<https://devfeed.tech/tags/history.md>), [logs](<https://devfeed.tech/tags/logs.md>), [metrics](<https://devfeed.tech/tags/metrics.md>), [monitoring](<https://devfeed.tech/tags/monitoring.md>), [observability](<https://devfeed.tech/tags/observability.md>), [opentelemetry](<https://devfeed.tech/tags/opentelemetry.md>), [performance](<https://devfeed.tech/tags/performance.md>), [plan](<https://devfeed.tech/tags/plan.md>), [queries](<https://devfeed.tech/tags/queries.md>), [telemetry](<https://devfeed.tech/tags/telemetry.md>), [tempo](<https://devfeed.tech/tags/tempo.md>), [text](<https://devfeed.tech/tags/text.md>), [trace](<https://devfeed.tech/tags/trace.md>), [traces](<https://devfeed.tech/tags/traces.md>), [tracing](<https://devfeed.tech/tags/tracing.md>)

## AI overview

Grafana Cloud Database Observability's trace linkage connects OpenTelemetry database spans to query context collected by Alloy. It uses query text, database system, and database name; spans with `db.query.text` or legacy `db.statement` may match without further application instrumentation. For more precise execution-level matches, optional sqlcommenter propagation places trace and span IDs in SQL comments, which Alloy extracts from query sample logs. Exact matches are best-effort: Alloy may miss short-lived executions or fail to poll them, sqlcommenter does not support every database engine and may affect database caches. When exact matching is unavailable, trace linkage accounts for differences in query formatting, comments, literals, and parameter placeholders to find matching query text, allowing users to inspect samples, historical performance, schema, and explain plans. Setup requires an OpenTelemetry-instrumented application sending traces to Grafana Cloud and Database Observability configured.

## Source excerpt

When an application request slows down, a trace can show a database call. Finding the database query behind it can be tedious, requiring you to switch between traces and database telemetry, as well as match timestamps or query text by hand. In Grafana Cloud, the Database Observability app already provides a window into all of your database telemetry, including query samples, performance history, and explain plan. But what if you could jump from that database call in the trace straight to its query details? OpenTelemetry database semantic conventions stabilized last year, giving us all a dependable shared language for describing database operations. That foundation has opened the door for what we call trace linkage, now Generally Available in Database Observability! What is trace linkage? With trace linkage, we try to provide a connection between OpenTelemetry-instrumented applications and database telemetry collected with Alloy. In other words, when you give us these previously-disjoint puzzle pieces, we'll do our best to provide you as much supporting information between these two elements as we can. And we'll do it without making you tediously piece together timestamps and logs. From a database span in a trace, you'll see a link on the query text. Clicking from there, the app searches for a connection between your database query and our opinionated view of your most relevant data in the Database Observability app. You can explore sampled query execution data or check out the query's historical performance, alongside that query's related schema and explain plan. This connection builds on the database attributes your OpenTelemetry instrumentation already emits. Grafana Cloud Traces, powered by Tempo, retain those attributes, and trace linkage uses the query text, database system, and database name to connect a database span to its supporting query context in Database Observability. We support the stable conventions like db.query.text and its legacy equivalent db.sta