@opentelemetry/instrumentation-koa
Version:
OpenTelemetry instrumentation for `koa` http web application framework
44 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isLayerIgnored = exports.getMiddlewareMetadata = void 0;
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
const types_1 = require("./types");
const AttributeNames_1 = require("./enums/AttributeNames");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const getMiddlewareMetadata = (context, layer, isRouter, layerPath) => {
if (isRouter) {
return {
attributes: {
[AttributeNames_1.AttributeNames.KOA_NAME]: layerPath?.toString(),
[AttributeNames_1.AttributeNames.KOA_TYPE]: types_1.KoaLayerType.ROUTER,
[semantic_conventions_1.ATTR_HTTP_ROUTE]: layerPath?.toString(),
},
name: context._matchedRouteName || `router - ${layerPath}`,
};
}
else {
return {
attributes: {
[AttributeNames_1.AttributeNames.KOA_NAME]: layer.name ?? 'middleware',
[AttributeNames_1.AttributeNames.KOA_TYPE]: types_1.KoaLayerType.MIDDLEWARE,
},
name: `middleware - ${layer.name}`,
};
}
};
exports.getMiddlewareMetadata = getMiddlewareMetadata;
/**
* Check whether the given request is ignored by configuration
* @param [list] List of ignore patterns
* @param [onException] callback for doing something when an exception has
* occurred
*/
const isLayerIgnored = (type, config) => {
return !!(Array.isArray(config?.ignoreLayersType) &&
config?.ignoreLayersType?.includes(type));
};
exports.isLayerIgnored = isLayerIgnored;
//# sourceMappingURL=utils.js.map