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

refactor(instrumentation-http): fix eslint warnings #5394

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

chancancode
Copy link
Contributor

Which problem is this PR solving?

Fixes the following eslint warnings:

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
  236:41  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  251:31  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  252:31  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  283:41  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  298:31  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  299:31  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  508:17  warning  Forbidden non-null assertion              @typescript-eslint/no-non-null-assertion
  931:11  warning  Forbidden non-null assertion              @typescript-eslint/no-non-null-assertion
  1032:13  warning  Forbidden non-null assertion              @typescript-eslint/no-non-null-assertion
  1043:13  warning  Forbidden non-null assertion              @typescript-eslint/no-non-null-assertion
  1051:15  warning  Don't use `Function` as a type            @typescript-eslint/ban-types

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-package.test.ts
  86:27  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-package.test.ts
  86:27  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts
  81:25  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api
  156:43  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api
  161:43  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api
  213:35  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/integrations/http-enable.test.ts
  300:9  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/integrations/https-enable.test.ts
  274:9  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

Ref #5365

Short description of the changes

There are a fair bit of changes here, but splitting into multiple PRs would just create a lot of conflicts. So instead, each commit is one unit of change with a detailed description in the commit message.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • unit tests
  • eslint
  • TypeScript

Checklist:

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

Fix the following eslint warnings:

```
/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
  236:41  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  251:31  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  252:31  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  283:41  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  298:31  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
  299:31  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
```

Extracted a utility function with more precise types for the job.

Ref open-telemetry#5365
Fix the following eslint warnings:

```
/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
  508:17  warning  Forbidden non-null assertion              @typescript-eslint/no-non-null-assertion
  931:11  warning  Forbidden non-null assertion              @typescript-eslint/no-non-null-assertion
  1032:13  warning  Forbidden non-null assertion              @typescript-eslint/no-non-null-assertion
  1043:13  warning  Forbidden non-null assertion              @typescript-eslint/no-non-null-assertion
```

Because the expression we check is indirected through the a method
call (`getConfig()`), TypeScript cannot assume the value would be
the same across the two calls. By extracting the value and checking
for that, TypeScript can narrow the type correctly and we can avoid
the non-null assertion.

Ref open-telemetry#5365
```
/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
  1051:15  warning  Don't use `Function` as a type            @typescript-eslint/ban-types
```

Be explict about what type of functions we are expecting here.

Ref open-telemetry#5365
```
/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-package.test.ts
  86:27  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-package.test.ts
  86:27  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts
  81:25  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api
  156:43  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api
  161:43  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api
  213:35  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/integrations/http-enable.test.ts
  300:9  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api

/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/test/integrations/https-enable.test.ts
  274:9  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api
```

Generally speaking, `new URL()` is not a direct replacement for the
deprecated `url.parse()`, so this type of change requires careful
considerations.

However, in this instance, these are all found in test code, which
cuts out a lot of the typically associated issues, and the tests
passing after the change is a good indication for correctness.

Ref open-telemetry#5365
@chancancode chancancode requested a review from a team as a code owner January 29, 2025 20:54
@chancancode chancancode mentioned this pull request Jan 29, 2025
25 tasks
Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.64%. Comparing base (29d0da5) to head (9f63cf8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5394   +/-   ##
=======================================
  Coverage   94.64%   94.64%           
=======================================
  Files         318      318           
  Lines        8033     8033           
  Branches     1688     1688           
=======================================
  Hits         7603     7603           
  Misses        430      430           

@chancancode chancancode changed the title Eslint warning instrumentation http refactor(instrumentation-http): fix eslint warnings Jan 29, 2025
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