Skip to content

Commit 137082d

Browse files
apply review suggestions
Co-authored-by: Marc Pichler <[email protected]>
1 parent c8a9930 commit 137082d

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

experimental/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
99
### :boom: Breaking Changes
1010

1111
* feat(api-logs)!: Marked private methods as "conventionally private". [#5789](https://github.com/open-telemetry/opentelemetry-js/pull/5789)
12+
* feat(exporter-otlp-\*): support custom HTTP agents [#5719](https://github.com/open-telemetry/opentelemetry-js/pull/5719) @raphael-theriault-swi
13+
* `OtlpHttpConfiguration.agentOptions` has been removed and functionality has been rolled into `OtlpHttpConfiguration.agentFactory`
14+
* (old) `{ agentOptions: myOptions }`
15+
* (new) `{ agentFactory: httpAgentFactoryFromOptions(myOptions) }`
1216

1317
### :rocket: Features
1418

15-
* feat(exporter-otlp-\*): support custom HTTP agents [#5719](https://github.com/open-telemetry/opentelemetry-js/pull/5719) @raphael-theriault-swi
16-
1719
### :bug: Bug Fixes
1820

1921
* fix(otlp-exporter-base): prioritize `esnext` export condition as it is more specific [#5458](https://github.com/open-telemetry/opentelemetry-js/pull/5458)

experimental/packages/otlp-exporter-base/src/configuration/legacy-node-configuration.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ import type { HttpAgentFactory } from './otlp-http-configuration';
2727
export interface OTLPExporterNodeConfigBase extends OTLPExporterConfigBase {
2828
keepAlive?: boolean;
2929
compression?: CompressionAlgorithm;
30+
/**
31+
* Custom HTTP agent options or a factory function for creating agents.
32+
*
33+
* @remarks
34+
* Prefer using `http.AgentOptions` or `https.AgentOptions` over a factory function wherever possible.
35+
* If using a factory function (`HttpAgentFactory`), **do not import `http.Agent` or `https.Agent`
36+
* statically at the top of the file**.
37+
* Instead, use dynamic `import()` or `require()` to load the module. This ensures that the `http` or `https`
38+
* module is not loaded before `@opentelemetry/instrumentation-http` can instrument it.
39+
*
40+
* @example <caption> Using agent options directly: </caption>
41+
* httpAgentOptions: {
42+
* keepAlive: true,
43+
* maxSockets: 10
44+
* }
45+
*
46+
* @example <caption> Using a factory with dynamic import: </caption>
47+
* httpAgentOptions: async (protocol) => {
48+
* const module = protocol === 'http:' ? await import('http') : await import('https');
49+
* return new module.Agent({ keepAlive: true });
50+
* }
51+
*/
3052
httpAgentOptions?: http.AgentOptions | https.AgentOptions | HttpAgentFactory;
3153
}
3254

experimental/packages/otlp-exporter-base/src/configuration/otlp-http-configuration.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,23 @@ import { validateAndNormalizeHeaders } from '../util';
2525
import type * as http from 'http';
2626
import type * as https from 'https';
2727

28-
export type HttpAgentFactory =
29-
| ((protocol: string) => http.Agent)
30-
| ((protocol: string) => https.Agent)
31-
| ((protocol: string) => Promise<http.Agent>)
32-
| ((protocol: string) => Promise<https.Agent>);
28+
export type HttpAgentFactory = (
29+
protocol: string
30+
) => http.Agent | https.Agent | Promise<http.Agent> | Promise<https.Agent>;
3331

3432
export interface OtlpHttpConfiguration extends OtlpSharedConfiguration {
3533
url: string;
3634
headers: () => Record<string, string>;
35+
/**
36+
* Factory function for creating agents.
37+
*
38+
* @remarks
39+
* Prefer using {@link httpAgentFactoryFromOptions} over manually writing a factory function wherever possible.
40+
* If using a factory function (`HttpAgentFactory`), **do not import `http.Agent` or `https.Agent`
41+
* statically at the top of the file**.
42+
* Instead, use dynamic `import()` or `require()` to load the module. This ensures that the `http` or `https`
43+
* module is not loaded before `@opentelemetry/instrumentation-http` can instrument it.
44+
*/
3745
agentFactory: HttpAgentFactory;
3846
}
3947

scripts/update-ts-configs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const tsConfigMergeKeys = [
4040
'compilerOptions',
4141
'include',
4242
'files',
43-
"ts-node",
4443
];
4544
// Make `extends` the first field.
4645
const tsConfigPriorityKeys = ['extends'];

0 commit comments

Comments
 (0)