Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What Does This Do
This PR updates the logic for the APM-DBM link feature introduced in #4847. It changes from prepending the sql comments, containing the APM trace context, to appending them to the raw sql. This requires no changes on the DBM side of things in either the agent or our backend.
Jira ticket: DBMON-2759
Motivation
This fixes an issue, which has been reported by several customers that executing
CallableStatement
s with the following syntax causes exceptions to be thrown when enabling APM-DBM link:We were able to reproduce this, using the latest version of the java tracer && an internal application. It seems to be caused by the SQL comments we inject being prepended instead of appended. For example, the issue of prepending the comment was reproduced with a simple java application (without APM-DBM link enabled), which did the following:
... this throws the same exception with message
Incorrect syntax near '{'.
Proof of Fix
After doing a custom build of this tracer code, we deployed our test app, which runs a combination of
PreparedStatement
/Statements
/CallableStatement
& no longer saw theIncorrect syntax near '{'.
exception being thrown.We were also able to confirm that injection is still working properly, e.g: our events are being properly decorated:
Expected DBM Behavior for Stored Procedures
Stored Procedures aren't supported for the APM-DBM usecase (unless the same app that is calling them is the thing that created the stored procedure & the linking was enabled). Otherwise, we wouldn't see the comments if someone had code that was simply calling
EXEC proc
or{call proc}
, since the actual text we see in the activity code is either:Neither, contains the text
EXEC proc
, which is what would have the comment injected via the tracer.Obviously, this is of secondary concern here. Updating the tracer to append the comment will fix this edge case being reported by customers. We really don't want the feature to cause users to see exceptions being thrown in their production code.