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

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

There is a newer version: 8.39.0
Show newest version
{"version":3,"file":"trpc.js","sources":["../../src/trpc.ts"],"sourcesContent":["import { isThenable, normalize } from '@sentry/utils';\n\nimport { getClient } from './currentScopes';\nimport { captureException, setContext } from './exports';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from './semanticAttributes';\nimport { startSpanManual } from './tracing';\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}\n\nconst trpcCaptureContext = { mechanism: { handled: false, data: { function: 'trpcMiddleware' } } };\n\n/**\n * Sentry tRPC middleware that captures errors and creates spans for tRPC procedures.\n */\nexport function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {\n  return function (opts: SentryTrpcMiddlewareArguments): T {\n    const { path, type, next, rawInput } = opts;\n    const client = getClient();\n    const clientOptions = client && client.getOptions();\n\n    const trpcContext: Record = {\n      procedure_type: type,\n    };\n\n    if (options.attachRpcInput !== undefined ? options.attachRpcInput : clientOptions && clientOptions.sendDefaultPii) {\n      trpcContext.input = normalize(rawInput);\n    }\n\n    setContext('trpc', trpcContext);\n\n    function 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\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      span => {\n        let maybePromiseResult;\n        try {\n          maybePromiseResult = next();\n        } catch (e) {\n          captureException(e, trpcCaptureContext);\n          span.end();\n          throw e;\n        }\n\n        if (isThenable(maybePromiseResult)) {\n          return maybePromiseResult.then(\n            nextResult => {\n              captureIfError(nextResult);\n              span.end();\n              return nextResult;\n            },\n            e => {\n              captureException(e, trpcCaptureContext);\n              span.end();\n              throw e;\n            },\n          ) as T;\n        } else {\n          captureIfError(maybePromiseResult);\n          span.end();\n          return maybePromiseResult;\n        }\n      },\n    );\n  };\n}\n"],"names":[],"mappings":";;;;;;;;AAmBA,MAAM,qBAAqB,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,gBAAiB,EAAA,IAAK,CAAA;AAClG;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,OAAO,GAAgC,EAAE,EAAE;AAC1E,EAAE,OAAO,UAAa,IAAI,EAAuC;AACjE,IAAI,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAA,EAAW,GAAE,IAAI,CAAA;AAC/C,IAAI,MAAM,MAAA,GAAS,SAAS,EAAE,CAAA;AAC9B,IAAI,MAAM,gBAAgB,MAAA,IAAU,MAAM,CAAC,UAAU,EAAE,CAAA;AACvD;AACA,IAAI,MAAM,WAAW,GAA4B;AACjD,MAAM,cAAc,EAAE,IAAI;AAC1B,KAAK,CAAA;AACL;AACA,IAAI,IAAI,OAAO,CAAC,cAAA,KAAmB,SAAU,GAAE,OAAO,CAAC,iBAAiB,aAAA,IAAiB,aAAa,CAAC,cAAc,EAAE;AACvH,MAAM,WAAW,CAAC,KAAA,GAAQ,SAAS,CAAC,QAAQ,CAAC,CAAA;AAC7C,KAAI;AACJ;AACA,IAAI,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AACnC;AACA,IAAI,SAAS,cAAc,CAAC,UAAU,EAAiB;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