opentelemetry-instrumentation-express
Advanced tools
Comparing version 0.40.0 to 0.41.0
import { ExpressInstrumentationConfig } from './types'; | ||
import { InstrumentationBase, InstrumentationModuleDefinition } from '@opentelemetry/instrumentation'; | ||
import type express from 'express'; | ||
export declare class ExpressInstrumentation extends InstrumentationBase<typeof express> { | ||
export declare class ExpressInstrumentation extends InstrumentationBase { | ||
static readonly supportedVersions: string[]; | ||
@@ -9,3 +9,3 @@ protected _config: ExpressInstrumentationConfig; | ||
setConfig(config?: ExpressInstrumentationConfig): void; | ||
protected init(): InstrumentationModuleDefinition<typeof express>; | ||
protected init(): InstrumentationModuleDefinition; | ||
protected patch(moduleExports: typeof express, moduleVersion?: string): typeof express; | ||
@@ -12,0 +12,0 @@ protected unpatch(moduleExports: typeof express): void; |
@@ -33,3 +33,3 @@ "use strict"; | ||
const application = moduleExports === null || moduleExports === void 0 ? void 0 : moduleExports.application; | ||
if (instrumentation_1.isWrapped(application === null || application === void 0 ? void 0 : application.lazyrouter)) { | ||
if ((0, instrumentation_1.isWrapped)(application === null || application === void 0 ? void 0 : application.lazyrouter)) { | ||
this._unwrap(application, 'lazyrouter'); | ||
@@ -59,3 +59,3 @@ } | ||
} | ||
this[types_1.PATH_STORE] = layer_path_1.getLayerPathFromFirstArg(path, options !== null && options !== void 0 ? options : {}); | ||
this[types_1.PATH_STORE] = (0, layer_path_1.getLayerPathFromFirstArg)(path, options !== null && options !== void 0 ? options : {}); | ||
return origLayerConstructor.call(this, path, options, fn); | ||
@@ -71,6 +71,6 @@ } | ||
const originalLayerExport = (_a = moduleExports[originalLayerStore]) !== null && _a !== void 0 ? _a : moduleExports; | ||
if (instrumentation_1.isWrapped(originalLayerExport.prototype.handle_request)) { | ||
if ((0, instrumentation_1.isWrapped)(originalLayerExport.prototype.handle_request)) { | ||
this._unwrap(originalLayerExport.prototype, 'handle_request'); | ||
} | ||
if (instrumentation_1.isWrapped(originalLayerExport.prototype.handle_error)) { | ||
if ((0, instrumentation_1.isWrapped)(originalLayerExport.prototype.handle_error)) { | ||
this._unwrap(originalLayerExport.prototype, 'handle_error'); | ||
@@ -141,9 +141,9 @@ } | ||
} | ||
const spanName = attributes_1.getSpanInitialName(req); | ||
const spanName = (0, attributes_1.getSpanInitialName)(req); | ||
const span = plugin.tracer.startSpan(spanName, { | ||
kind: api_1.SpanKind.INTERNAL, | ||
attributes: plugin._config.includeHttpAttributes ? attributes_1.getHttpSpanAttributesFromReq(req) : {}, | ||
attributes: plugin._config.includeHttpAttributes ? (0, attributes_1.getHttpSpanAttributesFromReq)(req) : {}, | ||
}); | ||
if (plugin._config.requestHook) { | ||
instrumentation_1.safeExecuteInTheMiddle(() => plugin._config.requestHook(span, { moduleVersion, req, res }), (e) => { | ||
(0, instrumentation_1.safeExecuteInTheMiddle)(() => plugin._config.requestHook(span, { moduleVersion, req, res }), (e) => { | ||
if (e) | ||
@@ -160,6 +160,6 @@ api_1.diag.error(`opentelemetry.express instrumentation: requestHook error`, e); | ||
const routeState = plugin.getCurrentRouteState(req); | ||
const routeAttributes = attributes_1.getRouteAttributes(routeState); | ||
const route = routeAttributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE]; | ||
const routeAttributes = (0, attributes_1.getRouteAttributes)(routeState); | ||
const route = routeAttributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE]; | ||
if (route) { | ||
const rpcMetadata = core_1.getRPCMetadata(api_1.context.active()); | ||
const rpcMetadata = (0, core_1.getRPCMetadata)(api_1.context.active()); | ||
if (rpcMetadata) { | ||
@@ -172,6 +172,6 @@ rpcMetadata.route = route; | ||
if (plugin._config.includeHttpAttributes) { | ||
span.setAttributes(attributes_1.getHttpSpanAttributeFromRes(res)); | ||
span.setAttributes((0, attributes_1.getHttpSpanAttributeFromRes)(res)); | ||
} | ||
span.setStatus(attributes_1.parseResponseStatus(res.statusCode)); | ||
const newSpanName = attributes_1.getSpanNameOnResEnd(req, routeState); | ||
span.setStatus((0, attributes_1.parseResponseStatus)(res.statusCode)); | ||
const newSpanName = (0, attributes_1.getSpanNameOnResEnd)(req, routeState); | ||
if (newSpanName) { | ||
@@ -190,3 +190,3 @@ span.updateName(newSpanName); | ||
const origRes = original.apply(this, arguments); | ||
if (!instrumentation_1.isWrapped(this._router.handle)) { | ||
if (!(0, instrumentation_1.isWrapped)(this._router.handle)) { | ||
self._wrap(this._router, 'handle', self.getAppRouterHandlerPatch.bind(self)); | ||
@@ -207,3 +207,3 @@ self.registerInstrumentationMiddleware(this, moduleVersion); | ||
} | ||
const initialState = route_context_1.createInitialRouteState(req); | ||
const initialState = (0, route_context_1.createInitialRouteState)(req); | ||
const patchedNext = function (err) { | ||
@@ -227,3 +227,3 @@ return self.runMiddlewareWithContext(Object.assign(Object.assign({}, initialState), { isUnhandled: true }), req, () => next(err)); | ||
const currentLayerPath = layer[types_1.PATH_STORE]; | ||
const newExpressRouteState = route_context_1.consumeLayerPathAndUpdateState(currentState, req, currentLayerPath); | ||
const newExpressRouteState = (0, route_context_1.consumeLayerPathAndUpdateState)(currentState, req, currentLayerPath); | ||
return { origState: currentState, newState: newExpressRouteState }; | ||
@@ -230,0 +230,0 @@ } |
@@ -20,3 +20,3 @@ import { Span } from '@opentelemetry/api'; | ||
}; | ||
export declare type LayerPathAlternative = { | ||
export type LayerPathAlternative = { | ||
userSuppliedValue: string | RegExp; | ||
@@ -26,3 +26,3 @@ displayValue: string; | ||
}; | ||
export declare type LayerPath = { | ||
export type LayerPath = { | ||
fastSlash: boolean; | ||
@@ -40,4 +40,4 @@ alternatives: LayerPathAlternative | LayerPathAlternative[]; | ||
} | ||
export declare type Parameters<T> = T extends (...args: infer T) => any ? T : unknown[]; | ||
export declare type PatchedRequest = { | ||
export type Parameters<T> = T extends (...args: infer T) => any ? T : unknown[]; | ||
export type PatchedRequest = { | ||
[REQ_SPAN]?: Span; | ||
@@ -47,4 +47,4 @@ [CONSUMED_ROUTE_STATE]?: ExpressConsumedRouteState; | ||
} & express.Request; | ||
export declare type PathParams = string | RegExp | Array<string | RegExp>; | ||
export declare type ExpressRouter = { | ||
export type PathParams = string | RegExp | Array<string | RegExp>; | ||
export type ExpressRouter = { | ||
params: { | ||
@@ -59,3 +59,3 @@ [key: string]: string; | ||
}; | ||
export declare type ExpressLayer = { | ||
export type ExpressLayer = { | ||
prototype: { | ||
@@ -79,3 +79,3 @@ handle_error: express.ErrorRequestHandler; | ||
} | ||
export declare type RequestHook = (span: Span, requestInfo: ExpressRequestHookInformation) => void; | ||
export type RequestHook = (span: Span, requestInfo: ExpressRequestHookInformation) => void; | ||
export interface ExpressInstrumentationConfig extends InstrumentationConfig { | ||
@@ -82,0 +82,0 @@ /** Hook for adding custom attributes before express start handling the request */ |
@@ -9,7 +9,7 @@ "use strict"; | ||
const attributes = {}; | ||
const resolvedRoute = exports.getResolvedRoute(routeState); | ||
const resolvedRoute = (0, exports.getResolvedRoute)(routeState); | ||
if (resolvedRoute != null) { | ||
attributes[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE] = resolvedRoute; | ||
attributes[semantic_conventions_1.SEMATTRS_HTTP_ROUTE] = resolvedRoute; | ||
} | ||
const fullRoute = exports.getFullRoute(routeState); | ||
const fullRoute = (0, exports.getFullRoute)(routeState); | ||
if (fullRoute) { | ||
@@ -51,3 +51,3 @@ attributes[types_1.ExpressInstrumentationAttributes.EXPRESS_ROUTE_FULL] = fullRoute; | ||
return { | ||
[semantic_conventions_1.SemanticAttributes.HTTP_STATUS_CODE]: res.statusCode, | ||
[semantic_conventions_1.SEMATTRS_HTTP_STATUS_CODE]: res.statusCode, | ||
}; | ||
@@ -60,3 +60,3 @@ }; | ||
const method = (_a = req === null || req === void 0 ? void 0 : req.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(); | ||
const route = exports.getResolvedRoute(routeState); | ||
const route = (0, exports.getResolvedRoute)(routeState); | ||
if (!method || !route) | ||
@@ -85,8 +85,8 @@ return undefined; | ||
return { | ||
[semantic_conventions_1.SemanticAttributes.HTTP_METHOD]: req.method.toUpperCase(), | ||
[semantic_conventions_1.SemanticAttributes.HTTP_TARGET]: req.originalUrl, | ||
[semantic_conventions_1.SemanticAttributes.HTTP_FLAVOR]: req.httpVersion, | ||
[semantic_conventions_1.SemanticAttributes.HTTP_HOST]: exports.createHostAttribute(req), | ||
[semantic_conventions_1.SemanticAttributes.HTTP_SCHEME]: req.protocol, | ||
[semantic_conventions_1.SemanticAttributes.NET_PEER_IP]: req.ip, | ||
[semantic_conventions_1.SEMATTRS_HTTP_METHOD]: req.method.toUpperCase(), | ||
[semantic_conventions_1.SEMATTRS_HTTP_TARGET]: req.originalUrl, | ||
[semantic_conventions_1.SEMATTRS_HTTP_FLAVOR]: req.httpVersion, | ||
[semantic_conventions_1.SEMATTRS_HTTP_HOST]: (0, exports.createHostAttribute)(req), | ||
[semantic_conventions_1.SEMATTRS_HTTP_SCHEME]: req.protocol, | ||
[semantic_conventions_1.SEMATTRS_NET_PEER_IP]: req.ip, | ||
}; | ||
@@ -93,0 +93,0 @@ }; |
@@ -21,3 +21,3 @@ "use strict"; | ||
displayValue: pathStringToDisplayValue(pathInput, options), | ||
regexp: path_to_regexp_1.default(pathInput, [], options), | ||
regexp: (0, path_to_regexp_1.default)(pathInput, [], options), | ||
}; | ||
@@ -29,3 +29,3 @@ } | ||
displayValue: pathInput.toString(), | ||
regexp: path_to_regexp_1.default(pathInput, [], options), | ||
regexp: (0, path_to_regexp_1.default)(pathInput, [], options), | ||
}; | ||
@@ -40,3 +40,3 @@ if (Array.isArray(pathInput)) { | ||
: undefined, | ||
regexp: path_to_regexp_1.default(alternativePath, [], options), | ||
regexp: (0, path_to_regexp_1.default)(alternativePath, [], options), | ||
})); | ||
@@ -43,0 +43,0 @@ } |
@@ -34,3 +34,3 @@ "use strict"; | ||
const currentReqPath = req.path; | ||
const { resolvedPath, error: resolvedPathError } = exports.getUsedPathFromLayerPath(currentLayerPath, currentParts.remainingRoute); | ||
const { resolvedPath, error: resolvedPathError } = (0, exports.getUsedPathFromLayerPath)(currentLayerPath, currentParts.remainingRoute); | ||
if (resolvedPathError) { | ||
@@ -62,3 +62,3 @@ return { | ||
// we use parseurl(req).pathname which is exactly what express is doing | ||
const path = parseurl_1.default(req).pathname; | ||
const path = (0, parseurl_1.default)(req).pathname; | ||
return { resolvedRoute: '', remainingRoute: path, configuredRoute: '', params: {} }; | ||
@@ -65,0 +65,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.40.0"; | ||
export declare const VERSION = "0.41.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// this is autogenerated file, see scripts/version-update.js | ||
exports.VERSION = '0.40.0'; | ||
exports.VERSION = '0.41.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "opentelemetry-instrumentation-express", | ||
"version": "0.40.0", | ||
"version": "0.41.0", | ||
"description": "enhanced open telemetry instrumentation for the `express` web framework", | ||
@@ -35,8 +35,8 @@ "author": "Aspecto.io", | ||
"peerDependencies": { | ||
"@opentelemetry/api": "^1.6.0" | ||
"@opentelemetry/api": "^1.8.0" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/core": "^1.17.1", | ||
"@opentelemetry/instrumentation": "^0.44.0", | ||
"@opentelemetry/semantic-conventions": "^1.17.1", | ||
"@opentelemetry/core": "^1.24.1", | ||
"@opentelemetry/instrumentation": "^0.51.1", | ||
"@opentelemetry/semantic-conventions": "^1.24.1", | ||
"parseurl": "~1.3.3", | ||
@@ -46,8 +46,9 @@ "path-to-regexp": "0.1.7" | ||
"devDependencies": { | ||
"@opentelemetry/api": "^1.6.0", | ||
"@opentelemetry/contrib-test-utils": "^0.34.2", | ||
"@opentelemetry/api": "^1.8.0", | ||
"@opentelemetry/contrib-test-utils": "^0.39.0", | ||
"@opentelemetry/instrumentation-http": "^0.44.0", | ||
"@opentelemetry/sdk-trace-base": "^1.17.1", | ||
"@opentelemetry/sdk-trace-base": "^1.24.1", | ||
"@types/express": "4.17.8", | ||
"@types/mocha": "^8.2.2", | ||
"aspecto-opentelemetry-instrumentation-mocha": "0.0.9-alpha.0", | ||
"axios": "0.21.1", | ||
@@ -58,6 +59,5 @@ "body-parser": "^1.19.0", | ||
"mocha": "^8.4.0", | ||
"opentelemetry-instrumentation-mocha": "0.0.7-alpha.1", | ||
"test-all-versions": "^5.0.1", | ||
"ts-node": "^9.1.1", | ||
"typescript": "4.3.4" | ||
"ts-node": "^10.9.2", | ||
"typescript": "5.4.5" | ||
}, | ||
@@ -71,6 +71,6 @@ "mocha": { | ||
"ts-node/register", | ||
"opentelemetry-instrumentation-mocha" | ||
"aspecto-opentelemetry-instrumentation-mocha" | ||
] | ||
}, | ||
"gitHead": "3be217b8c6c8a6ae41486c51453781732c2c3ea3" | ||
"gitHead": "6fd75bf4b1355485542c31e4f9322d70af8fe27d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
96930
24
+ Added@opentelemetry/api-logs@0.51.1(transitive)
+ Added@opentelemetry/instrumentation@0.51.1(transitive)
+ Addedacorn-import-attributes@1.9.5(transitive)
+ Addedimport-in-the-middle@1.7.4(transitive)
- Removed@opentelemetry/instrumentation@0.44.0(transitive)
- Removedacorn-import-assertions@1.9.0(transitive)
- Removedimport-in-the-middle@1.4.2(transitive)
Updated@opentelemetry/core@^1.24.1