aspecto-io / opentelemetry-ext-js

js extensions for the open-telemetry project
https://www.aspecto.io
Apache License 2.0
172 stars 40 forks source link

sequelize: Suggest better regex for opentelemetry-instrumentation-sequelize/utils.js extractTableFromQuery #253

Open ray58750034 opened 1 year ago

ray58750034 commented 1 year ago

Original code: https://github.com/aspecto-io/opentelemetry-ext-js/blob/master/packages/instrumentation-sequelize/src/utils.ts#L3

Suggest regex:

query.match(/(?<=(update|(?<!distinct\s+)from|join|truncate|into)\s+)\"?\`?(\w+)\"?\`?/gi);

Expect to work with following sqls:

UPDATE tableName SET field=value;
INSERT INTO tableName ("field") VALUES (value);
SELECT * FROM tableName WHERE field IS DISTINCT FROM value;