{"version":3,"file":"EmbraceFetchInstrumentation.cjs","names":["FetchInstrumentation"],"sources":["../../../../src/instrumentations/fetch/EmbraceFetchInstrumentation/EmbraceFetchInstrumentation.ts"],"sourcesContent":["import { isWrapped } from '@opentelemetry/instrumentation';\n\nimport { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch';\nimport type { EmbraceFetchInstrumentationArgs } from './types.ts';\n\nexport class EmbraceFetchInstrumentation extends FetchInstrumentation {\n  private readonly _omitIfAlreadyPatched?: boolean;\n\n  public constructor({\n    omitIfAlreadyPatched,\n    ...rest\n  }: EmbraceFetchInstrumentationArgs = {}) {\n    // Base constructor automatically calls this.enable() if enabled is true, but we need to run our overridden constructor\n    // first so force enabled false here and call it ourselves later\n    super({ ...rest, enabled: false });\n\n    this._omitIfAlreadyPatched = omitIfAlreadyPatched;\n\n    if (rest.enabled) {\n      this.enable();\n    }\n  }\n\n  public override enable(): void {\n    // The base implementation always removes and then re-patches, this means the last instrumentation to run \"wins\":\n    // https://github.com/open-telemetry/opentelemetry-js/blob/2d7eecbb19aec17bf2d8b9a4e4b2d84dc92c2d88/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L604\n    // Exposing an option in this class to allow leaving the existing patch in place and letting a previous instrumentation\n    // control the global\n    if (this._omitIfAlreadyPatched && isWrapped(fetch)) {\n      this._diag.debug(\n        'fetch is already passed and `omitIfAlreadyPatched` is true, skipping enabling this instrumentation',\n      );\n      return;\n    }\n\n    super.enable();\n  }\n}\n"],"mappings":";;;;;AAKA,IAAa,8BAAb,cAAiDA,qCAAAA,qBAAqB;CACpE;CAEA,YAAmB,EACjB,sBACA,GAAG,SACgC,EAAE,EAAE;AAGvC,QAAM;GAAE,GAAG;GAAM,SAAS;GAAO,CAAC;AAElC,OAAK,wBAAwB;AAE7B,MAAI,KAAK,QACP,MAAK,QAAQ;;CAIjB,SAA+B;AAK7B,MAAI,KAAK,0BAAA,GAAA,+BAAA,WAAmC,MAAM,EAAE;AAClD,QAAK,MAAM,MACT,qGACD;AACD;;AAGF,QAAM,QAAQ"}