Skip to content

Bug: RequestInit options lost when Request object passed as first argument to fetch() #6421

@dalechyn

Description

@dalechyn

Issue

In experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts at line 423,
the current logic discards RequestInit options when a Request object is passed as the
first argument to fetch().

Current Code

const options = args[0] instanceof Request ? args[0] : args[1] || {};

When fetch is called as fetch(request, requestInit), the requestInit (args[1]) is completely ignored, which violates the Fetch API specification.

Expected Behavior

According to the Fetch API spec, when a Request object is passed along with a RequestInit, the init options should override or extend the request's properties.

Proposed Fix

const options = args[0] instanceof Request 
  ? new Request(args[0], args[1]) 
  : { url: args[0], ...args[1] };

This ensures proper merging of request initialization options.

Affected Code

const options = args[0] instanceof Request ? args[0] : args[1] || {};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions