@sentry/node 9.41.0 → 10.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/integrations/tracing/express.js +0 -13
- package/build/cjs/integrations/tracing/express.js.map +1 -1
- package/build/cjs/integrations/tracing/fastify/index.js +10 -56
- package/build/cjs/integrations/tracing/fastify/index.js.map +1 -1
- package/build/cjs/integrations/tracing/index.js +0 -1
- package/build/cjs/integrations/tracing/index.js.map +1 -1
- package/build/cjs/integrations/tracing/redis.js +4 -4
- package/build/cjs/integrations/tracing/redis.js.map +1 -1
- package/build/cjs/integrations/tracing/vercelai/instrumentation.js +2 -15
- package/build/cjs/integrations/tracing/vercelai/instrumentation.js.map +1 -1
- package/build/cjs/sdk/initOtel.js +8 -6
- package/build/cjs/sdk/initOtel.js.map +1 -1
- package/build/esm/integrations/tracing/express.js +1 -13
- package/build/esm/integrations/tracing/express.js.map +1 -1
- package/build/esm/integrations/tracing/fastify/index.js +10 -56
- package/build/esm/integrations/tracing/fastify/index.js.map +1 -1
- package/build/esm/integrations/tracing/index.js +1 -2
- package/build/esm/integrations/tracing/index.js.map +1 -1
- package/build/esm/integrations/tracing/redis.js +3 -3
- package/build/esm/integrations/tracing/redis.js.map +1 -1
- package/build/esm/integrations/tracing/vercelai/instrumentation.js +3 -16
- package/build/esm/integrations/tracing/vercelai/instrumentation.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/sdk/initOtel.js +9 -7
- package/build/esm/sdk/initOtel.js.map +1 -1
- package/build/types/integrations/tracing/express.d.ts +0 -4
- package/build/types/integrations/tracing/express.d.ts.map +1 -1
- package/build/types/integrations/tracing/fastify/index.d.ts +2 -38
- package/build/types/integrations/tracing/fastify/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/index.d.ts.map +1 -1
- package/build/types/integrations/tracing/vercelai/instrumentation.d.ts.map +1 -1
- package/build/types/sdk/initOtel.d.ts.map +1 -1
- package/build/types-ts3.8/integrations/tracing/express.d.ts +0 -4
- package/build/types-ts3.8/integrations/tracing/fastify/index.d.ts +2 -38
- package/package.json +31 -31
- package/build/cjs/integrations/tracing/express-v5/enums/AttributeNames.js +0 -22
- package/build/cjs/integrations/tracing/express-v5/enums/AttributeNames.js.map +0 -1
- package/build/cjs/integrations/tracing/express-v5/enums/ExpressLayerType.js +0 -23
- package/build/cjs/integrations/tracing/express-v5/enums/ExpressLayerType.js.map +0 -1
- package/build/cjs/integrations/tracing/express-v5/instrumentation.js +0 -297
- package/build/cjs/integrations/tracing/express-v5/instrumentation.js.map +0 -1
- package/build/cjs/integrations/tracing/express-v5/internal-types.js +0 -29
- package/build/cjs/integrations/tracing/express-v5/internal-types.js.map +0 -1
- package/build/cjs/integrations/tracing/express-v5/utils.js +0 -176
- package/build/cjs/integrations/tracing/express-v5/utils.js.map +0 -1
- package/build/esm/integrations/tracing/express-v5/enums/AttributeNames.js +0 -22
- package/build/esm/integrations/tracing/express-v5/enums/AttributeNames.js.map +0 -1
- package/build/esm/integrations/tracing/express-v5/enums/ExpressLayerType.js +0 -23
- package/build/esm/integrations/tracing/express-v5/enums/ExpressLayerType.js.map +0 -1
- package/build/esm/integrations/tracing/express-v5/instrumentation.js +0 -293
- package/build/esm/integrations/tracing/express-v5/instrumentation.js.map +0 -1
- package/build/esm/integrations/tracing/express-v5/internal-types.js +0 -26
- package/build/esm/integrations/tracing/express-v5/internal-types.js.map +0 -1
- package/build/esm/integrations/tracing/express-v5/utils.js +0 -169
- package/build/esm/integrations/tracing/express-v5/utils.js.map +0 -1
- package/build/types/integrations/tracing/express-v5/enums/AttributeNames.d.ts +0 -5
- package/build/types/integrations/tracing/express-v5/enums/AttributeNames.d.ts.map +0 -1
- package/build/types/integrations/tracing/express-v5/enums/ExpressLayerType.d.ts +0 -6
- package/build/types/integrations/tracing/express-v5/enums/ExpressLayerType.d.ts.map +0 -1
- package/build/types/integrations/tracing/express-v5/instrumentation.d.ts +0 -27
- package/build/types/integrations/tracing/express-v5/instrumentation.d.ts.map +0 -1
- package/build/types/integrations/tracing/express-v5/internal-types.d.ts +0 -38
- package/build/types/integrations/tracing/express-v5/internal-types.d.ts.map +0 -1
- package/build/types/integrations/tracing/express-v5/types.d.ts +0 -39
- package/build/types/integrations/tracing/express-v5/types.d.ts.map +0 -1
- package/build/types/integrations/tracing/express-v5/utils.d.ts +0 -51
- package/build/types/integrations/tracing/express-v5/utils.d.ts.map +0 -1
- package/build/types-ts3.8/integrations/tracing/express-v5/enums/AttributeNames.d.ts +0 -5
- package/build/types-ts3.8/integrations/tracing/express-v5/enums/ExpressLayerType.d.ts +0 -6
- package/build/types-ts3.8/integrations/tracing/express-v5/instrumentation.d.ts +0 -27
- package/build/types-ts3.8/integrations/tracing/express-v5/internal-types.d.ts +0 -38
- package/build/types-ts3.8/integrations/tracing/express-v5/types.d.ts +0 -39
- package/build/types-ts3.8/integrations/tracing/express-v5/utils.d.ts +0 -57
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sources":["../../../../../src/integrations/tracing/express-v5/instrumentation.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/member-ordering */\n/* eslint-disable guard-for-in */\n/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable prefer-rest-params */\n/* eslint-disable @typescript-eslint/no-this-alias */\n/* eslint-disable jsdoc/require-jsdoc */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\n/* eslint-disable @typescript-eslint/explicit-member-accessibility */\n\n/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport { context, diag, SpanStatusCode, trace } from '@opentelemetry/api';\nimport { getRPCMetadata, RPCType } from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\nimport type * as express from 'express';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { ExpressLayerType } from './enums/ExpressLayerType';\nimport type { ExpressLayer, ExpressRouter, PatchedRequest } from './internal-types';\nimport { _LAYERS_STORE_PROPERTY, kLayerPatched } from './internal-types';\nimport type { ExpressInstrumentationConfig, ExpressRequestInfo } from './types';\nimport { asErrorAndMessage, getLayerMetadata, getLayerPath, isLayerIgnored, storeLayerPath } from './utils';\n\nexport const PACKAGE_VERSION = '0.1.0';\nexport const PACKAGE_NAME = '@sentry/instrumentation-express-v5';\n\n/** Express instrumentation for OpenTelemetry */\nexport class ExpressInstrumentationV5 extends InstrumentationBase<ExpressInstrumentationConfig> {\n constructor(config: ExpressInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n init() {\n return [\n new InstrumentationNodeModuleDefinition(\n 'express',\n ['>=5.0.0'],\n moduleExports => this._setup(moduleExports),\n moduleExports => this._tearDown(moduleExports),\n ),\n ];\n }\n\n private _setup(moduleExports: any) {\n const routerProto = moduleExports.Router.prototype;\n // patch express.Router.route\n if (isWrapped(routerProto.route)) {\n this._unwrap(routerProto, 'route');\n }\n this._wrap(routerProto, 'route', this._getRoutePatch());\n // patch express.Router.use\n if (isWrapped(routerProto.use)) {\n this._unwrap(routerProto, 'use');\n }\n this._wrap(routerProto, 'use', this._getRouterUsePatch() as any);\n // patch express.Application.use\n if (isWrapped(moduleExports.application.use)) {\n this._unwrap(moduleExports.application, 'use');\n }\n this._wrap(moduleExports.application, 'use', this._getAppUsePatch() as any);\n return moduleExports;\n }\n\n private _tearDown(moduleExports: any) {\n if (moduleExports === undefined) return;\n const routerProto = moduleExports.Router.prototype;\n this._unwrap(routerProto, 'route');\n this._unwrap(routerProto, 'use');\n this._unwrap(moduleExports.application, 'use');\n }\n\n /**\n * Get the patch for Router.route function\n */\n private _getRoutePatch() {\n const instrumentation = this;\n return function (original: express.Router['route']) {\n return function route_trace(this: ExpressRouter, ...args: Parameters<typeof original>) {\n const route = original.apply(this, args);\n const layer = this.stack[this.stack.length - 1] as ExpressLayer;\n instrumentation._applyPatch(layer, getLayerPath(args));\n return route;\n };\n };\n }\n\n /**\n * Get the patch for Router.use function\n */\n private _getRouterUsePatch() {\n const instrumentation = this;\n return function (original: express.Router['use']) {\n return function use(this: express.Application, ...args: Parameters<typeof original>) {\n const route = original.apply(this, args);\n const layer = this.stack[this.stack.length - 1] as ExpressLayer;\n instrumentation._applyPatch(layer, getLayerPath(args));\n return route;\n };\n };\n }\n\n /**\n * Get the patch for Application.use function\n */\n private _getAppUsePatch() {\n const instrumentation = this;\n return function (original: express.Application['use']) {\n return function use(\n // In express 5.x the router is stored in `router` whereas in 4.x it's stored in `_router`\n this: { _router?: ExpressRouter; router?: ExpressRouter },\n ...args: Parameters<typeof original>\n ) {\n // if we access app.router in express 4.x we trigger an assertion error\n // This property existed in v3, was removed in v4 and then re-added in v5\n const router = this.router;\n const route = original.apply(this, args);\n if (router) {\n const layer = router.stack[router.stack.length - 1] as ExpressLayer;\n instrumentation._applyPatch(layer, getLayerPath(args));\n }\n return route;\n };\n };\n }\n\n /** Patch each express layer to create span and propagate context */\n private _applyPatch(this: ExpressInstrumentationV5, layer: ExpressLayer, layerPath?: string) {\n const instrumentation = this;\n // avoid patching multiple times the same layer\n if (layer[kLayerPatched] === true) return;\n layer[kLayerPatched] = true;\n\n this._wrap(layer, 'handle', original => {\n // TODO: instrument error handlers\n if (original.length === 4) return original;\n\n const patched = function (this: ExpressLayer, req: PatchedRequest, res: express.Response) {\n storeLayerPath(req, layerPath);\n const route = (req[_LAYERS_STORE_PROPERTY] as string[])\n .filter(path => path !== '/' && path !== '/*')\n .join('')\n // remove duplicate slashes to normalize route\n .replace(/\\/{2,}/g, '/');\n\n const actualRoute = route.length > 0 ? route : undefined;\n\n const attributes: Attributes = {\n // eslint-disable-next-line deprecation/deprecation\n [SEMATTRS_HTTP_ROUTE]: actualRoute,\n };\n const metadata = getLayerMetadata(route, layer, layerPath);\n const type = metadata.attributes[AttributeNames.EXPRESS_TYPE] as ExpressLayerType;\n\n const rpcMetadata = getRPCMetadata(context.active());\n if (rpcMetadata?.type === RPCType.HTTP) {\n rpcMetadata.route = actualRoute;\n }\n\n // verify against the config if the layer should be ignored\n if (isLayerIgnored(metadata.name, type, instrumentation.getConfig())) {\n if (type === ExpressLayerType.MIDDLEWARE) {\n (req[_LAYERS_STORE_PROPERTY] as string[]).pop();\n }\n return original.apply(this, arguments);\n }\n\n if (trace.getSpan(context.active()) === undefined) {\n return original.apply(this, arguments);\n }\n\n const spanName = instrumentation._getSpanName(\n {\n request: req,\n layerType: type,\n route,\n },\n metadata.name,\n );\n const span = instrumentation.tracer.startSpan(spanName, {\n attributes: Object.assign(attributes, metadata.attributes),\n });\n\n const { requestHook } = instrumentation.getConfig();\n if (requestHook) {\n safeExecuteInTheMiddle(\n () =>\n requestHook(span, {\n request: req,\n layerType: type,\n route,\n }),\n e => {\n if (e) {\n diag.error('express instrumentation: request hook failed', e);\n }\n },\n true,\n );\n }\n\n let spanHasEnded = false;\n if (metadata.attributes[AttributeNames.EXPRESS_TYPE] !== ExpressLayerType.MIDDLEWARE) {\n span.end();\n spanHasEnded = true;\n }\n // listener for response.on('finish')\n const onResponseFinish = () => {\n if (spanHasEnded === false) {\n spanHasEnded = true;\n span.end();\n }\n };\n\n // verify we have a callback\n const args = Array.from(arguments);\n const callbackIdx = args.findIndex(arg => typeof arg === 'function');\n if (callbackIdx >= 0) {\n arguments[callbackIdx] = function () {\n // express considers anything but an empty value, \"route\" or \"router\"\n // passed to its callback to be an error\n const maybeError = arguments[0];\n const isError = ![undefined, null, 'route', 'router'].includes(maybeError);\n if (!spanHasEnded && isError) {\n const [error, message] = asErrorAndMessage(maybeError);\n span.recordException(error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message,\n });\n }\n\n if (spanHasEnded === false) {\n spanHasEnded = true;\n req.res?.removeListener('finish', onResponseFinish);\n span.end();\n }\n if (!(req.route && isError)) {\n (req[_LAYERS_STORE_PROPERTY] as string[]).pop();\n }\n const callback = args[callbackIdx] as Function;\n return callback.apply(this, arguments);\n };\n }\n\n try {\n return original.apply(this, arguments);\n } catch (anyError) {\n const [error, message] = asErrorAndMessage(anyError);\n span.recordException(error);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message,\n });\n throw anyError;\n } finally {\n /**\n * At this point if the callback wasn't called, that means either the\n * layer is asynchronous (so it will call the callback later on) or that\n * the layer directly end the http response, so we'll hook into the \"finish\"\n * event to handle the later case.\n */\n if (!spanHasEnded) {\n res.once('finish', onResponseFinish);\n }\n }\n };\n\n // `handle` isn't just a regular function in some cases. It also contains\n // some properties holding metadata and state so we need to proxy them\n // through through patched function\n // ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1950\n // Also some apps/libs do their own patching before OTEL and have these properties\n // in the proptotype. So we use a `for...in` loop to get own properties and also\n // any enumerable prop in the prototype chain\n // ref: https://github.com/open-telemetry/opentelemetry-js-contrib/issues/2271\n for (const key in original) {\n Object.defineProperty(patched, key, {\n get() {\n return original[key];\n },\n set(value) {\n original[key] = value;\n },\n });\n }\n return patched;\n });\n }\n\n _getSpanName(info: ExpressRequestInfo, defaultName: string) {\n const { spanNameHook } = this.getConfig();\n\n if (!(spanNameHook instanceof Function)) {\n return defaultName;\n }\n\n try {\n return spanNameHook(info, defaultName) ?? defaultName;\n } catch (err) {\n diag.error('express instrumentation: error calling span name rewrite hook', err);\n return defaultName;\n }\n }\n}\n"],"names":[],"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AAI,CAAC,KAAK,CAAC,+DAA+D,EAAE,GAAG,CAAC;AACtF,MAAM,OAAO,WAAW;AACxB;AACA;AACA;;;;"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This symbol is used to mark express layer as being already instrumented
|
|
3
|
-
* since its possible to use a given layer multiple times (ex: middlewares)
|
|
4
|
-
*/
|
|
5
|
-
const kLayerPatched = Symbol('express-layer-patched');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This const define where on the `request` object the Instrumentation will mount the
|
|
9
|
-
* current stack of express layer.
|
|
10
|
-
*
|
|
11
|
-
* It is necessary because express doesn't store the different layers
|
|
12
|
-
* (ie: middleware, router etc) that it called to get to the current layer.
|
|
13
|
-
* Given that, the only way to know the route of a given layer is to
|
|
14
|
-
* store the path of where each previous layer has been mounted.
|
|
15
|
-
*
|
|
16
|
-
* ex: bodyParser > auth middleware > /users router > get /:id
|
|
17
|
-
* in this case the stack would be: ["/users", "/:id"]
|
|
18
|
-
*
|
|
19
|
-
* ex2: bodyParser > /api router > /v1 router > /users router > get /:id
|
|
20
|
-
* stack: ["/api", "/v1", "/users", ":id"]
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
const _LAYERS_STORE_PROPERTY = '__ot_middlewares';
|
|
24
|
-
|
|
25
|
-
export { _LAYERS_STORE_PROPERTY, kLayerPatched };
|
|
26
|
-
//# sourceMappingURL=internal-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal-types.js","sources":["../../../../../src/integrations/tracing/express-v5/internal-types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/ban-types */\n\n/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Request } from 'express';\n\n/**\n * This symbol is used to mark express layer as being already instrumented\n * since its possible to use a given layer multiple times (ex: middlewares)\n */\nexport const kLayerPatched: unique symbol = Symbol('express-layer-patched');\n\n/**\n * This const define where on the `request` object the Instrumentation will mount the\n * current stack of express layer.\n *\n * It is necessary because express doesn't store the different layers\n * (ie: middleware, router etc) that it called to get to the current layer.\n * Given that, the only way to know the route of a given layer is to\n * store the path of where each previous layer has been mounted.\n *\n * ex: bodyParser > auth middleware > /users router > get /:id\n * in this case the stack would be: [\"/users\", \"/:id\"]\n *\n * ex2: bodyParser > /api router > /v1 router > /users router > get /:id\n * stack: [\"/api\", \"/v1\", \"/users\", \":id\"]\n *\n */\nexport const _LAYERS_STORE_PROPERTY = '__ot_middlewares';\n\nexport type PatchedRequest = {\n [_LAYERS_STORE_PROPERTY]?: string[];\n} & Request;\nexport type PathParams = string | RegExp | Array<string | RegExp>;\n\n// https://github.com/expressjs/express/blob/main/lib/router/index.js#L53\nexport type ExpressRouter = {\n stack: ExpressLayer[];\n};\n\n// https://github.com/expressjs/express/blob/main/lib/router/layer.js#L33\nexport type ExpressLayer = {\n handle: Function & Record<string, any>;\n [kLayerPatched]?: boolean;\n name: string;\n path: string;\n route?: ExpressLayer;\n};\n"],"names":[],"mappings":"AAqBA;AACA;AACA;AACA;MACa,aAAa,GAAkB,MAAM,CAAC,uBAAuB;;AAE1E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,sBAAA,GAAyB;;;;"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { AttributeNames } from './enums/AttributeNames.js';
|
|
2
|
-
import { ExpressLayerType } from './enums/ExpressLayerType.js';
|
|
3
|
-
import { _LAYERS_STORE_PROPERTY } from './internal-types.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Store layers path in the request to be able to construct route later
|
|
7
|
-
* @param request The request where
|
|
8
|
-
* @param [value] the value to push into the array
|
|
9
|
-
*/
|
|
10
|
-
const storeLayerPath = (request, value) => {
|
|
11
|
-
if (Array.isArray(request[_LAYERS_STORE_PROPERTY]) === false) {
|
|
12
|
-
Object.defineProperty(request, _LAYERS_STORE_PROPERTY, {
|
|
13
|
-
enumerable: false,
|
|
14
|
-
value: [],
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
if (value === undefined) return;
|
|
18
|
-
(request[_LAYERS_STORE_PROPERTY] ).push(value);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Recursively search the router path from layer stack
|
|
23
|
-
* @param path The path to reconstruct
|
|
24
|
-
* @param layer The layer to reconstruct from
|
|
25
|
-
* @returns The reconstructed path
|
|
26
|
-
*/
|
|
27
|
-
const getRouterPath = (path, layer) => {
|
|
28
|
-
const stackLayer = layer.handle?.stack?.[0];
|
|
29
|
-
|
|
30
|
-
if (stackLayer?.route?.path) {
|
|
31
|
-
return `${path}${stackLayer.route.path}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (stackLayer?.handle?.stack) {
|
|
35
|
-
return getRouterPath(path, stackLayer);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return path;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Parse express layer context to retrieve a name and attributes.
|
|
43
|
-
* @param route The route of the layer
|
|
44
|
-
* @param layer Express layer
|
|
45
|
-
* @param [layerPath] if present, the path on which the layer has been mounted
|
|
46
|
-
*/
|
|
47
|
-
const getLayerMetadata = (
|
|
48
|
-
route,
|
|
49
|
-
layer,
|
|
50
|
-
layerPath,
|
|
51
|
-
|
|
52
|
-
) => {
|
|
53
|
-
if (layer.name === 'router') {
|
|
54
|
-
const maybeRouterPath = getRouterPath('', layer);
|
|
55
|
-
const extractedRouterPath = maybeRouterPath ? maybeRouterPath : layerPath || route || '/';
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
attributes: {
|
|
59
|
-
[AttributeNames.EXPRESS_NAME]: extractedRouterPath,
|
|
60
|
-
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER,
|
|
61
|
-
},
|
|
62
|
-
name: `router - ${extractedRouterPath}`,
|
|
63
|
-
};
|
|
64
|
-
} else if (layer.name === 'bound dispatch' || layer.name === 'handle') {
|
|
65
|
-
return {
|
|
66
|
-
attributes: {
|
|
67
|
-
[AttributeNames.EXPRESS_NAME]: (route || layerPath) ?? 'request handler',
|
|
68
|
-
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER,
|
|
69
|
-
},
|
|
70
|
-
name: `request handler${layer.path ? ` - ${route || layerPath}` : ''}`,
|
|
71
|
-
};
|
|
72
|
-
} else {
|
|
73
|
-
return {
|
|
74
|
-
attributes: {
|
|
75
|
-
[AttributeNames.EXPRESS_NAME]: layer.name,
|
|
76
|
-
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE,
|
|
77
|
-
},
|
|
78
|
-
name: `middleware - ${layer.name}`,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Check whether the given obj match pattern
|
|
85
|
-
* @param constant e.g URL of request
|
|
86
|
-
* @param obj obj to inspect
|
|
87
|
-
* @param pattern Match pattern
|
|
88
|
-
*/
|
|
89
|
-
const satisfiesPattern = (constant, pattern) => {
|
|
90
|
-
if (typeof pattern === 'string') {
|
|
91
|
-
return pattern === constant;
|
|
92
|
-
} else if (pattern instanceof RegExp) {
|
|
93
|
-
return pattern.test(constant);
|
|
94
|
-
} else if (typeof pattern === 'function') {
|
|
95
|
-
return pattern(constant);
|
|
96
|
-
} else {
|
|
97
|
-
throw new TypeError('Pattern is in unsupported datatype');
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Check whether the given request is ignored by configuration
|
|
103
|
-
* It will not re-throw exceptions from `list` provided by the client
|
|
104
|
-
* @param constant e.g URL of request
|
|
105
|
-
* @param [list] List of ignore patterns
|
|
106
|
-
* @param [onException] callback for doing something when an exception has
|
|
107
|
-
* occurred
|
|
108
|
-
*/
|
|
109
|
-
const isLayerIgnored = (
|
|
110
|
-
name,
|
|
111
|
-
type,
|
|
112
|
-
config,
|
|
113
|
-
) => {
|
|
114
|
-
if (Array.isArray(config?.ignoreLayersType) && config?.ignoreLayersType?.includes(type)) {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
if (Array.isArray(config?.ignoreLayers) === false) return false;
|
|
118
|
-
try {
|
|
119
|
-
for (const pattern of config.ignoreLayers) {
|
|
120
|
-
if (satisfiesPattern(name, pattern)) {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
} catch {
|
|
125
|
-
/* catch block */
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return false;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Converts a user-provided error value into an error and error message pair
|
|
133
|
-
*
|
|
134
|
-
* @param error - User-provided error value
|
|
135
|
-
* @returns Both an Error or string representation of the value and an error message
|
|
136
|
-
*/
|
|
137
|
-
const asErrorAndMessage = (error) =>
|
|
138
|
-
error instanceof Error ? [error, error.message] : [String(error), String(error)];
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Extracts the layer path from the route arguments
|
|
142
|
-
*
|
|
143
|
-
* @param args - Arguments of the route
|
|
144
|
-
* @returns The layer path
|
|
145
|
-
*/
|
|
146
|
-
const getLayerPath = (args) => {
|
|
147
|
-
const firstArg = args[0];
|
|
148
|
-
|
|
149
|
-
if (Array.isArray(firstArg)) {
|
|
150
|
-
return firstArg.map(arg => extractLayerPathSegment(arg) || '').join(',');
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return extractLayerPathSegment(firstArg);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const extractLayerPathSegment = (arg) => {
|
|
157
|
-
if (typeof arg === 'string') {
|
|
158
|
-
return arg;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (arg instanceof RegExp || typeof arg === 'number') {
|
|
162
|
-
return arg.toString();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export { asErrorAndMessage, getLayerMetadata, getLayerPath, getRouterPath, isLayerIgnored, storeLayerPath };
|
|
169
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../../src/integrations/tracing/express-v5/utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n\n/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { ExpressLayerType } from './enums/ExpressLayerType';\nimport type { ExpressLayer, PatchedRequest } from './internal-types';\nimport { _LAYERS_STORE_PROPERTY } from './internal-types';\nimport type { ExpressInstrumentationConfig, IgnoreMatcher, LayerPathSegment } from './types';\n\n/**\n * Store layers path in the request to be able to construct route later\n * @param request The request where\n * @param [value] the value to push into the array\n */\nexport const storeLayerPath = (request: PatchedRequest, value?: string): void => {\n if (Array.isArray(request[_LAYERS_STORE_PROPERTY]) === false) {\n Object.defineProperty(request, _LAYERS_STORE_PROPERTY, {\n enumerable: false,\n value: [],\n });\n }\n if (value === undefined) return;\n (request[_LAYERS_STORE_PROPERTY] as string[]).push(value);\n};\n\n/**\n * Recursively search the router path from layer stack\n * @param path The path to reconstruct\n * @param layer The layer to reconstruct from\n * @returns The reconstructed path\n */\nexport const getRouterPath = (path: string, layer: ExpressLayer): string => {\n const stackLayer = layer.handle?.stack?.[0];\n\n if (stackLayer?.route?.path) {\n return `${path}${stackLayer.route.path}`;\n }\n\n if (stackLayer?.handle?.stack) {\n return getRouterPath(path, stackLayer);\n }\n\n return path;\n};\n\n/**\n * Parse express layer context to retrieve a name and attributes.\n * @param route The route of the layer\n * @param layer Express layer\n * @param [layerPath] if present, the path on which the layer has been mounted\n */\nexport const getLayerMetadata = (\n route: string,\n layer: ExpressLayer,\n layerPath?: string,\n): {\n attributes: Attributes;\n name: string;\n} => {\n if (layer.name === 'router') {\n const maybeRouterPath = getRouterPath('', layer);\n const extractedRouterPath = maybeRouterPath ? maybeRouterPath : layerPath || route || '/';\n\n return {\n attributes: {\n [AttributeNames.EXPRESS_NAME]: extractedRouterPath,\n [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER,\n },\n name: `router - ${extractedRouterPath}`,\n };\n } else if (layer.name === 'bound dispatch' || layer.name === 'handle') {\n return {\n attributes: {\n [AttributeNames.EXPRESS_NAME]: (route || layerPath) ?? 'request handler',\n [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER,\n },\n name: `request handler${layer.path ? ` - ${route || layerPath}` : ''}`,\n };\n } else {\n return {\n attributes: {\n [AttributeNames.EXPRESS_NAME]: layer.name,\n [AttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE,\n },\n name: `middleware - ${layer.name}`,\n };\n }\n};\n\n/**\n * Check whether the given obj match pattern\n * @param constant e.g URL of request\n * @param obj obj to inspect\n * @param pattern Match pattern\n */\nconst satisfiesPattern = (constant: string, pattern: IgnoreMatcher): boolean => {\n if (typeof pattern === 'string') {\n return pattern === constant;\n } else if (pattern instanceof RegExp) {\n return pattern.test(constant);\n } else if (typeof pattern === 'function') {\n return pattern(constant);\n } else {\n throw new TypeError('Pattern is in unsupported datatype');\n }\n};\n\n/**\n * Check whether the given request is ignored by configuration\n * It will not re-throw exceptions from `list` provided by the client\n * @param constant e.g URL of request\n * @param [list] List of ignore patterns\n * @param [onException] callback for doing something when an exception has\n * occurred\n */\nexport const isLayerIgnored = (\n name: string,\n type: ExpressLayerType,\n config?: ExpressInstrumentationConfig,\n): boolean => {\n if (Array.isArray(config?.ignoreLayersType) && config?.ignoreLayersType?.includes(type)) {\n return true;\n }\n if (Array.isArray(config?.ignoreLayers) === false) return false;\n try {\n for (const pattern of config!.ignoreLayers!) {\n if (satisfiesPattern(name, pattern)) {\n return true;\n }\n }\n } catch {\n /* catch block */\n }\n\n return false;\n};\n\n/**\n * Converts a user-provided error value into an error and error message pair\n *\n * @param error - User-provided error value\n * @returns Both an Error or string representation of the value and an error message\n */\nexport const asErrorAndMessage = (error: unknown): [error: string | Error, message: string] =>\n error instanceof Error ? [error, error.message] : [String(error), String(error)];\n\n/**\n * Extracts the layer path from the route arguments\n *\n * @param args - Arguments of the route\n * @returns The layer path\n */\nexport const getLayerPath = (args: [LayerPathSegment | LayerPathSegment[], ...unknown[]]): string | undefined => {\n const firstArg = args[0];\n\n if (Array.isArray(firstArg)) {\n return firstArg.map(arg => extractLayerPathSegment(arg) || '').join(',');\n }\n\n return extractLayerPathSegment(firstArg);\n};\n\nconst extractLayerPathSegment = (arg: LayerPathSegment) => {\n if (typeof arg === 'string') {\n return arg;\n }\n\n if (arg instanceof RegExp || typeof arg === 'number') {\n return arg.toString();\n }\n\n return;\n};\n"],"names":[],"mappings":";;;;AA2BA;AACA;AACA;AACA;AACA;MACa,cAAA,GAAiB,CAAC,OAAO,EAAkB,KA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CAAA,QAAA,CAAA;AACA;;AAEA,MAAA,uBAAA,GAAA,CAAA,GAAA,KAAA;AACA,EAAA,IAAA,OAAA,GAAA,KAAA,QAAA,EAAA;AACA,IAAA,OAAA,GAAA;AACA;;AAEA,EAAA,IAAA,GAAA,YAAA,MAAA,IAAA,OAAA,GAAA,KAAA,QAAA,EAAA;AACA,IAAA,OAAA,GAAA,CAAA,QAAA,EAAA;AACA;;AAEA,EAAA;AACA,CAAA;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AttributeNames.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/tracing/express-v5/enums/AttributeNames.ts"],"names":[],"mappings":"AAeA,oBAAY,cAAc;IACxB,YAAY,iBAAiB;IAC7B,YAAY,iBAAiB;CAC9B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressLayerType.d.ts","sourceRoot":"","sources":["../../../../../../src/integrations/tracing/express-v5/enums/ExpressLayerType.ts"],"names":[],"mappings":"AAeA,oBAAY,gBAAgB;IAC1B,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,eAAe,oBAAoB;CACpC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
|
-
import type { ExpressInstrumentationConfig, ExpressRequestInfo } from './types';
|
|
3
|
-
export declare const PACKAGE_VERSION = "0.1.0";
|
|
4
|
-
export declare const PACKAGE_NAME = "@sentry/instrumentation-express-v5";
|
|
5
|
-
/** Express instrumentation for OpenTelemetry */
|
|
6
|
-
export declare class ExpressInstrumentationV5 extends InstrumentationBase<ExpressInstrumentationConfig> {
|
|
7
|
-
constructor(config?: ExpressInstrumentationConfig);
|
|
8
|
-
init(): InstrumentationNodeModuleDefinition[];
|
|
9
|
-
private _setup;
|
|
10
|
-
private _tearDown;
|
|
11
|
-
/**
|
|
12
|
-
* Get the patch for Router.route function
|
|
13
|
-
*/
|
|
14
|
-
private _getRoutePatch;
|
|
15
|
-
/**
|
|
16
|
-
* Get the patch for Router.use function
|
|
17
|
-
*/
|
|
18
|
-
private _getRouterUsePatch;
|
|
19
|
-
/**
|
|
20
|
-
* Get the patch for Application.use function
|
|
21
|
-
*/
|
|
22
|
-
private _getAppUsePatch;
|
|
23
|
-
/** Patch each express layer to create span and propagate context */
|
|
24
|
-
private _applyPatch;
|
|
25
|
-
_getSpanName(info: ExpressRequestInfo, defaultName: string): string;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/tracing/express-v5/instrumentation.ts"],"names":[],"mappings":"AA8BA,OAAO,EACL,mBAAmB,EACnB,mCAAmC,EAGpC,MAAM,gCAAgC,CAAC;AAOxC,OAAO,KAAK,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGhF,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,YAAY,uCAAuC,CAAC;AAEjE,gDAAgD;AAChD,qBAAa,wBAAyB,SAAQ,mBAAmB,CAAC,4BAA4B,CAAC;gBACjF,MAAM,GAAE,4BAAiC;IAIrD,IAAI;IAWJ,OAAO,CAAC,MAAM;IAoBd,OAAO,CAAC,SAAS;IAQjB;;OAEG;IACH,OAAO,CAAC,cAAc;IAYtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACH,OAAO,CAAC,eAAe;IAqBvB,oEAAoE;IACpE,OAAO,CAAC,WAAW;IAmKnB,YAAY,CAAC,IAAI,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM;CAc3D"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Request } from 'express';
|
|
2
|
-
/**
|
|
3
|
-
* This symbol is used to mark express layer as being already instrumented
|
|
4
|
-
* since its possible to use a given layer multiple times (ex: middlewares)
|
|
5
|
-
*/
|
|
6
|
-
export declare const kLayerPatched: unique symbol;
|
|
7
|
-
/**
|
|
8
|
-
* This const define where on the `request` object the Instrumentation will mount the
|
|
9
|
-
* current stack of express layer.
|
|
10
|
-
*
|
|
11
|
-
* It is necessary because express doesn't store the different layers
|
|
12
|
-
* (ie: middleware, router etc) that it called to get to the current layer.
|
|
13
|
-
* Given that, the only way to know the route of a given layer is to
|
|
14
|
-
* store the path of where each previous layer has been mounted.
|
|
15
|
-
*
|
|
16
|
-
* ex: bodyParser > auth middleware > /users router > get /:id
|
|
17
|
-
* in this case the stack would be: ["/users", "/:id"]
|
|
18
|
-
*
|
|
19
|
-
* ex2: bodyParser > /api router > /v1 router > /users router > get /:id
|
|
20
|
-
* stack: ["/api", "/v1", "/users", ":id"]
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
export declare const _LAYERS_STORE_PROPERTY = "__ot_middlewares";
|
|
24
|
-
export type PatchedRequest = {
|
|
25
|
-
[_LAYERS_STORE_PROPERTY]?: string[];
|
|
26
|
-
} & Request;
|
|
27
|
-
export type PathParams = string | RegExp | Array<string | RegExp>;
|
|
28
|
-
export type ExpressRouter = {
|
|
29
|
-
stack: ExpressLayer[];
|
|
30
|
-
};
|
|
31
|
-
export type ExpressLayer = {
|
|
32
|
-
handle: Function & Record<string, any>;
|
|
33
|
-
[kLayerPatched]?: boolean;
|
|
34
|
-
name: string;
|
|
35
|
-
path: string;
|
|
36
|
-
route?: ExpressLayer;
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=internal-types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal-types.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/tracing/express-v5/internal-types.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,OAAO,MAAwC,CAAC;AAE5E;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,GAAG,OAAO,CAAC;AACZ,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAGlE,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,YAAY,EAAE,CAAC;CACvB,CAAC;AAGF,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Span } from '@opentelemetry/api';
|
|
2
|
-
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
|
|
3
|
-
import type { ExpressLayerType } from './enums/ExpressLayerType';
|
|
4
|
-
export type LayerPathSegment = string | RegExp | number;
|
|
5
|
-
export type IgnoreMatcher = string | RegExp | ((name: string) => boolean);
|
|
6
|
-
export type ExpressRequestInfo<T = any> = {
|
|
7
|
-
/** An express request object */
|
|
8
|
-
request: T;
|
|
9
|
-
route: string;
|
|
10
|
-
layerType: ExpressLayerType;
|
|
11
|
-
};
|
|
12
|
-
export type SpanNameHook = (info: ExpressRequestInfo,
|
|
13
|
-
/**
|
|
14
|
-
* If no decision is taken based on RequestInfo, the default name
|
|
15
|
-
* supplied by the instrumentation can be used instead.
|
|
16
|
-
*/
|
|
17
|
-
defaultName: string) => string;
|
|
18
|
-
/**
|
|
19
|
-
* Function that can be used to add custom attributes to the current span or the root span on
|
|
20
|
-
* a Express request
|
|
21
|
-
* @param span - The Express middleware layer span.
|
|
22
|
-
* @param info - An instance of ExpressRequestInfo that contains info about the request such as the route, and the layer type.
|
|
23
|
-
*/
|
|
24
|
-
export interface ExpressRequestCustomAttributeFunction {
|
|
25
|
-
(span: Span, info: ExpressRequestInfo): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Options available for the Express Instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#express-instrumentation-options))
|
|
29
|
-
*/
|
|
30
|
-
export interface ExpressInstrumentationConfig extends InstrumentationConfig {
|
|
31
|
-
/** Ignore specific based on their name */
|
|
32
|
-
ignoreLayers?: IgnoreMatcher[];
|
|
33
|
-
/** Ignore specific layers based on their type */
|
|
34
|
-
ignoreLayersType?: ExpressLayerType[];
|
|
35
|
-
spanNameHook?: SpanNameHook;
|
|
36
|
-
/** Function for adding custom attributes on Express request */
|
|
37
|
-
requestHook?: ExpressRequestCustomAttributeFunction;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/tracing/express-v5/types.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAExD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;AAE1E,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI;IACxC,gCAAgC;IAChC,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,gBAAgB,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,CACzB,IAAI,EAAE,kBAAkB;AACxB;;;GAGG;AACH,WAAW,EAAE,MAAM,KAChB,MAAM,CAAC;AAEZ;;;;;GAKG;AACH,MAAM,WAAW,qCAAqC;IACpD,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,qBAAqB;IACzE,0CAA0C;IAC1C,YAAY,CAAC,EAAE,aAAa,EAAE,CAAC;IAC/B,iDAAiD;IACjD,gBAAgB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACtC,YAAY,CAAC,EAAE,YAAY,CAAC;IAE5B,+DAA+D;IAC/D,WAAW,CAAC,EAAE,qCAAqC,CAAC;CACrD"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { Attributes } from '@opentelemetry/api';
|
|
2
|
-
import { ExpressLayerType } from './enums/ExpressLayerType';
|
|
3
|
-
import type { ExpressLayer, PatchedRequest } from './internal-types';
|
|
4
|
-
import type { ExpressInstrumentationConfig, LayerPathSegment } from './types';
|
|
5
|
-
/**
|
|
6
|
-
* Store layers path in the request to be able to construct route later
|
|
7
|
-
* @param request The request where
|
|
8
|
-
* @param [value] the value to push into the array
|
|
9
|
-
*/
|
|
10
|
-
export declare const storeLayerPath: (request: PatchedRequest, value?: string) => void;
|
|
11
|
-
/**
|
|
12
|
-
* Recursively search the router path from layer stack
|
|
13
|
-
* @param path The path to reconstruct
|
|
14
|
-
* @param layer The layer to reconstruct from
|
|
15
|
-
* @returns The reconstructed path
|
|
16
|
-
*/
|
|
17
|
-
export declare const getRouterPath: (path: string, layer: ExpressLayer) => string;
|
|
18
|
-
/**
|
|
19
|
-
* Parse express layer context to retrieve a name and attributes.
|
|
20
|
-
* @param route The route of the layer
|
|
21
|
-
* @param layer Express layer
|
|
22
|
-
* @param [layerPath] if present, the path on which the layer has been mounted
|
|
23
|
-
*/
|
|
24
|
-
export declare const getLayerMetadata: (route: string, layer: ExpressLayer, layerPath?: string) => {
|
|
25
|
-
attributes: Attributes;
|
|
26
|
-
name: string;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Check whether the given request is ignored by configuration
|
|
30
|
-
* It will not re-throw exceptions from `list` provided by the client
|
|
31
|
-
* @param constant e.g URL of request
|
|
32
|
-
* @param [list] List of ignore patterns
|
|
33
|
-
* @param [onException] callback for doing something when an exception has
|
|
34
|
-
* occurred
|
|
35
|
-
*/
|
|
36
|
-
export declare const isLayerIgnored: (name: string, type: ExpressLayerType, config?: ExpressInstrumentationConfig) => boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Converts a user-provided error value into an error and error message pair
|
|
39
|
-
*
|
|
40
|
-
* @param error - User-provided error value
|
|
41
|
-
* @returns Both an Error or string representation of the value and an error message
|
|
42
|
-
*/
|
|
43
|
-
export declare const asErrorAndMessage: (error: unknown) => [error: string | Error, message: string];
|
|
44
|
-
/**
|
|
45
|
-
* Extracts the layer path from the route arguments
|
|
46
|
-
*
|
|
47
|
-
* @param args - Arguments of the route
|
|
48
|
-
* @returns The layer path
|
|
49
|
-
*/
|
|
50
|
-
export declare const getLayerPath: (args: [LayerPathSegment | LayerPathSegment[], ...unknown[]]) => string | undefined;
|
|
51
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/integrations/tracing/express-v5/utils.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,KAAK,EAAE,4BAA4B,EAAiB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE7F;;;;GAIG;AACH,eAAO,MAAM,cAAc,YAAa,cAAc,UAAU,MAAM,KAAG,IASxE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,SAAU,MAAM,SAAS,YAAY,KAAG,MAYjE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,UACpB,MAAM,SACN,YAAY,cACP,MAAM,KACjB;IACD,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,MAAM,CAAC;CA8Bd,CAAC;AAoBF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,SACnB,MAAM,QACN,gBAAgB,WACb,4BAA4B,KACpC,OAgBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,UAAW,OAAO,6CACkC,CAAC;AAEnF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,SAAU,CAAC,gBAAgB,GAAG,gBAAgB,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,KAAG,MAAM,GAAG,SAQnG,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
|
|
2
|
-
import { ExpressInstrumentationConfig, ExpressRequestInfo } from './types';
|
|
3
|
-
export declare const PACKAGE_VERSION = "0.1.0";
|
|
4
|
-
export declare const PACKAGE_NAME = "@sentry/instrumentation-express-v5";
|
|
5
|
-
/** Express instrumentation for OpenTelemetry */
|
|
6
|
-
export declare class ExpressInstrumentationV5 extends InstrumentationBase<ExpressInstrumentationConfig> {
|
|
7
|
-
constructor(config?: ExpressInstrumentationConfig);
|
|
8
|
-
init(): InstrumentationNodeModuleDefinition[];
|
|
9
|
-
private _setup;
|
|
10
|
-
private _tearDown;
|
|
11
|
-
/**
|
|
12
|
-
* Get the patch for Router.route function
|
|
13
|
-
*/
|
|
14
|
-
private _getRoutePatch;
|
|
15
|
-
/**
|
|
16
|
-
* Get the patch for Router.use function
|
|
17
|
-
*/
|
|
18
|
-
private _getRouterUsePatch;
|
|
19
|
-
/**
|
|
20
|
-
* Get the patch for Application.use function
|
|
21
|
-
*/
|
|
22
|
-
private _getAppUsePatch;
|
|
23
|
-
/** Patch each express layer to create span and propagate context */
|
|
24
|
-
private _applyPatch;
|
|
25
|
-
_getSpanName(info: ExpressRequestInfo, defaultName: string): string;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Request } from 'express';
|
|
2
|
-
/**
|
|
3
|
-
* This symbol is used to mark express layer as being already instrumented
|
|
4
|
-
* since its possible to use a given layer multiple times (ex: middlewares)
|
|
5
|
-
*/
|
|
6
|
-
export declare const kLayerPatched: unique symbol;
|
|
7
|
-
/**
|
|
8
|
-
* This const define where on the `request` object the Instrumentation will mount the
|
|
9
|
-
* current stack of express layer.
|
|
10
|
-
*
|
|
11
|
-
* It is necessary because express doesn't store the different layers
|
|
12
|
-
* (ie: middleware, router etc) that it called to get to the current layer.
|
|
13
|
-
* Given that, the only way to know the route of a given layer is to
|
|
14
|
-
* store the path of where each previous layer has been mounted.
|
|
15
|
-
*
|
|
16
|
-
* ex: bodyParser > auth middleware > /users router > get /:id
|
|
17
|
-
* in this case the stack would be: ["/users", "/:id"]
|
|
18
|
-
*
|
|
19
|
-
* ex2: bodyParser > /api router > /v1 router > /users router > get /:id
|
|
20
|
-
* stack: ["/api", "/v1", "/users", ":id"]
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
export declare const _LAYERS_STORE_PROPERTY = "__ot_middlewares";
|
|
24
|
-
export type PatchedRequest = {
|
|
25
|
-
[_LAYERS_STORE_PROPERTY]?: string[];
|
|
26
|
-
} & Request;
|
|
27
|
-
export type PathParams = string | RegExp | Array<string | RegExp>;
|
|
28
|
-
export type ExpressRouter = {
|
|
29
|
-
stack: ExpressLayer[];
|
|
30
|
-
};
|
|
31
|
-
export type ExpressLayer = {
|
|
32
|
-
handle: Function & Record<string, any>;
|
|
33
|
-
[kLayerPatched]?: boolean;
|
|
34
|
-
name: string;
|
|
35
|
-
path: string;
|
|
36
|
-
route?: ExpressLayer;
|
|
37
|
-
};
|
|
38
|
-
//# sourceMappingURL=internal-types.d.ts.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Span } from '@opentelemetry/api';
|
|
2
|
-
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
|
|
3
|
-
import { ExpressLayerType } from './enums/ExpressLayerType';
|
|
4
|
-
export type LayerPathSegment = string | RegExp | number;
|
|
5
|
-
export type IgnoreMatcher = string | RegExp | ((name: string) => boolean);
|
|
6
|
-
export type ExpressRequestInfo<T = any> = {
|
|
7
|
-
/** An express request object */
|
|
8
|
-
request: T;
|
|
9
|
-
route: string;
|
|
10
|
-
layerType: ExpressLayerType;
|
|
11
|
-
};
|
|
12
|
-
export type SpanNameHook = (info: ExpressRequestInfo,
|
|
13
|
-
/**
|
|
14
|
-
* If no decision is taken based on RequestInfo, the default name
|
|
15
|
-
* supplied by the instrumentation can be used instead.
|
|
16
|
-
*/
|
|
17
|
-
defaultName: string) => string;
|
|
18
|
-
/**
|
|
19
|
-
* Function that can be used to add custom attributes to the current span or the root span on
|
|
20
|
-
* a Express request
|
|
21
|
-
* @param span - The Express middleware layer span.
|
|
22
|
-
* @param info - An instance of ExpressRequestInfo that contains info about the request such as the route, and the layer type.
|
|
23
|
-
*/
|
|
24
|
-
export interface ExpressRequestCustomAttributeFunction {
|
|
25
|
-
(span: Span, info: ExpressRequestInfo): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Options available for the Express Instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express#express-instrumentation-options))
|
|
29
|
-
*/
|
|
30
|
-
export interface ExpressInstrumentationConfig extends InstrumentationConfig {
|
|
31
|
-
/** Ignore specific based on their name */
|
|
32
|
-
ignoreLayers?: IgnoreMatcher[];
|
|
33
|
-
/** Ignore specific layers based on their type */
|
|
34
|
-
ignoreLayersType?: ExpressLayerType[];
|
|
35
|
-
spanNameHook?: SpanNameHook;
|
|
36
|
-
/** Function for adding custom attributes on Express request */
|
|
37
|
-
requestHook?: ExpressRequestCustomAttributeFunction;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=types.d.ts.map
|