{"version":3,"file":"otlp-node-http-configuration.js","sourceRoot":"","sources":["../../../src/configuration/otlp-node-http-configuration.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,uEAImC;AAwBnC,SAAgB,2BAA2B,CACzC,OAA+C;IAE/C,OAAO,KAAK,EAAC,QAAQ,EAAC,EAAE;QACtB,MAAM,MAAM,GAAG,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACvE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC;QAC/B,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AARD,kEAQC;AAED;;;;GAIG;AACH,SAAgB,0CAA0C,CACxD,yBAA6D,EAC7D,qBAAyD,EACzD,oBAA+C;IAE/C,OAAO;QACL,GAAG,IAAA,gEAAsC,EACvC,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,CACrB;QACD,YAAY,EACV,yBAAyB,CAAC,YAAY;YACtC,qBAAqB,CAAC,YAAY;YAClC,oBAAoB,CAAC,YAAY;KACpC,CAAC;AACJ,CAAC;AAhBD,gGAgBC;AAED,SAAgB,gCAAgC,CAC9C,eAAuC,EACvC,kBAA0B;IAE1B,OAAO;QACL,GAAG,IAAA,sDAA4B,EAAC,eAAe,EAAE,kBAAkB,CAAC;QACpE,YAAY,EAAE,2BAA2B,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;KAC/D,CAAC;AACJ,CAAC;AARD,4EAQC","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 */\nimport {\n  getHttpConfigurationDefaults,\n  mergeOtlpHttpConfigurationWithDefaults,\n  OtlpHttpConfiguration,\n} from './otlp-http-configuration';\n\n// NOTE: do not change these imports to be actual imports, otherwise they WILL break `@opentelemetry/instrumentation-http`\nimport type * as http from 'http';\nimport type * as https from 'https';\n\nexport type HttpAgentFactory = (\n  protocol: string\n) => http.Agent | https.Agent | Promise<http.Agent> | Promise<https.Agent>;\n\nexport interface OtlpNodeHttpConfiguration extends OtlpHttpConfiguration {\n  /**\n   * Factory function for creating agents.\n   *\n   * @remarks\n   * Prefer using {@link httpAgentFactoryFromOptions} over manually writing a factory function wherever possible.\n   * If using a factory function (`HttpAgentFactory`), **do not import `http.Agent` or `https.Agent`\n   * statically at the top of the file**.\n   * Instead, use dynamic `import()` or `require()` to load the module. This ensures that the `http` or `https`\n   * module is not loaded before `@opentelemetry/instrumentation-http` can instrument it.\n   */\n  agentFactory: HttpAgentFactory;\n}\n\nexport function httpAgentFactoryFromOptions(\n  options: http.AgentOptions | https.AgentOptions\n): HttpAgentFactory {\n  return async protocol => {\n    const module = protocol === 'http:' ? import('http') : import('https');\n    const { Agent } = await module;\n    return new Agent(options);\n  };\n}\n\n/**\n * @param userProvidedConfiguration  Configuration options provided by the user in code.\n * @param fallbackConfiguration Fallback to use when the {@link userProvidedConfiguration} does not specify an option.\n * @param defaultConfiguration The defaults as defined by the exporter specification\n */\nexport function mergeOtlpNodeHttpConfigurationWithDefaults(\n  userProvidedConfiguration: Partial<OtlpNodeHttpConfiguration>,\n  fallbackConfiguration: Partial<OtlpNodeHttpConfiguration>,\n  defaultConfiguration: OtlpNodeHttpConfiguration\n): OtlpNodeHttpConfiguration {\n  return {\n    ...mergeOtlpHttpConfigurationWithDefaults(\n      userProvidedConfiguration,\n      fallbackConfiguration,\n      defaultConfiguration\n    ),\n    agentFactory:\n      userProvidedConfiguration.agentFactory ??\n      fallbackConfiguration.agentFactory ??\n      defaultConfiguration.agentFactory,\n  };\n}\n\nexport function getNodeHttpConfigurationDefaults(\n  requiredHeaders: Record<string, string>,\n  signalResourcePath: string\n): OtlpNodeHttpConfiguration {\n  return {\n    ...getHttpConfigurationDefaults(requiredHeaders, signalResourcePath),\n    agentFactory: httpAgentFactoryFromOptions({ keepAlive: true }),\n  };\n}\n"]}