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AA,cAAc,kBAQzB","sourcesContent":["/*\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 */\nimport { KoaLayerType, KoaInstrumentationConfig } from './types';\nimport { KoaContext, KoaMiddleware } from './internal-types';\nimport { AttributeNames } from './enums/AttributeNames';\nimport { Attributes } from '@opentelemetry/api';\nimport { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';\n\nexport const getMiddlewareMetadata = (\n context: KoaContext,\n layer: KoaMiddleware,\n isRouter: boolean,\n layerPath?: string | RegExp\n): {\n attributes: Attributes;\n name: string;\n} => {\n if (isRouter) {\n return {\n attributes: {\n [AttributeNames.KOA_NAME]: layerPath?.toString(),\n [AttributeNames.KOA_TYPE]: KoaLayerType.ROUTER,\n [SEMATTRS_HTTP_ROUTE]: layerPath?.toString(),\n },\n name: context._matchedRouteName || `router - ${layerPath}`,\n };\n } else {\n return {\n attributes: {\n [AttributeNames.KOA_NAME]: layer.name ?? 'middleware',\n [AttributeNames.KOA_TYPE]: KoaLayerType.MIDDLEWARE,\n },\n name: `middleware - ${layer.name}`,\n };\n }\n};\n\n/**\n * Check whether the given request is ignored by configuration\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 type: KoaLayerType,\n config?: KoaInstrumentationConfig\n): boolean => {\n return !!(\n Array.isArray(config?.ignoreLayersType) &&\n config?.ignoreLayersType?.includes(type)\n );\n};\n"]}