Skip to content

Commit

Permalink
Change config.url to be a string instead of a URL object
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Sep 11, 2024
1 parent 14ebf97 commit 80565db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/dd-trace/src/appsec/remote_config/manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { URL, format } = require('url')
const { format } = require('url')
const uuid = require('crypto-randomuuid')
const { EventEmitter } = require('events')
const tracerVersion = require('../../../../../package.json').version
Expand All @@ -27,11 +27,11 @@ class RemoteConfigManager extends EventEmitter {

const pollInterval = Math.floor(config.remoteConfig.pollInterval * 1000)

this.url = config.url || new URL(format({
this.url = config.url || format({
protocol: 'http:',
hostname: config.hostname || 'localhost',
port: config.port
}))
})

this._handlers = new Map()
const appliedConfigs = this.appliedConfigs = new Map()
Expand Down
7 changes: 5 additions & 2 deletions packages/dd-trace/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,10 @@ function maybeFloat (number) {
}

function getAgentUrl (url, options) {
if (url) return new URL(url)
if (url) {
if (typeof url === 'string') return url
if (url instanceof URL) return url.toString()
}

if (os.type() === 'Windows_NT') return

Expand All @@ -1238,7 +1241,7 @@ function getAgentUrl (url, options) {
!process.env.DD_TRACE_AGENT_PORT &&
fs.existsSync('/var/run/datadog/apm.socket')
) {
return new URL('unix:///var/run/datadog/apm.socket')
return 'unix:///var/run/datadog/apm.socket'
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/dogstatsd.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ class DogStatsDClient {
if (config.url) {
clientConfig.metricsProxyUrl = config.url
} else if (config.port) {
clientConfig.metricsProxyUrl = new URL(format({
clientConfig.metricsProxyUrl = format({
protocol: 'http:',
hostname: config.hostname || 'localhost',
port: config.port
}))
})
}

return clientConfig
Expand Down
7 changes: 6 additions & 1 deletion packages/dd-trace/src/startup-log.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const { format } = require('url')
const { info, warn } = require('./log/writer')

const os = require('os')
Expand Down Expand Up @@ -54,7 +55,11 @@ function startupLog ({ agentError } = {}) {
}

function tracerInfo () {
const url = config.url || `http://${config.hostname || 'localhost'}:${config.port}`
const url = config.url || format({
protocol: 'http:',
hostname: config.hostname || 'localhost',
port: config.port
})

const out = {
[inspect.custom] () {
Expand Down

0 comments on commit 80565db

Please sign in to comment.