All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.build.cjs.trpc.js.map Maven / Gradle / Ivy

The newest version!
{"version":3,"file":"trpc.js","sources":["../../src/trpc.ts"],"sourcesContent":["import { getClient, withScope } from './currentScopes';\nimport { captureException } from './exports';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from './semanticAttributes';\nimport { startSpanManual } from './tracing';\nimport { normalize } from './utils-hoist/normalize';\n\ninterface SentryTrpcMiddlewareOptions {\n  /** Whether to include procedure inputs in reported events. Defaults to `false`. */\n  attachRpcInput?: boolean;\n}\n\nexport interface SentryTrpcMiddlewareArguments {\n  path?: unknown;\n  type?: unknown;\n  next: () => T;\n  rawInput?: unknown;\n  getRawInput?: () => Promise;\n}\n\nconst trpcCaptureContext = { mechanism: { handled: false, data: { function: 'trpcMiddleware' } } };\n\nfunction captureIfError(nextResult: unknown): void {\n  // TODO: Set span status based on what TRPCError was encountered\n  if (\n    typeof nextResult === 'object' &&\n    nextResult !== null &&\n    'ok' in nextResult &&\n    !nextResult.ok &&\n    'error' in nextResult\n  ) {\n    captureException(nextResult.error, trpcCaptureContext);\n  }\n}\n\ntype SentryTrpcMiddleware = T extends Promise ? T : Promise;\n\n/**\n * Sentry tRPC middleware that captures errors and creates spans for tRPC procedures.\n */\nexport function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {\n  // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n  // @ts-ignore\n  return async function (opts: SentryTrpcMiddlewareArguments): SentryTrpcMiddleware {\n    const { path, type, next, rawInput, getRawInput } = opts;\n\n    const client = getClient();\n    const clientOptions = client && client.getOptions();\n\n    const trpcContext: Record = {\n      procedure_path: path,\n      procedure_type: type,\n    };\n\n    if (options.attachRpcInput !== undefined ? options.attachRpcInput : clientOptions && clientOptions.sendDefaultPii) {\n      if (rawInput !== undefined) {\n        trpcContext.input = normalize(rawInput);\n      }\n\n      if (getRawInput !== undefined && typeof getRawInput === 'function') {\n        try {\n          const rawRes = await getRawInput();\n\n          trpcContext.input = normalize(rawRes);\n        } catch (err) {\n          // noop\n        }\n      }\n    }\n\n    return withScope(scope => {\n      scope.setContext('trpc', trpcContext);\n      return startSpanManual(\n        {\n          name: `trpc/${path}`,\n          op: 'rpc.server',\n          attributes: {\n            [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',\n            [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.rpc.trpc',\n          },\n        },\n        async span => {\n          try {\n            const nextResult = await next();\n            captureIfError(nextResult);\n            span.end();\n            return nextResult;\n          } catch (e) {\n            captureException(e, trpcCaptureContext);\n            span.end();\n            throw e;\n          }\n        },\n      ) as SentryTrpcMiddleware;\n    });\n  };\n}\n"],"names":["captureException","getClient","normalize","withScope","startSpanManual","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN"],"mappings":";;;;;;;;;;;;;;;AAmBA,MAAM,qBAAqB,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,gBAAiB,EAAA,IAAK;;AAElG,SAAS,cAAc,CAAC,UAAU,EAAiB;AACnD;AACA,EAAE;AACF,IAAI,OAAO,UAAW,KAAI,QAAS;AACnC,IAAI,UAAA,KAAe,IAAK;AACxB,IAAI,IAAA,IAAQ,UAAW;AACvB,IAAI,CAAC,UAAU,CAAC,EAAG;AACnB,IAAI,WAAW;AACf,IAAI;AACJ,IAAIA,0BAAgB,CAAC,UAAU,CAAC,KAAK,EAAE,kBAAkB,CAAC;AAC1D;AACA;;AAIA;AACA;AACA;AACO,SAAS,cAAc,CAAC,OAAO,GAAgC,EAAE,EAAE;AAC1E;AACA;AACA,EAAE,OAAO,gBAAmB,IAAI,EAA6D;AAC7F,IAAI,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAY,EA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