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AAC,EACF,EAAE,CACH;qBACF,EACD,KAAK,EAAC,IAAI,EAAC,EAAE;wBACX,IAAI;4BACF,OAAO,MAAM,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;yBACtC;wBAAC,OAAO,KAAU,EAAE;4BACnB,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;4BAClD,uBAAuB,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;4BACpD,MAAM,KAAK,CAAC;yBACb;gCAAS;4BACR,IAAI,CAAC,GAAG,EAAE,CAAC;yBACZ;oBACH,CAAC,CACF,CAAC;gBACJ,CAAC;gBACD,2EAA2E;gBAC3E,4CAA4C;gBAC5C,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,QAAQ,EAAE;oBAC7C,KAAK,EAAE,IAAI,EAAE,MAAM;iBACpB,CAAC,CAAC;gBACH,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,aAAoB,CAAC,CAAC;YACrE,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF;AAjWD,0DAiWC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Span, SpanKind, SpanStatusCode } from '@opentelemetry/api';\nimport {\n  InstrumentationBase,\n  InstrumentationNodeModuleDefinition,\n  InstrumentationNodeModuleFile,\n  isWrapped,\n} from '@opentelemetry/instrumentation';\nimport {\n  ATTR_CODE_FILE_PATH,\n  ATTR_CODE_FUNCTION_NAME,\n  ATTR_CODE_LINE_NUMBER,\n} from '@opentelemetry/semantic-conventions';\n\nimport type * as cucumber from '@cucumber/cucumber';\nimport type * as messages from '@cucumber/messages';\nimport type TestCaseRunner from '@cucumber/cucumber/lib/runtime/test_case_runner';\nimport type {\n  DefineStepPattern,\n  IDefineStepOptions,\n  IDefineTestRunHookOptions,\n} from '@cucumber/cucumber/lib/support_code_library_builder/types';\n\nimport { AttributeNames, CucumberInstrumentationConfig } from './types';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_VERSION } from './version';\n\nconst hooks = ['Before', 'BeforeStep', 'AfterStep', 'After'] as const;\nconst steps = ['Given', 'When', 'Then'] as const;\ntype Cucumber = typeof cucumber;\ntype Hook = (typeof hooks)[number];\ntype Step = (typeof steps)[number];\n\nconst supportedVersions = ['>=8.0.0 <13'];\n\nexport class CucumberInstrumentation extends InstrumentationBase<CucumberInstrumentationConfig> {\n  private module: Cucumber | undefined;\n\n  constructor(config: CucumberInstrumentationConfig = {}) {\n    super(PACKAGE_NAME, PACKAGE_VERSION, config);\n  }\n\n  init(): InstrumentationNodeModuleDefinition[] {\n    return [\n      new InstrumentationNodeModuleDefinition(\n        '@cucumber/cucumber',\n        supportedVersions,\n        (moduleExports: Cucumber) => {\n          this.module = moduleExports;\n          steps.forEach(step => {\n            if (isWrapped(moduleExports[step])) {\n              this._unwrap(moduleExports, step);\n            }\n            this._wrap(moduleExports, step, this._getStepPatch(step));\n          });\n          hooks.forEach(hook => {\n            if (isWrapped(moduleExports[hook])) {\n              this._unwrap(moduleExports, hook);\n            }\n            this._wrap(moduleExports, hook, this._getHookPatch(hook));\n          });\n          return moduleExports;\n        },\n        (moduleExports: Cucumber) => {\n          if (moduleExports === undefined) return;\n          [...hooks, ...steps].forEach(method => {\n            this._unwrap(moduleExports, method);\n          });\n        },\n        [\n          new InstrumentationNodeModuleFile(\n            '@cucumber/cucumber/lib/runtime/test_case_runner.js',\n            supportedVersions,\n            moduleExports => {\n              if (isWrapped(moduleExports.default.prototype.run)) {\n                this._unwrap(moduleExports.default.prototype, 'run');\n                this._unwrap(moduleExports.default.prototype, 'runStep');\n                if ('runAttempt' in moduleExports.default.prototype) {\n                  this._unwrap(moduleExports.default.prototype, 'runAttempt');\n                }\n              }\n              this._wrap(\n                moduleExports.default.prototype,\n                'run',\n                this._getTestCaseRunPatch()\n              );\n              this._wrap(\n                moduleExports.default.prototype,\n                'runStep',\n                this._getTestCaseRunStepPatch()\n              );\n              if ('runAttempt' in moduleExports.default.prototype) {\n                this._wrap(\n                  moduleExports.default.prototype,\n                  'runAttempt',\n                  this._getTestCaseRunAttemptPatch()\n                );\n              }\n              return moduleExports;\n            },\n            moduleExports => {\n              if (moduleExports === undefined) return;\n              this._unwrap(moduleExports.default.prototype, 'run');\n              this._unwrap(moduleExports.default.prototype, 'runStep');\n              if ('runAttempt' in moduleExports.default.prototype) {\n                this._unwrap(moduleExports.default.prototype, 'runAttempt');\n              }\n            }\n          ),\n        ]\n      ),\n    ];\n  }\n\n  private static mapTags(tags: readonly messages.Tag[]): string[] {\n    return tags.map(tag => tag.name);\n  }\n\n  private static setSpanToError(span: Span, error: any) {\n    span.recordException(error);\n    span.setStatus({\n      code: SpanStatusCode.ERROR,\n      message: error?.message ?? error,\n    });\n  }\n\n  private setSpanToStepStatus(\n    span: Span,\n    status: messages.TestStepResultStatus,\n    context?: string\n  ) {\n    // if the telemetry is enabled, the module should be defined\n    if (!this.module) return;\n\n    span.setAttribute(AttributeNames.STEP_STATUS, status);\n    if (\n      [\n        this.module.Status.UNDEFINED,\n        this.module.Status.AMBIGUOUS,\n        this.module.Status.FAILED,\n      ].includes(status)\n    ) {\n      span.recordException(status);\n      span.setStatus({\n        code: SpanStatusCode.ERROR,\n        message: context || status,\n      });\n    }\n  }\n\n  private _getTestCaseRunPatch() {\n    const instrumentation = this;\n    return function (original: TestCaseRunner['run']): TestCaseRunner['run'] {\n      return async function (this: TestCaseRunner, ...args) {\n        const gherkinDocument = this[\n          'gherkinDocument'\n        ] as Required<messages.GherkinDocument>;\n        const { feature } = gherkinDocument;\n        const pickle = this['pickle'] as messages.Pickle;\n        const scenario = feature.children.find(\n          node => node?.scenario?.id === pickle.astNodeIds[0]\n        )?.scenario as messages.Scenario;\n\n        return instrumentation.tracer.startActiveSpan(\n          `Feature: ${feature.name}. Scenario: ${pickle.name}`,\n          {\n            kind: SpanKind.CLIENT,\n            attributes: {\n              [ATTR_CODE_FILE_PATH]: gherkinDocument.uri,\n              [ATTR_CODE_LINE_NUMBER]: scenario.location.line,\n              [ATTR_CODE_FUNCTION_NAME]: `${feature.name} ${scenario.name}`,\n              [AttributeNames.FEATURE_TAGS]: CucumberInstrumentation.mapTags(\n                feature.tags\n              ),\n              [AttributeNames.FEATURE_LANGUAGE]: feature.language,\n              [AttributeNames.FEATURE_DESCRIPTION]: feature.description,\n              [AttributeNames.SCENARIO_TAGS]: CucumberInstrumentation.mapTags(\n                scenario.tags\n              ),\n              [AttributeNames.SCENARIO_DESCRIPTION]: scenario.description,\n            },\n          },\n          async span => {\n            try {\n              const status = await original.apply(this, args);\n              instrumentation.setSpanToStepStatus(span, status);\n              return status;\n            } catch (error: any) {\n              CucumberInstrumentation.setSpanToError(span, error);\n              throw error;\n            } finally {\n              span.end();\n            }\n          }\n        );\n      };\n    };\n  }\n\n  private _getTestCaseRunStepPatch() {\n    const instrumentation = this;\n    return function (\n      original: TestCaseRunner['runStep']\n    ): TestCaseRunner['runStep'] {\n      return async function (\n        this: TestCaseRunner,\n        ...args\n      ): ReturnType<TestCaseRunner['runStep']> {\n        const [pickleStep] = args;\n        return instrumentation.tracer.startActiveSpan(\n          pickleStep.text,\n          {\n            kind: SpanKind.CLIENT,\n            attributes: {\n              [AttributeNames.STEP_TYPE]: pickleStep.type,\n            },\n          },\n          async span => {\n            try {\n              const runStepResult = await original.apply(this, args);\n              const { result, error } = (() => {\n                if ('result' in runStepResult) {\n                  return runStepResult;\n                }\n                return {\n                  result: runStepResult,\n                  error: undefined,\n                };\n              })();\n              instrumentation.setSpanToStepStatus(\n                span,\n                result.status,\n                result.message\n              );\n              if (error) {\n                CucumberInstrumentation.setSpanToError(span, error);\n              }\n              return runStepResult;\n            } catch (error) {\n              CucumberInstrumentation.setSpanToError(span, error);\n              throw error;\n            } finally {\n              span.end();\n            }\n          }\n        );\n      };\n    };\n  }\n\n  private _getTestCaseRunAttemptPatch() {\n    const instrumentation = this;\n    return function (\n      original: TestCaseRunner['runAttempt']\n    ): TestCaseRunner['runAttempt'] {\n      return async function (this: TestCaseRunner, ...args): Promise<boolean> {\n        const [attempt] = args;\n        return instrumentation.tracer.startActiveSpan(\n          `Attempt #${attempt}`,\n          {\n            kind: SpanKind.CLIENT,\n            attributes: {},\n          },\n          async span => {\n            try {\n              const result = await original.apply(this, args);\n              const worstResult = this.getWorstStepResult();\n              instrumentation.setSpanToStepStatus(\n                span,\n                worstResult.status,\n                worstResult.message\n              );\n              return result;\n            } catch (error) {\n              CucumberInstrumentation.setSpanToError(span, error);\n              throw error;\n            } finally {\n              span.end();\n            }\n          }\n        );\n      };\n    };\n  }\n\n  private _getHookPatch<H extends Hook>(name: H) {\n    const instrumentation = this;\n    return function (original: Cucumber[H]): Cucumber[H] {\n      return function (\n        this: {},\n        tagsOrOptions: string | IDefineTestRunHookOptions | Function,\n        code?: Function\n      ) {\n        if (typeof tagsOrOptions === 'function') {\n          code = tagsOrOptions;\n          tagsOrOptions = {};\n        }\n\n        function traceableCode(\n          this: cucumber.IWorld,\n          arg: cucumber.ITestCaseHookParameter\n        ) {\n          // because we're wrapping the function that was passed to the hook,\n          // it will stay wrapped in cucumber's internal state\n          // even if we disable the instrumentation\n          if (!instrumentation.isEnabled()) return code?.call(this, arg);\n\n          return instrumentation.tracer.startActiveSpan(\n            name,\n            {\n              kind: SpanKind.CLIENT,\n            },\n            async span => {\n              try {\n                return await code?.call(this, arg);\n              } catch (error: any) {\n                this.attach?.(JSON.stringify(span.spanContext()));\n                CucumberInstrumentation.setSpanToError(span, error);\n                throw error;\n              } finally {\n                span.end();\n              }\n            }\n          );\n        }\n        return original.call(this, tagsOrOptions as any, traceableCode as any);\n      };\n    };\n  }\n\n  private _getStepPatch<S extends Step>(name: S) {\n    const instrumentation = this;\n    return function (original: Cucumber[S]): Cucumber[S] {\n      return function (\n        this: {},\n        pattern: DefineStepPattern,\n        options: IDefineStepOptions | Function,\n        code?: Function\n      ): void {\n        if (typeof options === 'function') {\n          code = options;\n          options = {};\n        }\n\n        function traceableCode(this: cucumber.IWorld, ...args: any[]) {\n          // because we're wrapping the function that was passed to the hook,\n          // it will stay wrapped in cucumber's internal state\n          // even if we disable the instrumentation\n          if (!instrumentation.isEnabled()) return code?.apply(this, args);\n\n          return instrumentation.tracer.startActiveSpan(\n            `${name}(${pattern.toString()})`,\n            {\n              kind: SpanKind.CLIENT,\n              // ignore the last argument because it's a callback\n              attributes: args.slice(0, -1).reduce(\n                (attrs, arg, index) => ({\n                  ...attrs,\n                  [`${AttributeNames.STEP_ARGS}[${index}]`]:\n                    arg?.raw instanceof Function\n                      ? JSON.stringify(arg.raw())\n                      : arg,\n                }),\n                {}\n              ),\n            },\n            async span => {\n              try {\n                return await code?.apply(this, args);\n              } catch (error: any) {\n                this.attach?.(JSON.stringify(span.spanContext()));\n                CucumberInstrumentation.setSpanToError(span, error);\n                throw error;\n              } finally {\n                span.end();\n              }\n            }\n          );\n        }\n        // cucumber asks for the number of arguments to match the specified pattern\n        // copy the value from the original function\n        Object.defineProperty(traceableCode, 'length', {\n          value: code?.length,\n        });\n        return original.call(this, pattern, options, traceableCode as any);\n      };\n    };\n  }\n}\n"]}