Skip to content

Commit eae9855

Browse files
committed
feat: update context for missing instrumentation
1 parent a26d2e9 commit eae9855

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/tests/instrumentation.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ test('Sends correct context when instrumentation was set up incorrectly', async
1313
expect(errorEvent.exception?.values).toHaveLength(1);
1414
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123');
1515

16-
expect(errorEvent.contexts?.Instrumentation).toEqual({
17-
isMissing: true,
16+
expect(errorEvent.contexts?.missing_instrumentation).toEqual({
1817
package: 'express',
19-
isCjs: true,
18+
'javascript.is_cjs': true,
2019
});
2120
});

packages/node/src/integrations/context.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import type {
1313
DeviceContext,
1414
Event,
1515
IntegrationFn,
16+
MissingInstrumentationContext,
1617
OsContext,
1718
} from '@sentry/types';
19+
import { isCjs } from '../utils/commonjs';
1820

1921
export const readFileAsync = promisify(readFile);
2022
export const readDirAsync = promisify(readdir);
@@ -476,3 +478,8 @@ function getCloudResourceContext(): CloudResourceContext | undefined {
476478
return undefined;
477479
}
478480
}
481+
482+
export const createMissingInstrumentationContext = (pkg: string): MissingInstrumentationContext => ({
483+
package: pkg,
484+
'javascript.is_cjs': isCjs(),
485+
});

packages/node/src/utils/ensureIsWrapped.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { isWrapped } from '@opentelemetry/core';
22
import { getGlobalScope, hasTracingEnabled, isEnabled } from '@sentry/core';
33
import { consoleSandbox } from '@sentry/utils';
4+
import { createMissingInstrumentationContext } from '../integrations/context';
45
import { isCjs } from './commonjs';
56

67
/**
@@ -25,10 +26,6 @@ export function ensureIsWrapped(
2526
}
2627
});
2728

28-
getGlobalScope().setContext('Instrumentation', {
29-
isMissing: true,
30-
package: name,
31-
isCjs: isCjs(),
32-
});
29+
getGlobalScope().setContext('missing_instrumentation', createMissingInstrumentationContext(name));
3330
}
3431
}

packages/types/src/context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,8 @@ export interface CloudResourceContext extends Record<string, unknown> {
119119
export interface ProfileContext extends Record<string, unknown> {
120120
profile_id: string;
121121
}
122+
123+
export interface MissingInstrumentationContext extends Record<string, unknown> {
124+
package: string;
125+
['javascript.is_cjs']?: boolean;
126+
}

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type {
1818
CultureContext,
1919
TraceContext,
2020
CloudResourceContext,
21+
MissingInstrumentationContext,
2122
} from './context';
2223
export type { DataCategory } from './datacategory';
2324
export type { DsnComponents, DsnLike, DsnProtocol } from './dsn';

0 commit comments

Comments
 (0)