Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jmeunier/dbmon 2759 take two #6093

Closed
wants to merge 2 commits into from
Closed

Conversation

jmeunier28
Copy link
Contributor

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 CallableStatements with the following syntax causes exceptions to be thrown when enabling APM-DBM link:

The customer’s code base makes a CallableStatement statementvariable = connection.prepareCall("{call some_function_namehere(?,?,?) }";) and whenever both of these are active, the Java application starts throwing syntax error at or near "{" over and over.

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:

  final String storedProcedureCall = "/*test commnet*/ {call foo(?, ?)}";
  CallableStatement callableStmt = con.prepareCall(storedProcedureCall);
  callableStmt.setInt(1,10);
  callableStmt.setInt(2,11);
  callableStmt.execute();
  callableStmt.close(); 

... 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 the Incorrect 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:

Screen Shot 2023-10-12 at 5 26 06 PM

Screen Shot 2023-10-12 at 5 26 15 PM

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:

  1. The entire stored proc text e.g.:
CREATE PROCEDURE foo
BEGIN
-- do stuff
END;
  1. The currently executing query in the context of the stored proc

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.

@jmeunier28 jmeunier28 requested a review from a team as a code owner October 24, 2023 16:32
@jmeunier28 jmeunier28 closed this Oct 24, 2023
@PerfectSlayer
Copy link
Contributor

Duplicate of #6034

@PerfectSlayer PerfectSlayer marked this as a duplicate of #6034 Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants