From 22569aca32284d549101c930940ee14db6cadf6e Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Wed, 29 Jan 2025 03:53:18 -0800 Subject: [PATCH] fix(exporter-zipkin): remove deprecated `url.parse` usage (#5390) --- CHANGELOG.md | 1 + .../src/platform/node/util.ts | 22 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1925505a06..a0c9f2ea360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts b/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts index 8835177ccda..93d29ccd0da 100644 --- a/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts +++ b/packages/opentelemetry-exporter-zipkin/src/platform/node/util.ts @@ -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'; /** @@ -31,18 +30,15 @@ export function prepareSend( urlStr: string, headers?: Record ): 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. @@ -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;