Skip to content

Commit 562e082

Browse files
committed
fix closure for instrumentation
1 parent 8a581cf commit 562e082

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

dev-packages/node-integration-tests/suites/express/multiple-routers/common-infix/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { loggingTransport } from '@sentry-internal/node-integration-tests';
22
import * as Sentry from '@sentry/node';
33

44
Sentry.init({
5+
debug: true,
56
dsn: 'https://[email protected]/1337',
67
release: '1.0',
78
tracesSampleRate: 1.0,

dev-packages/node-integration-tests/suites/tracing/ai/scenario.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const { loggingTransport } = require('@sentry-internal/node-integration-tests');
22
const Sentry = require('@sentry/node');
33

44
Sentry.init({
5-
debug: true,
65
dsn: 'https://[email protected]/1337',
76
release: '1.0',
87
tracesSampleRate: 1.0,

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP, defineIntegration, spanToJSON } from '@se
33
import type { IntegrationFn } from '@sentry/core';
44
import { generateInstrumentOnce } from '../../../otel/instrument';
55
import { addOriginToSpan } from '../../../utils/addOriginToSpan';
6-
import { SentryVercelAiInstrumentation } from './instrumentation';
6+
import { SentryVercelAiInstrumentation, sentryVercelAiPatched } from './instrumentation';
77

8-
const sentryVercelAiInstance = new SentryVercelAiInstrumentation({});
9-
10-
export const instrumentVercelAi = generateInstrumentOnce('vercelAI', () => sentryVercelAiInstance);
8+
export const instrumentVercelAi = generateInstrumentOnce('vercelAI', () => new SentryVercelAiInstrumentation({}));
119

1210
const _vercelAIIntegration = (() => {
1311
return {
1412
name: 'vercelAI',
1513
setupOnce() {
1614
instrumentVercelAi();
1715
},
18-
preprocessEvent(event) {
19-
if (!sentryVercelAiInstance.patchIsActive) {
20-
return;
21-
}
22-
16+
processEvent(event) {
2317
if (event.type === 'transaction' && event.spans?.length) {
2418
for (const span of event.spans) {
2519
const { data: attributes, description: name } = span;
@@ -46,10 +40,12 @@ const _vercelAIIntegration = (() => {
4640
}
4741
}
4842
}
43+
44+
return event;
4945
},
5046
setup(client) {
5147
client.on('spanStart', span => {
52-
if (!sentryVercelAiInstance.patchIsActive) {
48+
if (!sentryVercelAiPatched) {
5349
return;
5450
}
5551

packages/node/src/integrations/tracing/vercelai/instrumentation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ type MethodArgs = [MethodFirstArg, ...unknown[]];
2323
type PatchedModuleExports = Record<(typeof INSTRUMENTED_METHODS)[number], (...args: MethodArgs) => unknown> &
2424
Record<string, unknown>;
2525

26+
export let sentryVercelAiPatched = false;
27+
2628
/**
2729
* This detects is added by the Sentry Vercel AI Integration to detect if the integration should
2830
* be enabled.
2931
*
3032
* It also patches the `ai` module to enable Vercel AI telemetry automatically for all methods.
3133
*/
3234
export class SentryVercelAiInstrumentation extends InstrumentationBase {
33-
public patchIsActive: boolean = false;
34-
3535
public constructor(config: InstrumentationConfig = {}) {
36-
super('sentry-vercel-ai', SDK_VERSION, config);
36+
super('@sentry/instrumentation-vercel-ai', SDK_VERSION, config);
3737
}
3838

3939
/**
@@ -48,7 +48,7 @@ export class SentryVercelAiInstrumentation extends InstrumentationBase {
4848
* Patches module exports to enable Vercel AI telemetry.
4949
*/
5050
private _patch(moduleExports: PatchedModuleExports): unknown {
51-
this.patchIsActive = true;
51+
sentryVercelAiPatched = true;
5252

5353
function generatePatch(name: string) {
5454
return (...args: MethodArgs) => {

0 commit comments

Comments
 (0)