diff --git a/packages/core/src/envelope.ts b/packages/core/src/envelope.ts index 023955df2208..f4e8b18f1bd4 100644 --- a/packages/core/src/envelope.ts +++ b/packages/core/src/envelope.ts @@ -35,6 +35,8 @@ function enhanceEventWithSdkInfo(event: Event, sdkInfo?: SdkInfo): Event { event.sdk.version = event.sdk.version || sdkInfo.version; event.sdk.integrations = [...(event.sdk.integrations || []), ...(sdkInfo.integrations || [])]; event.sdk.packages = [...(event.sdk.packages || []), ...(sdkInfo.packages || [])]; + // Either 'CDN', 'npm', or 'lambdaLayer'. This is hardcoded as part of our build process. + event.sdk.source = '__SDK_SOURCE__'; return event; } diff --git a/packages/serverless/rollup.aws.config.js b/packages/serverless/rollup.aws.config.js index 23c10b757f33..6da2c2ef4c7c 100644 --- a/packages/serverless/rollup.aws.config.js +++ b/packages/serverless/rollup.aws.config.js @@ -5,7 +5,7 @@ export default [ ...makeBundleConfigVariants( makeBaseBundleConfig({ // this automatically sets it to be CJS - bundleType: 'node', + bundleType: 'lambdaLayer', entrypoints: ['src/index.awslambda.ts'], jsVersion: 'es6', licenseTitle: '@sentry/serverless', diff --git a/packages/types/src/sdkinfo.ts b/packages/types/src/sdkinfo.ts index 0a839b0c7c95..0c280e521c91 100644 --- a/packages/types/src/sdkinfo.ts +++ b/packages/types/src/sdkinfo.ts @@ -5,4 +5,6 @@ export interface SdkInfo { version?: string; integrations?: string[]; packages?: Package[]; + // Either 'CDN', 'npm', or 'lambdaLayer'. This is hardcoded as part of our build process. + source?: string; } diff --git a/rollup/bundleHelpers.js b/rollup/bundleHelpers.js index 41888d54f77e..f1523814be1c 100644 --- a/rollup/bundleHelpers.js +++ b/rollup/bundleHelpers.js @@ -10,6 +10,7 @@ import { makeBrowserBuildPlugin, makeCommonJSPlugin, makeIsDebugBuildPlugin, + makeSDKSourcePlugin, makeLicensePlugin, makeNodeResolvePlugin, makeCleanupPlugin, @@ -28,6 +29,8 @@ export function makeBaseBundleConfig(options) { const sucrasePlugin = makeSucrasePlugin(); const cleanupPlugin = makeCleanupPlugin(); const markAsBrowserBuildPlugin = makeBrowserBuildPlugin(true); + const markAsCDNSourcePlugin = makeSDKSourcePlugin('CDN'); + const markAsLambdaLayerSourcePlugin = makeSDKSourcePlugin('lambdaLayer'); const licensePlugin = makeLicensePlugin(licenseTitle); const tsPlugin = makeTSPlugin(jsVersion.toLowerCase()); @@ -43,7 +46,7 @@ export function makeBaseBundleConfig(options) { name: 'Sentry', }, context: 'window', - plugins: [markAsBrowserBuildPlugin], + plugins: [markAsBrowserBuildPlugin, markAsCDNSourcePlugin], }; // used by `@sentry/integrations` and `@sentry/wasm` (bundles which need to be combined with a stand-alone SDK bundle) @@ -76,15 +79,15 @@ export function makeBaseBundleConfig(options) { // code to add after the CJS wrapper footer: '}(window));', }, - plugins: [markAsBrowserBuildPlugin], + plugins: [markAsBrowserBuildPlugin, markAsCDNSourcePlugin], }; // used by `@sentry/serverless`, when creating the lambda layer - const nodeBundleConfig = { + const lambdaLayerBundleConfig = { output: { format: 'cjs', }, - plugins: [commonJSPlugin], + plugins: [commonJSPlugin, markAsLambdaLayerSourcePlugin], // Don't bundle any of Node's core modules external: builtinModules, }; @@ -110,7 +113,7 @@ export function makeBaseBundleConfig(options) { const bundleTypeConfigMap = { standalone: standAloneBundleConfig, addon: addOnBundleConfig, - node: nodeBundleConfig, + lambdaLayer: lambdaLayerBundleConfig, }; return deepMerge.all([sharedBundleConfig, bundleTypeConfigMap[bundleType], packageSpecificConfig || {}], { diff --git a/rollup/npmHelpers.js b/rollup/npmHelpers.js index e1657f7ef598..cec45e1b579f 100644 --- a/rollup/npmHelpers.js +++ b/rollup/npmHelpers.js @@ -13,6 +13,7 @@ import { makeCleanupPlugin, makeSucrasePlugin, makeDebugBuildStatementReplacePlugin, + makeSDKSourcePlugin, } from './plugins/index.js'; import { mergePlugins } from './utils'; @@ -31,6 +32,7 @@ export function makeBaseNPMConfig(options = {}) { const debugBuildStatementReplacePlugin = makeDebugBuildStatementReplacePlugin(); const cleanupPlugin = makeCleanupPlugin(); const extractPolyfillsPlugin = makeExtractPolyfillsPlugin(); + const markAsNPMSourcePlugin = makeSDKSourcePlugin('npm'); const defaultBaseConfig = { input: entrypoints, @@ -85,6 +87,7 @@ export function makeBaseNPMConfig(options = {}) { nodeResolvePlugin, sucrasePlugin, debugBuildStatementReplacePlugin, + markAsNPMSourcePlugin, cleanupPlugin, extractPolyfillsPlugin, ], diff --git a/rollup/plugins/npmPlugins.js b/rollup/plugins/npmPlugins.js index ec162615623f..b664cb2a0ffb 100644 --- a/rollup/plugins/npmPlugins.js +++ b/rollup/plugins/npmPlugins.js @@ -104,4 +104,21 @@ export function makeDebugBuildStatementReplacePlugin() { }); } +/** + * Creates a plugin to replace all instances of "__SDK_SOURCE__" with either "CDN" or "npm". + * + * @returns A `@rollup/plugin-replace` instance. + */ +export function makeSDKSourcePlugin(source) { + return replace({ + // TODO `preventAssignment` will default to true in version 5.x of the replace plugin, at which point we can get rid + // of this. (It actually makes no difference in this case whether it's true or false, since we never assign to + // `__SDK_SOURCE__`, but if we don't give it a value, it will spam with warnings.) + preventAssignment: true, + values: { + __SDK_SOURCE__: source, + }, + }); +} + export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.js';