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

feat: typeorm instrumentation #2187

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

Conversation

seemk
Copy link
Contributor

@seemk seemk commented May 8, 2024

Short description of the changes

Adds the typeorm instrumentation created by Aspecto.

Only contains minor changes: upgraded to the latest SDK and semantic conventions package, modified the tests to use assert, changed the hook type signature.

@seemk seemk requested a review from a team as a code owner May 8, 2024 14:02
Copy link

codecov bot commented May 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.40%. Comparing base (dfb2dff) to head (7fd5fd0).
Report is 152 commits behind head on main.

Current head 7fd5fd0 differs from pull request most recent head 7d829a3

Please upload reports for the commit 7d829a3 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2187      +/-   ##
==========================================
- Coverage   90.97%   90.40%   -0.58%     
==========================================
  Files         146      149       +3     
  Lines        7492     7514      +22     
  Branches     1502     1573      +71     
==========================================
- Hits         6816     6793      -23     
- Misses        676      721      +45     

see 54 files with indirect coverage changes

Copy link
Member

@blumamir blumamir left a comment

Choose a reason for hiding this comment

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

Thank you for working on this 🙏🎉

Left few comments and suggestions

The original instrumentation had a test-all-versions setup. I wonder if it was left out on purpose or just overlooked.

plugins/node/instrumentation-typeorm/src/typeorm.ts Outdated Show resolved Hide resolved
plugins/node/instrumentation-typeorm/src/typeorm.ts Outdated Show resolved Hide resolved
plugins/node/instrumentation-typeorm/src/typeorm.ts Outdated Show resolved Hide resolved
plugins/node/instrumentation-typeorm/src/typeorm.ts Outdated Show resolved Hide resolved
plugins/node/instrumentation-typeorm/package.json Outdated Show resolved Hide resolved
plugins/node/instrumentation-typeorm/package.json Outdated Show resolved Hide resolved
plugins/node/instrumentation-typeorm/src/types.ts Outdated Show resolved Hide resolved
import { InstrumentationConfig } from '@opentelemetry/instrumentation';

export enum ExtendedDatabaseAttribute {
DB_STATEMENT_PARAMETERS = 'db.statement.parameters',
Copy link
Member

Choose a reason for hiding this comment

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

While this isn't a speced name similar to many others, there is still this rule for semantic attributes which the existing name violates:

Names SHOULD NOT coincide with namespaces. For example if service.instance.id is an attribute name then it is no longer valid to have an attribute named service.instance because service.instance is already a namespace

Since we already have db.statement, I think it is better to use the opportunity and rename it to db.typeorm.parameters (similar to 'db.postgresql.values', 'db.mysql.values'). or some other good name that does not make db.statement a namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it, thanks

if (typeof statement === 'string') {
statement = statement.trim();
try {
operation = statement.split(' ')[0].toUpperCase();
Copy link
Member

Choose a reason for hiding this comment

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

The semantic conventions for database says:

[2]: When setting this to an SQL keyword, it is not recommended to attempt any client-side parsing of db.statement just to get this property, but it should be set if the operation name is provided by the library being instrumented

Since this code does not cover many valid cases, can introduce performance hit, and the semantic conventions specifically advise aginst it, I would consider removing it from the instrumentation at the moment, or introducing a config option to opt-in to it.

If we end up keeping it, we can consider refactoring it for better performance - so that we don't need to parse the entire string and create an array just to get the first word:

let firstSpaceIndex = statement.indexOf(' ');
operation = firstSpaceIndex === -1 ? statement.toUpperCase() : statement.substring(0, firstSpaceIndex).toUpperCase();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it completely for now

plugins/node/instrumentation-typeorm/README.md Outdated Show resolved Hide resolved
@seemk
Copy link
Contributor Author

seemk commented May 22, 2024

Thank you for working on this 🙏🎉

Left few comments and suggestions

The original instrumentation had a test-all-versions setup. I wonder if it was left out on purpose or just overlooked.

Overlooked, going to re-add it, thanks!

Copy link
Member

@blumamir blumamir left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the comments. There are still few threads from previous review I think would be best to address now as this is already a breaking change from the original instrumentation and doing it later will be yet another breaking change for users.

If you prefer that we leave it as is, and address these less trivial cases sometime else, that is also ok with me.

plugins/node/instrumentation-typeorm/README.md Outdated Show resolved Hide resolved
plugins/node/instrumentation-typeorm/package.json Outdated Show resolved Hide resolved
@seemk
Copy link
Contributor Author

seemk commented Jun 4, 2024

Briefly messed up a commit and GitHub actions added various tags, shouldn't be a problem

@seemk
Copy link
Contributor Author

seemk commented Jun 5, 2024

Should've addressed all the feedback now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:auto-instrumentations-node pkg:auto-instrumentations-web pkg:host-metrics pkg:id-generator-aws-xray pkg:instrumentation-amqplib pkg:instrumentation-aws-lambda pkg:instrumentation-aws-sdk pkg:instrumentation-bunyan pkg:instrumentation-cassandra-driver pkg:instrumentation-connect pkg:instrumentation-cucumber pkg:instrumentation-dataloader pkg:instrumentation-dns pkg:instrumentation-document-load pkg:instrumentation-express pkg:instrumentation-fastify pkg:instrumentation-fs pkg:instrumentation-generic-pool pkg:instrumentation-graphql pkg:instrumentation-hapi pkg:instrumentation-ioredis pkg:instrumentation-knex pkg:instrumentation-koa pkg:instrumentation-long-task pkg:instrumentation-lru-memoizer pkg:instrumentation-memcached pkg:instrumentation-mongodb pkg:instrumentation-mongoose pkg:instrumentation-mysql pkg:instrumentation-mysql2 pkg:instrumentation-nestjs-core pkg:instrumentation-net pkg:instrumentation-pg pkg:instrumentation-pino pkg:instrumentation-redis pkg:instrumentation-redis-4 pkg:instrumentation-restify pkg:instrumentation-router pkg:instrumentation-runtime-node pkg:instrumentation-socket.io pkg:instrumentation-tedious pkg:instrumentation-undici pkg:instrumentation-user-interaction pkg:instrumentation-winston pkg:plugin-react-load pkg:propagation-utils pkg:resource-detector-alibaba-cloud pkg:resource-detector-aws pkg:resource-detector-azure pkg:resource-detector-container pkg:resource-detector-gcp pkg:resource-detector-instana pkg:sampler-aws-xray pkg:test-utils
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants