Skip to content

Commit

Permalink
fix(exporter-zipkin): remove deprecated url.parse usage
Browse files Browse the repository at this point in the history
Addresses the following deprecation/eslint warning:

```
/home/runner/work/opentelemetry-js/opentelemetry-js/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts
  34:19  warning  'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead  node/no-deprecated-api
```

`http(s).request` now takes a URL (the global one, not `url.URL`)
argument separate from the options bag, so we should be able to
make this change compatibly, outside of some weird edge cases that
are probably not applicable here.

It is worth noting in the CHANGELOG since this used to trigger a
Node runtime deprecation warning with `--pending-deprecation`.

Ref #5365
  • Loading branch information
chancancode committed Jan 29, 2025
1 parent 199fd8d commit a173adc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

### :bug: (Bug Fix)

* fix(exporter-zipkin): remove usages of deprecated `url.parse` from `node:url` [#5390](https://github.com/open-telemetry/opentelemetry-js/pull/5390) @chancancode
* fix(sdk-metrics): do not export from `PeriodicExportingMetricReader` when there are no metrics to export. [#5288](https://github.com/open-telemetry/opentelemetry-js/pull/5288) @jacksonweber

### :books: (Refine Doc)
Expand Down
22 changes: 9 additions & 13 deletions packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { diag } from '@opentelemetry/api';
import { ExportResult, ExportResultCode } from '@opentelemetry/core';
import * as http from 'http';
import * as https from 'https';
import * as url from 'url';
import * as zipkinTypes from '../../types';

/**
Expand All @@ -31,18 +30,15 @@ export function prepareSend(
urlStr: string,
headers?: Record<string, string>
): zipkinTypes.SendFn {
const urlOpts = url.parse(urlStr);
const url = new URL(urlStr);

const reqOpts: http.RequestOptions = Object.assign(
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
...headers,
},
const reqOpts: http.RequestOptions = Object.assign({
method: 'POST',
headers: {
'Content-Type': 'application/json',
...headers,
},
urlOpts
);
});

/**
* Send spans to the remote Zipkin service.
Expand All @@ -56,8 +52,8 @@ export function prepareSend(
return done({ code: ExportResultCode.SUCCESS });
}

const { request } = reqOpts.protocol === 'http:' ? http : https;
const req = request(reqOpts, (res: http.IncomingMessage) => {
const { request } = url.protocol === 'http:' ? http : https;
const req = request(url, reqOpts, (res: http.IncomingMessage) => {
let rawData = '';
res.on('data', chunk => {
rawData += chunk;
Expand Down

0 comments on commit a173adc

Please sign in to comment.