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1aD,8CA0aC","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 * as api from '@opentelemetry/api';\nimport { isTracingSuppressed, suppressTracing } from '@opentelemetry/core';\nimport {\n InstrumentationBase,\n InstrumentationNodeModuleDefinition,\n isWrapped,\n} from '@opentelemetry/instrumentation';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\nimport {\n CALLBACK_FUNCTIONS,\n PROMISE_FUNCTIONS,\n SYNC_FUNCTIONS,\n} from './constants';\nimport type * as fs from 'fs';\nimport type {\n FMember,\n FPMember,\n CreateHook,\n EndHook,\n FsInstrumentationConfig,\n} from './types';\nimport { promisify } from 'util';\nimport { indexFs } from './utils';\n\ntype FS = typeof fs;\ntype FSPromises = (typeof fs)['promises'];\n\n/**\n * This is important for 2-level functions like `realpath.native` to retain the 2nd-level\n * when patching the 1st-level.\n */\nfunction patchedFunctionWithOriginalProperties<\n T extends (...args: any[]) => ReturnType\n>(patchedFunction: T, original: T): T {\n return Object.assign(patchedFunction, original);\n}\n\nexport class FsInstrumentation extends InstrumentationBase {\n constructor(config: FsInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n init(): (\n | InstrumentationNodeModuleDefinition\n | InstrumentationNodeModuleDefinition\n )[] {\n return [\n new InstrumentationNodeModuleDefinition(\n 'fs',\n ['*'],\n (fs: FS) => {\n for (const fName of SYNC_FUNCTIONS) {\n const { objectToPatch, functionNameToPatch } = indexFs(fs, fName);\n\n if (isWrapped(objectToPatch[functionNameToPatch])) {\n this._unwrap(objectToPatch, functionNameToPatch);\n }\n this._wrap(\n objectToPatch,\n functionNameToPatch,\n this._patchSyncFunction.bind(this, fName)\n );\n }\n for (const fName of CALLBACK_FUNCTIONS) {\n const { objectToPatch, functionNameToPatch } = indexFs(fs, fName);\n if (isWrapped(objectToPatch[functionNameToPatch])) {\n this._unwrap(objectToPatch, functionNameToPatch);\n }\n if (fName === 'exists') {\n // handling separately because of the inconsistent cb style:\n // `exists` doesn't have error as the first argument, but the result\n this._wrap(\n objectToPatch,\n functionNameToPatch,\n this._patchExistsCallbackFunction.bind(this, fName)\n );\n continue;\n }\n this._wrap(\n objectToPatch,\n functionNameToPatch,\n this._patchCallbackFunction.bind(this, fName)\n );\n }\n for (const fName of PROMISE_FUNCTIONS) {\n if (isWrapped(fs.promises[fName])) {\n this._unwrap(fs.promises, fName);\n }\n this._wrap(\n fs.promises,\n fName,\n this._patchPromiseFunction.bind(this, fName)\n );\n }\n return fs;\n },\n (fs: FS) => {\n if (fs === undefined) return;\n for (const fName of SYNC_FUNCTIONS) {\n const { objectToPatch, functionNameToPatch } = indexFs(fs, fName);\n if (isWrapped(objectToPatch[functionNameToPatch])) {\n this._unwrap(objectToPatch, functionNameToPatch);\n }\n }\n for (const fName of CALLBACK_FUNCTIONS) {\n const { objectToPatch, functionNameToPatch } = indexFs(fs, fName);\n if (isWrapped(objectToPatch[functionNameToPatch])) {\n this._unwrap(objectToPatch, functionNameToPatch);\n }\n }\n for (const fName of PROMISE_FUNCTIONS) {\n if (isWrapped(fs.promises[fName])) {\n this._unwrap(fs.promises, fName);\n }\n }\n }\n ),\n new InstrumentationNodeModuleDefinition(\n 'fs/promises',\n ['*'],\n (fsPromises: FSPromises) => {\n for (const fName of PROMISE_FUNCTIONS) {\n if (isWrapped(fsPromises[fName])) {\n this._unwrap(fsPromises, fName);\n }\n this._wrap(\n fsPromises,\n fName,\n this._patchPromiseFunction.bind(this, fName)\n );\n }\n return fsPromises;\n },\n (fsPromises: FSPromises) => {\n if (fsPromises === undefined) return;\n for (const fName of PROMISE_FUNCTIONS) {\n if (isWrapped(fsPromises[fName])) {\n this._unwrap(fsPromises, fName);\n }\n }\n }\n ),\n ];\n }\n\n protected _patchSyncFunction ReturnType>(\n functionName: FMember,\n original: T\n ): T {\n const instrumentation = this;\n const patchedFunction = function (this: any, ...args: any[]) {\n const activeContext = api.context.active();\n\n if (!instrumentation._shouldTrace(activeContext)) {\n return original.apply(this, args);\n }\n if (\n instrumentation._runCreateHook(functionName, {\n args: args,\n }) === false\n ) {\n return api.context.with(\n suppressTracing(activeContext),\n original,\n this,\n ...args\n );\n }\n\n const span = instrumentation.tracer.startSpan(\n `fs ${functionName}`\n ) as api.Span;\n\n try {\n // Suppress tracing for internal fs calls\n const res = api.context.with(\n suppressTracing(api.trace.setSpan(activeContext, span)),\n original,\n this,\n ...args\n );\n instrumentation._runEndHook(functionName, { args: args, span });\n return res;\n } catch (error: any) {\n span.recordException(error);\n span.setStatus({\n message: error.message,\n code: api.SpanStatusCode.ERROR,\n });\n instrumentation._runEndHook(functionName, { args: args, span, error });\n throw error;\n } finally {\n span.end();\n }\n };\n return patchedFunctionWithOriginalProperties(patchedFunction, original);\n }\n\n protected _patchCallbackFunction ReturnType>(\n functionName: FMember,\n original: T\n ): T {\n const instrumentation = this;\n const patchedFunction = function (this: any, ...args: any[]) {\n const activeContext = api.context.active();\n\n if (!instrumentation._shouldTrace(activeContext)) {\n return original.apply(this, args);\n }\n if (\n instrumentation._runCreateHook(functionName, {\n args: args,\n }) === false\n ) {\n return api.context.with(\n suppressTracing(activeContext),\n original,\n this,\n ...args\n );\n }\n\n const lastIdx = args.length - 1;\n const cb = args[lastIdx];\n if (typeof cb === 'function') {\n const span = instrumentation.tracer.startSpan(\n `fs ${functionName}`\n ) as api.Span;\n\n // Return to the context active during the call in the callback\n args[lastIdx] = api.context.bind(\n activeContext,\n function (this: unknown, error?: Error) {\n if (error) {\n span.recordException(error);\n span.setStatus({\n message: error.message,\n code: api.SpanStatusCode.ERROR,\n });\n }\n instrumentation._runEndHook(functionName, {\n args: args,\n span,\n error,\n });\n span.end();\n return cb.apply(this, arguments);\n }\n );\n\n try {\n // Suppress tracing for internal fs calls\n return api.context.with(\n suppressTracing(api.trace.setSpan(activeContext, span)),\n original,\n this,\n ...args\n );\n } catch (error: any) {\n span.recordException(error);\n span.setStatus({\n message: error.message,\n code: api.SpanStatusCode.ERROR,\n });\n instrumentation._runEndHook(functionName, {\n args: args,\n span,\n error,\n });\n span.end();\n throw error;\n }\n } else {\n // TODO: what to do if we are pretty sure it's going to throw\n return original.apply(this, args);\n }\n };\n return patchedFunctionWithOriginalProperties(patchedFunction, original);\n }\n\n protected _patchExistsCallbackFunction<\n T extends (...args: any[]) => ReturnType\n >(functionName: 'exists', original: T): T {\n const instrumentation = this;\n const patchedFunction = function (this: any, ...args: any[]) {\n const activeContext = api.context.active();\n\n if (!instrumentation._shouldTrace(activeContext)) {\n return original.apply(this, args);\n }\n if (\n instrumentation._runCreateHook(functionName, {\n args: args,\n }) === false\n ) {\n return api.context.with(\n suppressTracing(activeContext),\n original,\n this,\n ...args\n );\n }\n\n const lastIdx = args.length - 1;\n const cb = args[lastIdx];\n if (typeof cb === 'function') {\n const span = instrumentation.tracer.startSpan(\n `fs ${functionName}`\n ) as api.Span;\n\n // Return to the context active during the call in the callback\n args[lastIdx] = api.context.bind(\n activeContext,\n function (this: unknown) {\n // `exists` never calls the callback with an error\n instrumentation._runEndHook(functionName, {\n args: args,\n span,\n });\n span.end();\n return cb.apply(this, arguments);\n }\n );\n\n try {\n // Suppress tracing for internal fs calls\n return api.context.with(\n suppressTracing(api.trace.setSpan(activeContext, span)),\n original,\n this,\n ...args\n );\n } catch (error: any) {\n span.recordException(error);\n span.setStatus({\n message: error.message,\n code: api.SpanStatusCode.ERROR,\n });\n instrumentation._runEndHook(functionName, {\n args: args,\n span,\n error,\n });\n span.end();\n throw error;\n }\n } else {\n return original.apply(this, args);\n }\n };\n const functionWithOriginalProperties =\n patchedFunctionWithOriginalProperties(patchedFunction, original);\n\n // `exists` has a custom promisify function because of the inconsistent signature\n // replicating that on the patched function\n const promisified = function (path: unknown) {\n return new Promise(resolve =>\n functionWithOriginalProperties(path, resolve)\n );\n };\n Object.defineProperty(promisified, 'name', { value: functionName });\n Object.defineProperty(functionWithOriginalProperties, promisify.custom, {\n value: promisified,\n });\n\n return functionWithOriginalProperties;\n }\n\n protected _patchPromiseFunction ReturnType>(\n functionName: FPMember,\n original: T\n ): T {\n const instrumentation = this;\n const patchedFunction = async function (this: any, ...args: any[]) {\n const activeContext = api.context.active();\n\n if (!instrumentation._shouldTrace(activeContext)) {\n return original.apply(this, args);\n }\n if (\n instrumentation._runCreateHook(functionName, {\n args: args,\n }) === false\n ) {\n return api.context.with(\n suppressTracing(activeContext),\n original,\n this,\n ...args\n );\n }\n\n const span = instrumentation.tracer.startSpan(\n `fs ${functionName}`\n ) as api.Span;\n\n try {\n // Suppress tracing for internal fs calls\n const res = await api.context.with(\n suppressTracing(api.trace.setSpan(activeContext, span)),\n original,\n this,\n ...args\n );\n instrumentation._runEndHook(functionName, { args: args, span });\n return res;\n } catch (error: any) {\n span.recordException(error);\n span.setStatus({\n message: error.message,\n code: api.SpanStatusCode.ERROR,\n });\n instrumentation._runEndHook(functionName, { args: args, span, error });\n throw error;\n } finally {\n span.end();\n }\n };\n return patchedFunctionWithOriginalProperties(patchedFunction, original);\n }\n\n protected _runCreateHook(\n ...args: Parameters\n ): ReturnType {\n const { createHook } = this.getConfig();\n if (typeof createHook === 'function') {\n try {\n return createHook(...args);\n } catch (e) {\n this._diag.error('caught createHook error', e);\n }\n }\n return true;\n }\n\n protected _runEndHook(...args: Parameters): ReturnType {\n const { endHook } = this.getConfig();\n if (typeof endHook === 'function') {\n try {\n endHook(...args);\n } catch (e) {\n this._diag.error('caught endHook error', e);\n }\n }\n }\n\n protected _shouldTrace(context: api.Context): boolean {\n if (isTracingSuppressed(context)) {\n // Performance optimization. Avoid creating additional contexts and spans\n // if we already know that the tracing is being suppressed.\n return false;\n }\n\n const { requireParentSpan } = this.getConfig();\n if (requireParentSpan) {\n const parentSpan = api.trace.getSpan(context);\n if (parentSpan == null) {\n return false;\n }\n }\n\n return true;\n }\n}\n"]}