Describe the feature you'd like
Provide an opt-in way to append DBM SQL propagation comments instead of prepending them.
For example, something similar to:
DD_DBM_PROPAGATION_COMMENT_POSITION=append
Current behavior:
/*dddb='my-service'*/ SELECT * FROM users WHERE id = 1
Proposed behavior:
SELECT * FROM users WHERE id = 1 /*dddb='my-service'*/
The default behavior could remain unchanged (prepend) to preserve backwards compatibility.
Is your feature request related to a problem?
Yes.
Some database middleware and proxies use SQL comments as query annotations and require those annotations to remain in the first comment position of the query.
For example:
SELECT /*+ ;min_gtid=<gtid> */ * FROM users WHERE id = 1
When DBM propagation prepends its comment, the query becomes:
/*dddb='my-service'*/ SELECT /*+ ;min_gtid=<gtid> */ * FROM users WHERE id = 1
In this scenario, the middleware may no longer recognize the annotation because it is no longer the first comment encountered in the query.
An append mode would allow DBM propagation to coexist with systems that rely on specific SQL comment placement.
Describe alternatives you've considered
I have considered:
- Disabling DBM propagation entirely for affected services.
- Maintaining a local fork of
dd-trace-php that appends comments instead of prepending them.
- Modifying the database middleware to avoid comment-based annotations.
All of these approaches have drawbacks. An opt-in append mode in the tracer would provide a cleaner solution while preserving existing behavior for current users.
Additional context
There is prior art for this feature in other Datadog tracers.
Node.js already supports appending SQL comments through the appendComment option:
https://datadoghq.dev/dd-trace-js/interfaces/plugins.pg.html
Ruby also had a discussion around append-vs-prepend comment placement due to compatibility issues with other tooling:
DataDog/dd-trace-rb#3601
Because similar functionality already exists elsewhere in the Datadog ecosystem, I wanted to check whether a similar opt-in capability would be considered for dd-trace-php.
If this is something the maintainers would be open to, I would be happy to investigate and contribute an implementation.
Describe the feature you'd like
Provide an opt-in way to append DBM SQL propagation comments instead of prepending them.
For example, something similar to:
Current behavior:
Proposed behavior:
The default behavior could remain unchanged (prepend) to preserve backwards compatibility.
Is your feature request related to a problem?
Yes.
Some database middleware and proxies use SQL comments as query annotations and require those annotations to remain in the first comment position of the query.
For example:
When DBM propagation prepends its comment, the query becomes:
In this scenario, the middleware may no longer recognize the annotation because it is no longer the first comment encountered in the query.
An append mode would allow DBM propagation to coexist with systems that rely on specific SQL comment placement.
Describe alternatives you've considered
I have considered:
dd-trace-phpthat appends comments instead of prepending them.All of these approaches have drawbacks. An opt-in append mode in the tracer would provide a cleaner solution while preserving existing behavior for current users.
Additional context
There is prior art for this feature in other Datadog tracers.
Node.js already supports appending SQL comments through the
appendCommentoption:https://datadoghq.dev/dd-trace-js/interfaces/plugins.pg.html
Ruby also had a discussion around append-vs-prepend comment placement due to compatibility issues with other tooling:
DataDog/dd-trace-rb#3601
Because similar functionality already exists elsewhere in the Datadog ecosystem, I wanted to check whether a similar opt-in capability would be considered for
dd-trace-php.If this is something the maintainers would be open to, I would be happy to investigate and contribute an implementation.