-
Notifications
You must be signed in to change notification settings - Fork 39
fix: handled non-promise return from instrumented pg call #2335
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8716104
fix: handled pg where instrumented promise is not returned
abhilash-sivan f9fd13f
chore: pr comment
abhilash-sivan 4dad0cd
chore: added log throttling
abhilash-sivan 2b9a400
chore: changed to logger.trace
abhilash-sivan 33f1b36
chore: fix test
abhilash-sivan 0329a98
chore: update packages/core/src/tracing/instrumentation/databases/pg.js
abhilash-sivan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -411,3 +411,21 @@ exports.setErrorDetails = function setErrorDetails(span, error, technology) { | |
| logger.error('Failed to set error details on span:', err); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Handles and logs a trace message when the instrumented function returns an unexpected value(not a promise) | ||
| * | ||
| * @param {*} returnValue - The return value from the instrumented function | ||
| * @param {string} spanName - The name of the span (e.g., 'redis', 'postgres', 'mysql') | ||
| * @param {string} operationContext - Additional context about the operation (e.g., 'query', 'command') | ||
| * @returns {boolean} - Returns true if the return value was unexpected (not a promise), false otherwise | ||
| */ | ||
| exports.handleUnexpectedReturnValue = function handleUnexpectedReturnValue(returnValue, spanName, operationContext) { | ||
| logger.trace( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed from debug to trace, this will not get logged unless the trace level is "TRACE" |
||
| `${spanName} instrumentation: Unexpected return value from ${operationContext}. ` + | ||
| `Expected a promise but got: ${typeof returnValue}. ` + | ||
| 'This indicates an unsupported library behavior.' | ||
| ); | ||
|
|
||
| return true; | ||
| }; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add this change due to an issue with tracing error cases after introducing the promise.then undefined handling.
When a callback was executed and an error occurred, finishSpan was being called twice — once from the callback wrapper and once from the promise handlers. In this specific error scenario, both paths were getting executed. (We only encountered this now because the newly added non-promise case exposed this scenario.)
To prevent this duplication, if callbackIndex >= 0, we now return early and skip the promise checks entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think this is even cleaner - no need to check again if there is a promise response.