diff --git a/.chloggen/db-context-propagation-via-sql-commenter.yaml b/.chloggen/db-context-propagation-via-sql-commenter.yaml new file mode 100644 index 0000000000..b8d2c71048 --- /dev/null +++ b/.chloggen/db-context-propagation-via-sql-commenter.yaml @@ -0,0 +1,22 @@ +# Use this changelog template to create an entry for release notes. +# +# If your change doesn't affect end users you should instead start +# your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the area of concern in the attributes-registry, (e.g. http, cloud, db) +component: db + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add context propagation via SQL commenter for databases + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +# The values here must be integers. +issues: [2162] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/docs/database/database-spans.md b/docs/database/database-spans.md index 31ec816ea5..98fac7d772 100644 --- a/docs/database/database-spans.md +++ b/docs/database/database-spans.md @@ -13,6 +13,8 @@ linkTitle: Spans - [Notes and well-known identifiers for `db.system.name`](#notes-and-well-known-identifiers-for-dbsystemname) - [Sanitization of `db.query.text`](#sanitization-of-dbquerytext) - [Generating a summary of the query](#generating-a-summary-of-the-query) +- [Context propagation](#context-propagation) + - [SQL commenter](#sql-commenter) - [Semantic conventions for specific database technologies](#semantic-conventions-for-specific-database-technologies) @@ -478,6 +480,37 @@ Semantic conventions for individual database systems or specialized instrumentat MAY specify a different `db.query.summary` format as long as produced summary remains relatively short and its cardinality remains low comparing to the `db.query.text`. +## Context propagation + +**Status**: [Development][DocumentStatus] + +### SQL commenter + +Instrumentations MAY propagate context using [SQL commenter](https://google.github.io/sqlcommenter/spec/) by injecting comments into SQL queries before execution. SQL commenter-based context propagation SHOULD NOT be enabled by default, but instrumentation MAY allow users to opt into it. + +The instrumentation implementation SHOULD **append** the comment to the end of the query. Semantic conventions for individual database systems MAY specify different format, which may include different position, encoding, or schema, depending on the specific database system's requirements or preferences. + +The instrumentation SHOULD allow users to pass a propagator to overwrite the global propagator. If no propagator is provided by the user, instrumentation SHOULD use the global propagator. + +**Examples:** + +- For a query `SELECT * FROM songs` with W3C TraceContext propagator: + + ```sql + SELECT * FROM songs /*traceparent='00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01',tracestate='congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7'*/ + ``` + + Note that adding high cardinality comments, like `traceparent` and `tracestate`, to queries can impact the performance for some database systems, such as: + + - Prepared statements in MySQL. See [this related issue](https://github.com/google/sqlcommenter/issues/284) for more details. + - Oracle and SQL Server for both prepared and non-prepared statements. + +- For a query `SELECT * FROM songs` with a custom propagator that injects `service.name` into carrier where `service.name` is `shoppingcart`: + + ```sql + SELECT * FROM songs /*service.name='shoppingcart'*/ + ``` + ## Semantic conventions for specific database technologies More specific Semantic Conventions are defined for the following database technologies: