Documentation forSolarWinds Observability

Trace context in queries

Many services and applications rely on databases to store and retrieve data. When an APM library's trace encounters database queries, it will collect basic information about the database and the query. For a deeper analysis of the database and queries the service encountered, you can monitor the database with SolarWinds Observability and configure the APM library to connect the trace with the database it encounters.

When a request enters an instrumented application, the APM libraries create a unique trace context and maintain that context through the lifetime of the transaction. The trace context is included when the library reports performance metrics, the transaction trace (if sampled), to your application logs (if enabled), and in your database queries (if enabled). Adding trace context to queries provides the ability to correlate a database entity with a service entity based on a traced transaction, and, if sampled, the database entity to the query detected in the transaction trace detail.

The Queries tab of the Span Details pane in the Traces Explorer lists the query or queries encountered during a trace. If trace context is added to the query of a monitored database entity, click View Query Details to view database monitoring information collected for that query.

Trace context

The trace context is inserted as a comment at the beginning of the detected SQL statement. The trace context takes the form of /*traceparent='00-<TraceID>-<SpanID>-<Trace Flags>'*/. An example trace context inserted in the SQL statement is: /*traceparent='00-abcdef1234567890abcdef1234567890-1234abcd1234abcd-01'*/.

Trace ID

The Trace ID is a hex string that represents the associated transaction trace. This Trace ID can also be seen in the Transaction Details page of the Traces Explorer. An example Trace ID is: abcdef1234567890abcdef1234567890.

Span ID

The Span ID is a hex string representing the associated span. This Span ID can be seen in the Span panel of the Transaction Details page in the Traces Explorer. An example Span ID is: 1234abcd1234abcd.

Trace Flags

The Trace Flags indicates whether the trace was sampled; 01 means there was a corresponding sampled trace and 00 means no trace was sampled.


Trace context in queries is currently compatible with monitored MySQL database instances. Limited support for additional database types varies by instrumentation library.

For .NET instrumented services, trace context in queries is only supported for the MySql.Data.MySqlClient and MySqlConnector data providers under ADO.NET.

Trace context will not be inserted into a prepared statements query if the APM library cannot guarantee the correct trace context was inserted. If multiple statements are sent in a single call to the database server for an off-host database entity, the trace context will only be inserted at the beginning of the first statement.

Enable trace context in queries

Trace context in queries is disabled by default. See the links below on how to enable this feature in each library: