Skip to content

Commit 1adaaac

Browse files
committed
feat(node): add genericPool integration using opentelemetry instrumentation
Signed-off-by: Kaung Zin Hein <[email protected]>
1 parent 88fef5b commit 1adaaac

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

packages/node/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"@opentelemetry/resources": "^1.25.1",
8989
"@opentelemetry/sdk-trace-base": "^1.25.1",
9090
"@opentelemetry/semantic-conventions": "^1.25.1",
91+
"@opentelemetry/instrumentation-generic-pool": "^0.38.0",
9192
"@prisma/instrumentation": "5.17.0",
9293
"@sentry/core": "8.25.0",
9394
"@sentry/opentelemetry": "8.25.0",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { GenericPoolInstrumentation } from '@opentelemetry/instrumentation-generic-pool';
2+
import { defineIntegration, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON } from '@sentry/core';
3+
import type { IntegrationFn } from '@sentry/types';
4+
import { generateInstrumentOnce } from '../../otel/instrument';
5+
6+
const INTEGRATION_NAME = 'GenericPool';
7+
8+
export const instrumentGenericPool = generateInstrumentOnce(INTEGRATION_NAME, () => new GenericPoolInstrumentation({}));
9+
10+
const _genericPoolIntegration = (() => {
11+
return {
12+
name: INTEGRATION_NAME,
13+
setupOnce() {
14+
instrumentGenericPool();
15+
},
16+
17+
setup(client) {
18+
client.on('spanStart', span => {
19+
const spanJSON = spanToJSON(span);
20+
if (spanJSON.description === 'generic-pool.acquire') {
21+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.db.otel.generic-pool');
22+
}
23+
});
24+
},
25+
};
26+
}) satisfies IntegrationFn;
27+
28+
/**
29+
* GenericPool integration
30+
*
31+
* Capture tracing data for GenericPool.
32+
*/
33+
export const genericPoolIntegration = defineIntegration(_genericPoolIntegration);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { instrumentMysql2, mysql2Integration } from './mysql2';
1414
import { instrumentNest, nestIntegration } from './nest/nest';
1515
import { instrumentPostgres, postgresIntegration } from './postgres';
1616
import { instrumentRedis, redisIntegration } from './redis';
17+
import { instrumentGenericPool, genericPoolIntegration} from './genericPool'
1718

1819
/**
1920
* With OTEL, all performance integrations will be added, as OTEL only initializes them when the patched package is actually required.
@@ -37,6 +38,7 @@ export function getAutoPerformanceIntegrations(): Integration[] {
3738
hapiIntegration(),
3839
koaIntegration(),
3940
connectIntegration(),
41+
genericPoolIntegration(),
4042
];
4143
}
4244

@@ -61,5 +63,6 @@ export function getOpenTelemetryInstrumentationToPreload(): (((options?: any) =>
6163
instrumentHapi,
6264
instrumentGraphql,
6365
instrumentRedis,
66+
instrumentGenericPool,
6467
];
6568
}

0 commit comments

Comments
 (0)