{"version":3,"file":"instrumentation.mjs","names":[],"sources":["../src/instrumentation.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\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<T>,\n>(patchedFunction: T, original: T): T {\n  return Object.assign(patchedFunction, original);\n}\n\nexport class FsInstrumentation extends InstrumentationBase<FsInstrumentationConfig> {\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              <any>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                <any>this._patchExistsCallbackFunction.bind(this, fName)\n              );\n              continue;\n            }\n            this._wrap(\n              objectToPatch,\n              functionNameToPatch,\n              <any>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              <any>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              <any>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<T extends (...args: any[]) => ReturnType<T>>(\n    functionName: FMember,\n    original: T\n  ): T {\n    const instrumentation = this;\n    const patchedFunction = <any>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<T extends (...args: any[]) => ReturnType<T>>(\n    functionName: FMember,\n    original: T\n  ): T {\n    const instrumentation = this;\n    const patchedFunction = <any>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<T>,\n  >(functionName: 'exists', original: T): T {\n    const instrumentation = this;\n    const patchedFunction = <any>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<T extends (...args: any[]) => ReturnType<T>>(\n    functionName: FPMember,\n    original: T\n  ): T {\n    const instrumentation = this;\n    const patchedFunction = <any>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<CreateHook>\n  ): ReturnType<CreateHook> {\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<EndHook>): ReturnType<EndHook> {\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"],"mappings":";;;;;;;;;;;;;AAqCA,SAAS,sCAEP,iBAAoB,UAAgB;CACpC,OAAO,OAAO,OAAO,iBAAiB,QAAQ;AAChD;AAEA,IAAa,oBAAb,cAAuC,oBAA6C;CAClF,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM,cAAc,iBAAiB,MAAM;CAC7C;CAEA,OAGI;EACF,OAAO,CACL,IAAI,oCACF,MACA,CAAC,GAAG,IACH,OAAW;GACV,KAAK,MAAM,SAAS,gBAAgB;IAClC,MAAM,EAAE,eAAe,wBAAwB,QAAQ,IAAI,KAAK;IAEhE,IAAI,UAAU,cAAc,oBAAoB,GAC9C,KAAK,QAAQ,eAAe,mBAAmB;IAEjD,KAAK,MACH,eACA,qBACK,KAAK,mBAAmB,KAAK,MAAM,KAAK,CAC/C;GACF;GACA,KAAK,MAAM,SAAS,oBAAoB;IACtC,MAAM,EAAE,eAAe,wBAAwB,QAAQ,IAAI,KAAK;IAChE,IAAI,UAAU,cAAc,oBAAoB,GAC9C,KAAK,QAAQ,eAAe,mBAAmB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