Skip to content

Commit b3ba484

Browse files
committed
feat(node): Add knexIntegration to Node
Set up initial code and dependencies. Enable integration by default. Signed-off-by: Kaung Zin Hein <[email protected]>
1 parent 7d331fa commit b3ba484

File tree

6 files changed

+108
-2
lines changed

6 files changed

+108
-2
lines changed

dev-packages/node-integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"graphql": "^16.3.0",
4848
"http-terminator": "^3.2.0",
4949
"ioredis": "^5.4.1",
50+
"knex": "^2.5.1",
5051
"mongodb": "^3.7.3",
5152
"mongodb-memory-server-global": "^7.6.3",
5253
"mongoose": "^5.13.22",

packages/node/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"@opentelemetry/instrumentation-hapi": "0.40.0",
7878
"@opentelemetry/instrumentation-http": "0.52.1",
7979
"@opentelemetry/instrumentation-ioredis": "0.42.0",
80+
"@opentelemetry/instrumentation-knex": "0.39.0",
8081
"@opentelemetry/instrumentation-koa": "0.42.0",
8182
"@opentelemetry/instrumentation-mongodb": "0.46.0",
8283
"@opentelemetry/instrumentation-mongoose": "0.40.0",

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export { hapiIntegration, setupHapiErrorHandler } from './integrations/tracing/h
2626
export { koaIntegration, setupKoaErrorHandler } from './integrations/tracing/koa';
2727
export { connectIntegration, setupConnectErrorHandler } from './integrations/tracing/connect';
2828
export { spotlightIntegration } from './integrations/spotlight';
29+
export { knexIntegration } from './integrations/tracing/knex';
2930

3031
export { SentryContextManager } from './otel/contextManager';
3132
export { generateInstrumentOnce } from './otel/instrument';

packages/node/src/integrations/tracing/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { expressIntegration, instrumentExpress } from './express';
66
import { fastifyIntegration, instrumentFastify } from './fastify';
77
import { graphqlIntegration, instrumentGraphql } from './graphql';
88
import { hapiIntegration, instrumentHapi } from './hapi';
9+
import { instrumentKnex, knexIntegration } from './knex';
910
import { instrumentKoa, koaIntegration } from './koa';
1011
import { instrumentMongo, mongoIntegration } from './mongo';
1112
import { instrumentMongoose, mongooseIntegration } from './mongoose';
@@ -37,6 +38,7 @@ export function getAutoPerformanceIntegrations(): Integration[] {
3738
hapiIntegration(),
3839
koaIntegration(),
3940
connectIntegration(),
41+
knexIntegration(),
4042
];
4143
}
4244

@@ -61,5 +63,6 @@ export function getOpenTelemetryInstrumentationToPreload(): (((options?: any) =>
6163
instrumentHapi,
6264
instrumentGraphql,
6365
instrumentRedis,
66+
instrumentKnex,
6467
];
6568
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { KnexInstrumentation } from '@opentelemetry/instrumentation-knex';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration, spanToJSON } from '@sentry/core';
3+
import type { IntegrationFn } from '@sentry/types';
4+
import { generateInstrumentOnce } from '../../otel/instrument';
5+
6+
const INTEGRATION_NAME = 'Knex';
7+
8+
export const instrumentKnex = generateInstrumentOnce(INTEGRATION_NAME, () => new KnexInstrumentation({}));
9+
10+
const _knexIntegration = (() => {
11+
return {
12+
name: INTEGRATION_NAME,
13+
setupOnce() {
14+
instrumentKnex();
15+
},
16+
17+
setup(client) {
18+
client.on('spanStart', span => {
19+
const spanJSON = spanToJSON(span);
20+
21+
const spanDescription = spanJSON.description;
22+
console.log('[Knex]: span description: ', spanDescription);
23+
24+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.knex');
25+
});
26+
},
27+
};
28+
}) satisfies IntegrationFn;
29+
30+
/**
31+
* Knex integration
32+
*
33+
* Capture tracing data for Knex.
34+
*/
35+
export const knexIntegration = defineIntegration(_knexIntegration);

yarn.lock

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7148,6 +7148,14 @@
71487148
"@opentelemetry/redis-common" "^0.36.2"
71497149
"@opentelemetry/semantic-conventions" "^1.23.0"
71507150

7151+
"@opentelemetry/[email protected]":
7152+
version "0.39.0"
7153+
resolved "https://registry.yarnpkg.com/@opentelemetry/instrumentation-knex/-/instrumentation-knex-0.39.0.tgz#1650615221056676f2ecb6c1654ae7977f0b24cc"
7154+
integrity sha512-lRwTqIKQecPWDkH1KEcAUcFhCaNssbKSpxf4sxRTAROCwrCEnYkjOuqJHV+q1/CApjMTaKu0Er4LBv/6bDpoxA==
7155+
dependencies:
7156+
"@opentelemetry/instrumentation" "^0.52.0"
7157+
"@opentelemetry/semantic-conventions" "^1.22.0"
7158+
71517159
"@opentelemetry/[email protected]":
71527160
version "0.42.0"
71537161
resolved "https://registry.yarnpkg.com/@opentelemetry/instrumentation-koa/-/instrumentation-koa-0.42.0.tgz#1c180f3605448c2e57a4ba073b69ffba7b2970b3"
@@ -14472,6 +14480,11 @@ colord@^2.9.3:
1447214480
resolved "https://registry.yarnpkg.com/colord/-/colord-2.9.3.tgz#4f8ce919de456f1d5c1c368c307fe20f3e59fb43"
1447314481
integrity sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==
1447414482

14483+
14484+
version "2.0.19"
14485+
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798"
14486+
integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==
14487+
1447514488
colorette@^2.0.10:
1447614489
version "2.0.20"
1447714490
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.20.tgz#9eb793e6833067f7235902fcd3b09917a000a95a"
@@ -14519,7 +14532,7 @@ [email protected], commander@^7.2.0:
1451914532
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
1452014533
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==
1452114534

14522-
commander@^10.0.1:
14535+
commander@^10.0.0, commander@^10.0.1:
1452314536
version "10.0.1"
1452414537
resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06"
1452514538
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==
@@ -17977,7 +17990,7 @@ esm-env@^1.0.0:
1797717990
resolved "https://registry.yarnpkg.com/esm-env/-/esm-env-1.0.0.tgz#b124b40b180711690a4cb9b00d16573391950413"
1797817991
integrity sha512-Cf6VksWPsTuW01vU9Mk/3vRue91Zevka5SjyNf3nEpokFRuqt/KjUQoGAwq9qMmhpLTHmXzSIrFRw8zxWzmFBA==
1797917992

17980-
esm@^3.2.4:
17993+
esm@^3.2.25, esm@^3.2.4:
1798117994
version "3.2.25"
1798217995
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"
1798317996
integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==
@@ -19314,6 +19327,11 @@ get-value@^2.0.3, get-value@^2.0.6:
1931419327
resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28"
1931519328
integrity sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=
1931619329

19330+
19331+
version "2.3.0"
19332+
resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.3.0.tgz#71e5593284807e03e2427449d4f6712a268666f4"
19333+
integrity sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==
19334+
1931719335
giget@^1.2.3:
1931819336
version "1.2.3"
1931919337
resolved "https://registry.yarnpkg.com/giget/-/giget-1.2.3.tgz#ef6845d1140e89adad595f7f3bb60aa31c672cb6"
@@ -20996,6 +21014,11 @@ interpret@^1.0.0:
2099621014
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
2099721015
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
2099821016

21017+
interpret@^2.2.0:
21018+
version "2.2.0"
21019+
resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9"
21020+
integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==
21021+
2099921022
into-stream@^3.1.0:
2100021023
version "3.1.0"
2100121024
resolved "https://registry.yarnpkg.com/into-stream/-/into-stream-3.1.0.tgz#96fb0a936c12babd6ff1752a17d05616abd094c6"
@@ -22651,6 +22674,26 @@ klona@^2.0.4, klona@^2.0.5, klona@^2.0.6:
2265122674
resolved "https://registry.yarnpkg.com/klona/-/klona-2.0.6.tgz#85bffbf819c03b2f53270412420a4555ef882e22"
2265222675
integrity sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA==
2265322676

