Skip to content

Commit 5107dac

Browse files
authored
feat: only add host tag to profiles when DD_TRACE_REPORT_HOSTNAME is set (#7494)
1 parent 24c71b6 commit 5107dac

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

packages/dd-trace/src/profiling/config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
const os = require('os')
43
const path = require('path')
54
const { pathToFileURL } = require('url')
65

@@ -53,7 +52,6 @@ class Config {
5352
DD_TAGS,
5453
} = getProfilingEnvValues()
5554

56-
const host = os.hostname()
5755
// Must be longer than one minute so pad with five seconds
5856
const flushInterval = options.interval ?? (Number(DD_PROFILING_UPLOAD_PERIOD) * 1000 || 65 * 1000)
5957
const uploadTimeout = options.uploadTimeout ?? (Number(DD_PROFILING_UPLOAD_TIMEOUT) || 60 * 1000)
@@ -62,7 +60,6 @@ class Config {
6260
// TODO: Remove the fallback. Just use the value from the config.
6361
this.service = options.service || 'node'
6462
this.env = options.env
65-
this.host = host
6663
this.functionname = AWS_LAMBDA_FUNCTION_NAME
6764

6865
this.version = options.version
@@ -71,7 +68,7 @@ class Config {
7168
tagger.parse(options.tags),
7269
tagger.parse({
7370
env: options.env,
74-
host,
71+
host: options.reportHostname ? require('os').hostname() : undefined,
7572
service: this.service,
7673
version: this.version,
7774
functionname: AWS_LAMBDA_FUNCTION_NAME,

packages/dd-trace/src/profiling/profiler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Profiler extends EventEmitter {
7676
repositoryUrl,
7777
commitSHA,
7878
injectionEnabled,
79+
reportHostname,
7980
} = config
8081
const { enabled, sourceMap, exporters } = config.profiling
8182
const { heartbeatInterval } = config.telemetry
@@ -112,6 +113,7 @@ class Profiler extends EventEmitter {
112113
libraryInjected,
113114
activation,
114115
heartbeatInterval,
116+
reportHostname,
115117
}
116118

117119
return this._start(options).catch((err) => {

packages/dd-trace/test/profiling/config.spec.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ describe('config', () => {
7171

7272
assert.deepStrictEqual(config.tags, {
7373
service: 'node',
74-
host: os.hostname(),
7574
})
7675

7776
assert.ok(config.logger instanceof ConsoleLogger)
@@ -94,12 +93,13 @@ describe('config', () => {
9493
profilers: 'space,wall',
9594
url: 'http://localhost:1234/',
9695
codeHotspotsEnabled: false,
96+
reportHostname: true,
9797
}
9898

9999
const config = new Config(options)
100100

101101
assert.strictEqual(config.service, options.service)
102-
assert.strictEqual(typeof config.host, 'string')
102+
assert.strictEqual(typeof config.tags.host, 'string')
103103
assert.strictEqual(config.version, options.version)
104104
assert.ok(typeof config.tags === 'object' && config.tags !== null)
105105
assert.strictEqual(typeof config.tags.host, 'string')
@@ -121,6 +121,28 @@ describe('config', () => {
121121
}
122122
})
123123

124+
it('should not include host tag when reportHostname is false', () => {
125+
const config = new Config({ reportHostname: false })
126+
127+
assert.strictEqual(config.tags.host, undefined)
128+
assert.ok(!('host' in config.tags))
129+
})
130+
131+
it('should not include host tag when reportHostname is not set', () => {
132+
const config = new Config({})
133+
134+
assert.strictEqual(config.tags.host, undefined)
135+
assert.ok(!('host' in config.tags))
136+
})
137+
138+
it('should include host tag when reportHostname is true', () => {
139+
const config = new Config({ reportHostname: true })
140+
141+
assert.strictEqual(typeof config.tags.host, 'string')
142+
assert.ok(config.tags.host.length > 0)
143+
assert.strictEqual(config.tags.host, os.hostname())
144+
})
145+
124146
it('should filter out invalid profilers', () => {
125147
const errors = []
126148
const options = {
@@ -444,7 +466,7 @@ describe('config', () => {
444466
})
445467

446468
it('should enable OOM heap profiler by default and use process as default strategy', () => {
447-
const config = new Config()
469+
const config = new Config({ reportHostname: true })
448470

449471
if (oomMonitoringSupported) {
450472
assert.deepStrictEqual(config.oomMonitoring, {
@@ -456,7 +478,7 @@ describe('config', () => {
456478
process.execPath,
457479
path.normalize(path.join(__dirname, '../../src/profiling', 'exporter_cli.js')),
458480
'http://127.0.0.1:8126/',
459-
`host:${config.host},service:node,snapshot:on_oom`,
481+
`host:${config.tags.host},service:node,snapshot:on_oom`,
460482
'space',
461483
],
462484
})
@@ -513,7 +535,7 @@ describe('config', () => {
513535
DD_PROFILING_EXPERIMENTAL_OOM_EXPORT_STRATEGIES: 'process,async,process',
514536
}
515537

516-
const config = new Config({})
538+
const config = new Config({ reportHostname: true })
517539

518540
assert.deepStrictEqual(config.oomMonitoring, {
519541
enabled: true,
@@ -524,7 +546,7 @@ describe('config', () => {
524546
process.execPath,
525547
path.normalize(path.join(__dirname, '../../src/profiling', 'exporter_cli.js')),
526548
'http://127.0.0.1:8126/',
527-
`host:${config.host},service:node,snapshot:on_oom`,
549+
`host:${config.tags.host},service:node,snapshot:on_oom`,
528550
'space',
529551
],
530552
})

0 commit comments

Comments
 (0)