Skip to content

fixing headers issue in FetchTransport instantiation#9876

Open
ssakhamu wants to merge 1 commit intocrashlyticsfrom
crashlytics-logexporter-fix
Open

fixing headers issue in FetchTransport instantiation#9876
ssakhamu wants to merge 1 commit intocrashlyticsfrom
crashlytics-logexporter-fix

Conversation

@ssakhamu
Copy link
Copy Markdown

@ssakhamu ssakhamu commented Apr 22, 2026

The branch currently has an unresolved error for headers value in OTLPLogExporter constructor's FetchTransport instantiation:

Argument of type 'Record<string, string> | HeadersFactory | undefined' is not assignable to parameter of type 'HeadersInit | undefined'.
Type 'HeadersFactory' is not assignable to type 'HeadersInit | undefined'

The type mismatch issue is fixed by making it consistent with what it is in the crashlytics-traces branch. config.headers is casted as a Record such that a HeadersFactory type cannot be passed into the Headers constructor.

@ssakhamu ssakhamu requested a review from a team as a code owner April 22, 2026 14:00
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

⚠️ No Changeset found

Latest commit: e826a98

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the initialization of headers in the OTLPLogExporter to ensure they are treated as an object. The review feedback points out that the current implementation incorrectly ignores function-based header factories and warns of a high-severity issue where headers could accumulate indefinitely due to shared mutable state within the transport layer.

Comment on lines +100 to +104
headers: new Headers(
typeof config.headers === 'object'
? (config.headers as Record<string, string>)
: {}
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation has a few issues:

  1. Ignored HeadersFactory: The check typeof config.headers === 'object' silently ignores config.headers if it is a function (HeadersFactory). This means dynamic headers provided via the standard OpenTelemetry configuration will not be sent.
  2. Code Complexity: The type check and cast can be simplified while still satisfying the TypeScript compiler.
  3. Shared Mutable State (High Severity): Note that FetchTransport (in fetch-transport.ts:87) appends dynamic headers directly to the headers instance passed in the constructor. Since this single instance is shared across all send() calls, headers will accumulate indefinitely with every export. While the fix for the mutation should ideally be in FetchTransport.send(), you should be aware that passing a single Headers instance here triggers this behavior.
          headers: new Headers(
            typeof config.headers === 'function' ? undefined : config.headers
          ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant