Skip to content

Conversation

@aryamohanan
Copy link
Contributor

Which problem is this PR solving?

Fixes #3193

When using prepared statements with the following syntax, query parameter values were not captured even when enhancedDatabaseReporting: true was enabled:

client.query(
  { name: 'statement_name', text: 'SELECT * FROM pg_tables WHERE schemaname = $1' },
  ['public']
);

Short description of the changes

  • Fixed missing parameter values when executing prepared statements.
  • Updated instrumentation to correctly read values from the second argument (args[1]) when the first argument is a query config object.
  • Ensured that db.postgresql.values is only recorded when enhancedDatabaseReporting:true.
  • Maintained query text sanitization, placeholders ($1, $2, etc.) remain in db.statement.

@github-actions github-actions bot requested a review from maryliag October 27, 2025 18:14
@aryamohanan aryamohanan marked this pull request as ready for review October 28, 2025 08:17
@aryamohanan aryamohanan requested a review from a team as a code owner October 28, 2025 08:17
@aryamohanan
Copy link
Contributor Author

@maryliag Could you please take a look at this PR? TIA


const instrumentationConfig = plugin.getConfig();

// Normalize the query configuration so that prepared statements with a separate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the suggestion on the issue itself, of just updating the line 342 to
values: (arg0 as any).values ?? (Array.isArray(args[1]) ? args[1] : undefined),, this way it avoids doing some repetition on checks, which is what you're doing here.

Would you mind making that solutions instead and checking if the tests will work as expected?

Copy link
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you!

@maryliag maryliag merged commit 5030825 into open-telemetry:main Nov 12, 2025
23 checks passed
@otelbot
Copy link
Contributor

otelbot bot commented Nov 12, 2025

Thank you for your contribution @aryamohanan! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query values not captured when passed as second argument (prepared statements)

2 participants