Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(otlp-exporter-base): use dynamic import instead of require in esm/esnext build #5220

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(otlp-exporter-base): use dynamic imports over require for lazy-loading http transport utils [#5220](https://github.com/open-telemetry/opentelemetry-js/pull/5220) @pichlermarc
* enables bundling of Node.js HTTP exporters with rollup
* Limitation: if a single-file bundle is built the dynamically loaded file needs to be inlined via rollup's `inlineDynamicImports: true` setting. However, doing so may lead to `@opentelemetry/instrumentation-http` not generating telemetry.

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ class HttpExporterTransport implements IExporterTransport {
async send(data: Uint8Array, timeoutMillis: number): Promise<ExportResponse> {
if (this._send == null) {
// Lazy require to ensure that http/https is not required before instrumentations can wrap it.
const {
sendWithHttp,
createHttpAgent,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('./http-transport-utils');
const { sendWithHttp, createHttpAgent } = await import(
'./http-transport-utils'
);
this._agent = createHttpAgent(
this._parameters.url,
this._parameters.agentOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"outDir": "build/esm",
"rootDir": "src",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo",
"module": "es2020"
},
"include": [
"src/**/*.ts"
Expand Down
Loading