Skip to content

Prepend SQL query correlation metadata as a SQL comment #2590

@jtduffy

Description

@jtduffy

Description

Enhance APM SQL driver instrumentation to prepend correlation metadata as SQL comments to all database queries. This enables bidirectional correlation between APM traces and QPM performance metrics without cardinality impact.

Jira ticket

Requirements

Metadata comment

Prepend a comment to the SQL statement string that contains the following:

  • the transaction id
  • the span id
  • the service name (app name)

For example:
/* nr_trace_id=7f8a9b2c1d3e4f5a,nr_span_id=abc123def456,nr_service=user-api */ SELECT id, name FROM users where user_id = 1;

Configuration

A new config section needs to be added to the transaction_tracer stanza to configure the new functionality.

  transaction_tracer:
    sql_metadata_comments:
      enabled: false
      excludes:
  • enabled - true to enable SQL metadata comment generation, Default is false
  • excludes - comma separated list of regular expressions; if a SQL statement matches one of these regular expressions no comment is prepended

Design Consideration/Limitations

  • excludes config option can be a stretch goal after basic functionality is implemented
  • Support for all SQL products supported by the agent (Postgres, MySQL, Oracle, SqlServer...)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In Sprint

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions