Skip to content

feat(meta): Send SDK source data #6216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/serverless/rollup.aws.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/sdkinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
13 changes: 8 additions & 5 deletions rollup/bundleHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
makeBrowserBuildPlugin,
makeCommonJSPlugin,
makeIsDebugBuildPlugin,
makeSDKSourcePlugin,
makeLicensePlugin,
makeNodeResolvePlugin,
makeCleanupPlugin,
Expand All @@ -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());

Expand All @@ -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)
Expand Down Expand Up @@ -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,
};
Expand All @@ -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 || {}], {
Expand Down
3 changes: 3 additions & 0 deletions rollup/npmHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
makeCleanupPlugin,
makeSucrasePlugin,
makeDebugBuildStatementReplacePlugin,
makeSDKSourcePlugin,
} from './plugins/index.js';
import { mergePlugins } from './utils';

Expand All @@ -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,
Expand Down Expand Up @@ -85,6 +87,7 @@ export function makeBaseNPMConfig(options = {}) {
nodeResolvePlugin,
sucrasePlugin,
debugBuildStatementReplacePlugin,
markAsNPMSourcePlugin,
cleanupPlugin,
extractPolyfillsPlugin,
],
Expand Down
17 changes: 17 additions & 0 deletions rollup/plugins/npmPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';