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

refactor(instrumentation-mysql2): improve performance of getSpanName using substring #2470

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

geotry
Copy link

@geotry geotry commented Oct 10, 2024

Which problem is this PR solving?

We noticed that getSpanName() from instrumentation-mysql2 was taking non-negligeable time from our profiler in production, considering that it's in a critical path.

This PR replaces split() by substring() to avoid instanciating a new array everytime.

Here is a benchmark with the difference before and after (~20 times faster for me): https://jsbm.dev/YtumA6nRNvjVJ

Short description of the changes

Use substring() with indexOf() instead of split() to extract the SQL verb from a sql query. It also checks for queries with no spaces like "COMMIT" and fallback to return the raw query.

@geotry geotry requested a review from a team as a code owner October 10, 2024 10:44
Copy link

linux-foundation-easycla bot commented Oct 10, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added pkg:instrumentation-mysql2 pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found. labels Oct 10, 2024
@maryliag
Copy link
Contributor

Would you mind doing the same change on the other mysql package, to keep consistency: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-mysql/src/utils.ts#L118

Copy link
Contributor

This package does not have an assigned component owner and is considered unmaintained. As such this package is in feature-freeze and this PR will be closed with 14 days unless a new owner or a sponsor (a member of @open-telemetry/javascript-approvers) for the feature is found. It is the responsibility of the author to find a sponsor for this feature.
Are you familiar with this package? Consider becoming a component owner.

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.53%. Comparing base (25ab243) to head (81e955b).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2470      +/-   ##
==========================================
- Coverage   90.74%   90.53%   -0.21%     
==========================================
  Files         156       99      -57     
  Lines        7723     5092    -2631     
  Branches     1588     1008     -580     
==========================================
- Hits         7008     4610    -2398     
+ Misses        715      482     -233     
Files with missing lines Coverage Δ
...e/opentelemetry-instrumentation-mysql/src/utils.ts 97.82% <100.00%> (+0.09%) ⬆️

... and 57 files with indirect coverage changes

@david-luna
Copy link
Contributor

@geotry

Thanks for contributing to OpenTelemetry :)

Could you run npm run lint:fix and push the changes to pass all checks?

@geotry
Copy link
Author

geotry commented Oct 11, 2024

thanks for the review

@maryliag I implemented the change in instrumentation-mysql and added tests to cover getSpanName().
I c/c the same code from instrumentation-mysql2 for consistency but it was slightly different as it was returning the full query string in case of an object instead of just the verb. I'm not sure wether it's safe or not to apply this change, let me know and I can revert it 👍

I also fixed the lint issues, sorry about that @david-luna

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:instrumentation-mysql pkg:instrumentation-mysql2 pkg-status:unmaintained:autoclose-scheduled pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants