package.build.esm.integrations.requestdata.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Base implementation for all Sentry JavaScript SDKs
{"version":3,"file":"requestdata.js","sources":["../../../src/integrations/requestdata.ts"],"sourcesContent":["import type { IntegrationFn } from '@sentry/types';\nimport type { AddRequestDataToEventOptions, TransactionNamingScheme } from '@sentry/utils';\nimport { addRequestDataToEvent } from '@sentry/utils';\nimport { defineIntegration } from '../integration';\n\nexport type RequestDataIntegrationOptions = {\n /**\n * Controls what data is pulled from the request and added to the event\n */\n include?: {\n cookies?: boolean;\n data?: boolean;\n headers?: boolean;\n ip?: boolean;\n query_string?: boolean;\n url?: boolean;\n user?:\n | boolean\n | {\n id?: boolean;\n username?: boolean;\n email?: boolean;\n };\n };\n\n /** Whether to identify transactions by parameterized path, parameterized path with method, or handler name */\n transactionNamingScheme?: TransactionNamingScheme;\n};\n\nconst DEFAULT_OPTIONS = {\n include: {\n cookies: true,\n data: true,\n headers: true,\n ip: false,\n query_string: true,\n url: true,\n user: {\n id: true,\n username: true,\n email: true,\n },\n },\n transactionNamingScheme: 'methodPath' as const,\n};\n\nconst INTEGRATION_NAME = 'RequestData';\n\nconst _requestDataIntegration = ((options: RequestDataIntegrationOptions = {}) => {\n const _options: Required = {\n ...DEFAULT_OPTIONS,\n ...options,\n include: {\n ...DEFAULT_OPTIONS.include,\n ...options.include,\n user:\n options.include && typeof options.include.user === 'boolean'\n ? options.include.user\n : {\n ...DEFAULT_OPTIONS.include.user,\n // Unclear why TS still thinks `options.include.user` could be a boolean at this point\n ...((options.include || {}).user as Record),\n },\n },\n };\n\n return {\n name: INTEGRATION_NAME,\n processEvent(event) {\n // Note: In the long run, most of the logic here should probably move into the request data utility functions. For\n // the moment it lives here, though, until https://github.com/getsentry/sentry-javascript/issues/5718 is addressed.\n // (TL;DR: Those functions touch many parts of the repo in many different ways, and need to be cleaned up. Once\n // that's happened, it will be easier to add this logic in without worrying about unexpected side effects.)\n\n const { sdkProcessingMetadata = {} } = event;\n const req = sdkProcessingMetadata.request;\n\n if (!req) {\n return event;\n }\n\n const addRequestDataOptions = convertReqDataIntegrationOptsToAddReqDataOpts(_options);\n\n return addRequestDataToEvent(event, req, addRequestDataOptions);\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Add data about a request to an event. Primarily for use in Node-based SDKs, but included in `@sentry/core`\n * so it can be used in cross-platform SDKs like `@sentry/nextjs`.\n */\nexport const requestDataIntegration = defineIntegration(_requestDataIntegration);\n\n/** Convert this integration's options to match what `addRequestDataToEvent` expects */\n/** TODO: Can possibly be deleted once https://github.com/getsentry/sentry-javascript/issues/5718 is fixed */\nfunction convertReqDataIntegrationOptsToAddReqDataOpts(\n integrationOptions: Required,\n): AddRequestDataToEventOptions {\n const {\n transactionNamingScheme,\n include: { ip, user, ...requestOptions },\n } = integrationOptions;\n\n const requestIncludeKeys: string[] = ['method'];\n for (const [key, value] of Object.entries(requestOptions)) {\n if (value) {\n requestIncludeKeys.push(key);\n }\n }\n\n let addReqDataUserOpt;\n if (user === undefined) {\n addReqDataUserOpt = true;\n } else if (typeof user === 'boolean') {\n addReqDataUserOpt = user;\n } else {\n const userIncludeKeys: string[] = [];\n for (const [key, value] of Object.entries(user)) {\n if (value) {\n userIncludeKeys.push(key);\n }\n }\n addReqDataUserOpt = userIncludeKeys;\n }\n\n return {\n include: {\n ip,\n user: addReqDataUserOpt,\n request: requestIncludeKeys.length !== 0 ? requestIncludeKeys : undefined,\n transaction: transactionNamingScheme,\n },\n };\n}\n"],"names":[],"mappings":";;;AA6BA,MAAM,kBAAkB;AACxB,EAAE,OAAO,EAAE;AACX,IAAI,OAAO,EAAE,IAAI;AACjB,IAAI,IAAI,EAAE,IAAI;AACd,IAAI,OAAO,EAAE,IAAI;AACjB,IAAI,EAAE,EAAE,KAAK;AACb,IAAI,YAAY,EAAE,IAAI;AACtB,IAAI,GAAG,EAAE,IAAI;AACb,IAAI,IAAI,EAAE;AACV,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