Skip to content

Commit 224f107

Browse files
XSAMsincejunepellaredzacharycmontoyalmolkova
authored
Add SQL commenter as context propagation for databases (#2495)
Co-authored-by: Chao Weng <[email protected]> Co-authored-by: Robert Pająk <[email protected]> Co-authored-by: Zach Montoya <[email protected]> Co-authored-by: Liudmila Molkova <[email protected]>
1 parent 132c7cd commit 224f107

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Use this changelog template to create an entry for release notes.
2+
#
3+
# If your change doesn't affect end users you should instead start
4+
# your pull request title with [chore] or use the "Skip Changelog" label.
5+
6+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
7+
change_type: enhancement
8+
9+
# The name of the area of concern in the attributes-registry, (e.g. http, cloud, db)
10+
component: db
11+
12+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
13+
note: Add context propagation via SQL commenter for databases
14+
15+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
16+
# The values here must be integers.
17+
issues: [2162]
18+
19+
# (Optional) One or more lines of additional information to render under the primary note.
20+
# These lines will be padded with 2 spaces and then inserted directly into the document.
21+
# Use pipe (|) for multiline entries.
22+
subtext:

docs/database/database-spans.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ linkTitle: Spans
1313
- [Notes and well-known identifiers for `db.system.name`](#notes-and-well-known-identifiers-for-dbsystemname)
1414
- [Sanitization of `db.query.text`](#sanitization-of-dbquerytext)
1515
- [Generating a summary of the query](#generating-a-summary-of-the-query)
16+
- [Context propagation](#context-propagation)
17+
- [SQL commenter](#sql-commenter)
1618
- [Semantic conventions for specific database technologies](#semantic-conventions-for-specific-database-technologies)
1719

1820
<!-- tocstop -->
@@ -478,6 +480,37 @@ Semantic conventions for individual database systems or specialized instrumentat
478480
MAY specify a different `db.query.summary` format as long as produced summary remains
479481
relatively short and its cardinality remains low comparing to the `db.query.text`.
480482
483+
## Context propagation
484+
485+
**Status**: [Development][DocumentStatus]
486+
487+
### SQL commenter
488+
489+
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.
490+
491+
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.
492+
493+
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.
494+
495+
**Examples:**
496+
497+
- For a query `SELECT * FROM songs` with W3C TraceContext propagator:
498+
499+
```sql
500+
SELECT * FROM songs /*traceparent='00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01',tracestate='congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7'*/
501+
```
502+
503+
Note that adding high cardinality comments, like `traceparent` and `tracestate`, to queries can impact the performance for some database systems, such as:
504+
505+
- Prepared statements in MySQL. See [this related issue](https://github.com/google/sqlcommenter/issues/284) for more details.
506+
- Oracle and SQL Server for both prepared and non-prepared statements.
507+
508+
- For a query `SELECT * FROM songs` with a custom propagator that injects `service.name` into carrier where `service.name` is `shoppingcart`:
509+
510+
```sql
511+
SELECT * FROM songs /*service.name='shoppingcart'*/
512+
```
513+
481514
## Semantic conventions for specific database technologies
482515

483516
More specific Semantic Conventions are defined for the following database technologies:

0 commit comments

Comments
 (0)