22677+
knex@^2.5.1:
22678+
version "2.5.1"
22679+
resolved "https://registry.yarnpkg.com/knex/-/knex-2.5.1.tgz#a6c6b449866cf4229f070c17411f23871ba52ef9"
22680+
integrity sha512-z78DgGKUr4SE/6cm7ku+jHvFT0X97aERh/f0MUKAKgFnwCYBEW4TFBqtHWFYiJFid7fMrtpZ/gxJthvz5mEByA==
22681+
dependencies:
22682+
colorette "2.0.19"
22683+
commander "^10.0.0"
22684+
debug "4.3.4"
22685+
escalade "^3.1.1"
22686+
esm "^3.2.25"
22687+
get-package-type "^0.1.0"
22688+
getopts "2.3.0"
22689+
interpret "^2.2.0"
22690+
lodash "^4.17.21"
22691+
pg-connection-string "2.6.1"
22692+
rechoir "^0.8.0"
22693+
resolve-from "^5.0.0"
22694+
tarn "^3.0.2"
22695+
tildify "2.0.0"
22696+
2265422697
knitwork@^1.0.0, knitwork@^1.1.0:
2265522698
version "1.1.0"
2265622699
resolved "https://registry.yarnpkg.com/knitwork/-/knitwork-1.1.0.tgz#d8c9feafadd7ee744ff64340b216a52c7199c417"
@@ -27048,6 +27091,11 @@ periscopic@^3.1.0:
2704827091
estree-walker "^3.0.0"
2704927092
is-reference "^3.0.0"
2705027093

27094+
27095+
version "2.6.1"
27096+
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.6.1.tgz#78c23c21a35dd116f48e12e23c0965e8d9e2cbfb"
27097+
integrity sha512-w6ZzNu6oMmIzEAYVw+RLK0+nqHPt8K3ZnknKi+g48Ak2pr3dtljJW3o+D/n2zzCG07Zoe9VOX3aiKpj+BN0pjg==
27098+
2705127099
pg-connection-string@^2.5.0:
2705227100
version "2.5.0"
2705327101
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34"
@@ -28869,6 +28917,13 @@ rechoir@^0.6.2:
2886928917
dependencies:
2887028918
resolve "^1.1.6"
2887128919

28920+
rechoir@^0.8.0:
28921+
version "0.8.0"
28922+
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22"
28923+
integrity sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==
28924+
dependencies:
28925+
resolve "^1.20.0"
28926+
2887228927
redent@^3.0.0:
2887328928
version "3.0.0"
2887428929
resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f"
@@ -31682,6 +31737,11 @@ tar@^6.2.0:
3168231737
mkdirp "^1.0.3"
3168331738
yallist "^4.0.0"
3168431739

31740+
tarn@^3.0.2:
31741+
version "3.0.2"
31742+
resolved "https://registry.yarnpkg.com/tarn/-/tarn-3.0.2.tgz#73b6140fbb881b71559c4f8bfde3d9a4b3d27693"
31743+
integrity sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ==
31744+
3168531745
teeny-request@^7.0.0:
3168631746
version "7.0.1"
3168731747
resolved "https://registry.yarnpkg.com/teeny-request/-/teeny-request-7.0.1.tgz#bdd41fdffea5f8fbc0d29392cb47bec4f66b2b4c"
@@ -31886,6 +31946,11 @@ thunky@^1.0.2:
3188631946
resolved "https://registry.yarnpkg.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d"
3188731947
integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==
3188831948

31949+
31950+
version "2.0.0"
31951+
resolved "https://registry.yarnpkg.com/tildify/-/tildify-2.0.0.tgz#f205f3674d677ce698b7067a99e949ce03b4754a"
31952+
integrity sha512-Cc+OraorugtXNfs50hU9KS369rFXCfgGLpfCfvlc+Ud5u6VWmUQsOAa9HbTvheQdYnrdJqqv1e5oIqXppMYnSw==
31953+
3188931954
timed-out@^4.0.1:
3189031955
version "4.0.1"
3189131956
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"

0 commit comments

Comments
 (0)