October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How OpenTelemetry Connects Application Requests to Database Calls

OpenTelemetry can connect a request to a database client span through propagated trace context, but server-side visibility requires additional database-specific support in many setups.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

OpenTelemetry can show a database call as part of an application request when the application and database-client instrumentation create spans with the same propagated trace context. That client span represents the application’s logical database operation—not necessarily work observed inside the database server. Server-side visibility and client/server correlation may require database-specific support and configuration.

How a database call becomes part of a trace

A trace is a set of correlated spans describing work across an operation. A span records a unit of work, including its name, parent span ID, timestamps, context, attributes, events, links, and status. If an instrumented service creates a server span when a request arrives, framework and library instrumentation can add child spans as the request proceeds. At the database-client boundary, instrumentation can add a CLIENT span for the logical database operation.

As an Amazon Associate I earn from qualifying purchases.

Context propagation carries trace identity across supported boundaries so spans created in different places can be correlated. When the database client uses the active context correctly, its span can appear beneath the application operation in the trace. See the OpenTelemetry traces documentation and Trace API specification.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Instrument the logical database operation

Database-client instrumentation should generally create a span for the logical database request. The lower-level physical network requests belong in the libraries that implement those requests. Instrumenting the same activity at multiple abstraction layers can make a trace appear to contain duplicate work. OpenTelemetry’s library instrumentation guidance describes this boundary; the database client spans conventions recommend CLIENT span kind for calls to databases typically running in another process or accessed over an instrumented protocol.

Choose a span boundary that matches what the instrumentation can know. A generic query layer may know that it executed a statement, while a higher-level stored-procedure API may know the operation’s purpose. In the latter case, instrumenting the higher-level operation may provide more useful context. Use meaningful span names and avoid names that vary with every query value, which would create unnecessary cardinality.

Check the emitted database convention version

Database semantic conventions evolve, and the convention set emitted by an instrumentation library depends on its version and migration behavior. The OpenTelemetry database conventions page currently describes their overall stability as “Mixed”: it covers database client spans, metrics, and exceptions, but individual conventions can have different stability statuses.

The conventions document says existing instrumentations using v1.24.0 or earlier are advised not to change convention output silently by default within their current major version. It documents OTEL_SEMCONV_STABILITY_OPT_IN=database for emitting stable database conventions instead of prior experimental conventions, and database/dup for emitting both during a phased migration. A library’s default may remain its previous experimental convention set. These options should not be assumed to work identically across all instrumentation packages: check the exact library version and its migration documentation alongside the database semantic conventions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Protect query data and control cardinality

Query text can expose sensitive values and can create high-cardinality, lengthy span attributes. The database conventions say db.query.text should be collected by default only when sanitization excludes sensitive information. Sanitization should replace literal values with placeholders. Parameterized query text is not subject to that sanitization rule, but you should still assess your own data sensitivity and instrumentation configuration.

Where available, prefer a short db.query.summary that is low-cardinality and contains no dynamic or sensitive data. Do not use raw query text as a metric label. The database client spans specification provides the relevant attributes and guidance.

Understand what client spans do—and do not—show

An exported client span shows the application’s database call. It does not, by itself, prove that the database server is instrumented or that the server’s internal work is visible in the same trace. W3C TraceContext is a common way to propagate context between instrumented application components, but making that context visible to a database server’s logs or tracing may require a driver-specific bridge or another database-specific mechanism.

SQL commenter is one optional mechanism: context is appended to SQL comments so database-side logs or instrumentation can associate a statement with a trace. The OpenTelemetry specification states, “SQL commenter-based context propagation SHOULD NOT be enabled by default, but instrumentation MAY allow users to opt into it.” It is not a prerequisite for ordinary client tracing, and high-cardinality comments can affect performance on some database systems. Enable it only when the particular integration and database support it and the operational trade-offs are understood.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Oracle illustrates why database-specific checks matter

The Oracle semantic convention documents driver mechanisms for carrying trace context to Oracle, but end-to-end tracing requires compatible driver and server support, and server-side tracing must be explicitly configured. Oracle context can persist as session state; instrumentation may need to clear or scope it so a pooled session does not pass stale context to later statements. Driver and language APIs vary, so verify the exact server and driver versions rather than treating Oracle’s approach as a universal recipe. See the Oracle semantic conventions.

SQL commenter in Python DB-API is an integration-specific option

The Python DB-API instrumentation documentation describes SQL commenter as optional. When enabled, configured key-value context is appended to queries; the documentation describes support for client/server propagation when database log records are enabled. This behavior is specific to that integration and does not establish that other database libraries support the same mechanism. See the Python DB-API instrumentation documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose instrumentation before choosing a trace destination

Exporters can send trace data to standard output for development, to an OpenTelemetry Collector, or to an open-source or vendor backend. A Collector or backend receives, processes, or presents telemetry; neither replaces the application framework and database-driver instrumentation that generates spans and propagates context.

  • Confirm the language and database driver have suitable instrumentation.
  • Decide whether automatic instrumentation covers the logical database operation or whether manual instrumentation is needed.
  • Check the emitted span kind, attributes, and semantic-convention version.
  • Set query-text capture and sanitization deliberately, and keep summaries low-cardinality.
  • Determine whether server-side correlation is needed and whether the specific database and driver support it.
  • Choose an exporter and collection path that fits how traces will be queried and operated.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.