Area(s)
area:db
What's missing?
docs/db/mongodb.md currently defines Spans and Metrics but has no
Context propagation section, unlike the other databases that gained one under
#2162 and the framework in #2495:
As a result there is no standard, cross-language way for a client to propagate
W3C trace context to the server, so application spans and server-side spans
appear as two disconnected traces. In #2162, @XSAM noted follow-up issues may be
opened for specific databases; this is the MongoDB follow-up.
Because the instrumentation lives in the MongoDB drivers, this convention
would apply not only to MongoDB itself but to any database accessed through the
MongoDB drivers / MongoDB wire protocol (for example, DocumentDB and other
MongoDB-compatible engines). A single carrier convention therefore benefits the
whole MongoDB-driver ecosystem rather than one implementation.
Describe the solution you'd like
Add a Context propagation section to docs/db/mongodb.md that standardizes
carrying W3C trace context in the MongoDB comment command field, mirroring
the existing per-database sections.
Proposed shape (opt-in, not enabled by default, consistent with SQL Server /
Oracle / PostgreSQL / MySQL):
- Carrier: the top-level
comment command field, set to a JSON/BSON object.
- Detection: the
comment is treated as trace context iff it is an
object containing a top-level traceparent; a plain-string comment or an
object without traceparent is left untouched.
- Fields:
traceparent (required, W3C, version 00), tracestate
(optional, carried opaquely), and an optional slot for the user's own comment
so it remains recoverable.
- Failure handling: any malformed/absent/unsupported value is ignored and a
fresh trace is started; propagation never breaks the operation.
Why the comment field (and how it differs from SQL-comment propagation)
Concerns raised in open-telemetry/opentelemetry-specification#2279 and
google/sqlcommenter#284 were about embedding context in SQL statement text:
mutating the statement string changes its identity. The MongoDB comment field
differs in two ways that matter at the wire-protocol layer:
- The context travels in a dedicated, structured field of the command,
separate from the operation and query, rather than being appended to
statement text, so the convention does not require mutating any
query/operation text. We propose the convention specify only this
wire-protocol carrier and leave how a server propagates the context further to
the implementation, consistent with how the existing per-database sections
document a carrier without dictating downstream handling.
- The
comment field is bounded by maxBsonObjectSize rather than a small
fixed byte limit, so unlike CONTEXT_INFO (128 B) / V$SESSION.ACTION
(64 B) it can carry tracestate in addition to traceparent.
Prior art / consistency
Additional context
Because context injection would happen in the MongoDB driver / instrumentation
layer, MongoDB and MongoDB-compatible databases (e.g. DocumentDB) would all
benefit from the same convention without per-engine work.
We would like to bring this to a Semantic Conventions DB SIG meeting to align on
the field shape (flat W3C keys vs. a reserved namespace) and status. We are
willing to write the specification PR.
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Area(s)
area:db
What's missing?
docs/db/mongodb.mdcurrently defines Spans and Metrics but has noContext propagation section, unlike the other databases that gained one under
#2162 and the framework in #2495:
SET CONTEXT_INFOV$SESSION.ACTIONSET application_name([db] Add context propagation for PostgreSQL via SET application_name #3581)SET @traceparent([db] Add context propagation for MySQL via SET @traceparent #3768)As a result there is no standard, cross-language way for a client to propagate
W3C trace context to the server, so application spans and server-side spans
appear as two disconnected traces. In #2162, @XSAM noted follow-up issues may be
opened for specific databases; this is the MongoDB follow-up.
Because the instrumentation lives in the MongoDB drivers, this convention
would apply not only to MongoDB itself but to any database accessed through the
MongoDB drivers / MongoDB wire protocol (for example, DocumentDB and other
MongoDB-compatible engines). A single carrier convention therefore benefits the
whole MongoDB-driver ecosystem rather than one implementation.
Describe the solution you'd like
Add a Context propagation section to
docs/db/mongodb.mdthat standardizescarrying W3C trace context in the MongoDB
commentcommand field, mirroringthe existing per-database sections.
Proposed shape (opt-in, not enabled by default, consistent with SQL Server /
Oracle / PostgreSQL / MySQL):
commentcommand field, set to a JSON/BSON object.commentis treated as trace context iff it is anobject containing a top-level
traceparent; a plain-string comment or anobject without
traceparentis left untouched.traceparent(required, W3C, version00),tracestate(optional, carried opaquely), and an optional slot for the user's own comment
so it remains recoverable.
fresh trace is started; propagation never breaks the operation.
Why the
commentfield (and how it differs from SQL-comment propagation)Concerns raised in open-telemetry/opentelemetry-specification#2279 and
google/sqlcommenter#284 were about embedding context in SQL statement text:
mutating the statement string changes its identity. The MongoDB
commentfielddiffers in two ways that matter at the wire-protocol layer:
separate from the operation and query, rather than being appended to
statement text, so the convention does not require mutating any
query/operation text. We propose the convention specify only this
wire-protocol carrier and leave how a server propagates the context further to
the implementation, consistent with how the existing per-database sections
document a carrier without dictating downstream handling.
commentfield is bounded bymaxBsonObjectSizerather than a smallfixed byte limit, so unlike
CONTEXT_INFO(128 B) /V$SESSION.ACTION(64 B) it can carry
tracestatein addition totraceparent.Prior art / consistency
already exists in a MongoDB-compatible gateway (DocumentDB); it extracts a
traceparent(and carriestracestateopaquely) from thecommentfield andre-parents the server's root span. We can contribute conformance test vectors.
Additional context
Because context injection would happen in the MongoDB driver / instrumentation
layer, MongoDB and MongoDB-compatible databases (e.g. DocumentDB) would all
benefit from the same convention without per-engine work.
We would like to bring this to a Semantic Conventions DB SIG meeting to align on
the field shape (flat W3C keys vs. a reserved namespace) and status. We are
willing to write the specification PR.
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding
+1orme too, to help us triage it. Learn more here.