Skip to content

test(instrumentation-http): avoid deprecated url.parse()#6102

Merged
pichlermarc merged 2 commits intoopen-telemetry:mainfrom
cjihrig:url-parse-tests
Nov 13, 2025
Merged

test(instrumentation-http): avoid deprecated url.parse()#6102
pichlermarc merged 2 commits intoopen-telemetry:mainfrom
cjihrig:url-parse-tests

Conversation

@cjihrig
Copy link
Copy Markdown
Contributor

@cjihrig cjihrig commented Nov 13, 2025

Which problem is this PR solving?

The tests in the instrumentation-http package rely on url.parse(), which is deprecated in Node.

Fixes #6061

Short description of the changes

The relevant tests have been updated to no longer rely on url.parse(). Most of the uses of url.parse() are simply replaced by new URL() and url. urlToHttpOptions().

Some of the tested APIs, such as getRequestInfo() and getAbsoluteUrl() seem to specifically expect objects that are output from url.parse(). In these cases, I inlined the result of url.parse() in the tests since this is highly unlikely to ever change in Node.js at this point.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Test suite.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@cjihrig cjihrig requested a review from a team as a code owner November 13, 2025 02:20
Comment thread experimental/CHANGELOG.md Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.16%. Comparing base (66ee4d6) to head (d44f10a).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6102   +/-   ##
=======================================
  Coverage   95.16%   95.16%           
=======================================
  Files         316      316           
  Lines        9220     9220           
  Branches     2080     2080           
=======================================
  Hits         8774     8774           
  Misses        446      446           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

hostname: null,
hash: null,
search: null,
query: null as unknown as undefined,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unrelated note - the types for getAbsoluteUrl() seem like they may be slightly incorrect. See the other type cast on line 203 of this file.

url.parse() returns an object whose query field is of type string | null | ParsedUrlQuery. However, string and null are problematic in getAbsoluteUrl(). The first argument to getAbsoluteUrl() is currently ParsedRequestOptions | null. ParsedRequestOptions is defined as:

export type ParsedRequestOptions =
  | (http.RequestOptions & Partial<url.UrlWithParsedQuery>)
  | http.RequestOptions;

And, the relevant Node core types are:

    // Output of `url.parse`
    interface Url {
        auth: string | null;
        hash: string | null;
        host: string | null;
        hostname: string | null;
        href: string;
        path: string | null;
        pathname: string | null;
        protocol: string | null;
        search: string | null;
        slashes: boolean | null;
        port: string | null;
        query: string | null | ParsedUrlQuery;
    }
    interface UrlWithParsedQuery extends Url {
        query: ParsedUrlQuery;
    }
    interface UrlWithStringQuery extends Url {
        query: string | null;
    }

It's not clear to me why ParsedRequestOptions uses url.UrlWithParsedQuery instead of url.Url here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tired to do some archeology on this and it seems that this was added all the way back in #161 and has grown to be somewhat different since then. I think some cleanup is needed here (in a separate PR).

hostname: null,
hash: null,
search: null,
query: null as unknown as undefined,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tired to do some archeology on this and it seems that this was added all the way back in #161 and has grown to be somewhat different since then. I think some cleanup is needed here (in a separate PR).

@pichlermarc pichlermarc added this pull request to the merge queue Nov 13, 2025
Merged via the queue into open-telemetry:main with commit 2c0bca4 Nov 13, 2025
27 checks passed
@otelbot
Copy link
Copy Markdown
Contributor

otelbot Bot commented Nov 13, 2025

Thank you for your contribution @cjihrig! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

@cjihrig cjihrig deleted the url-parse-tests branch November 13, 2025 14:27
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.

url.parse has been deprecated in Node v24 and is used in instrument-http

2 participants