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,gEAwCC","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 */\n\nimport { context } from '@opentelemetry/api';\nimport {\n InstrumentationBase,\n InstrumentationConfig,\n InstrumentationNodeModuleDefinition,\n} from '@opentelemetry/instrumentation';\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nexport class LruMemoizerInstrumentation extends InstrumentationBase {\n constructor(config: InstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n init(): InstrumentationNodeModuleDefinition[] {\n return [\n new InstrumentationNodeModuleDefinition(\n 'lru-memoizer',\n ['>=1.3 <3'],\n moduleExports => {\n // moduleExports is a function which receives an options object,\n // and returns a \"memoizer\" function upon invocation.\n // We want to patch this \"memoizer's\" internal function\n const asyncMemoizer = function (this: unknown) {\n // This following function is invoked every time the user wants to get a (possible) memoized value\n // We replace it with another function in which we bind the current context to the last argument (callback)\n const origMemoizer = moduleExports.apply(this, arguments);\n return function (this: unknown) {\n const modifiedArguments = [...arguments];\n // last argument is the callback\n const origCallback = modifiedArguments.pop();\n const callbackWithContext =\n typeof origCallback === 'function'\n ? context.bind(context.active(), origCallback)\n : origCallback;\n modifiedArguments.push(callbackWithContext);\n return origMemoizer.apply(this, modifiedArguments);\n };\n };\n\n // sync function preserves context, but we still need to export it\n // as the lru-memoizer package does\n asyncMemoizer.sync = moduleExports.sync;\n return asyncMemoizer;\n },\n undefined // no need to disable as this instrumentation does not create any spans\n ),\n ];\n }\n}\n"]}