Skip to content

Commit 119d80a

Browse files
committed
Code hotspots and endpoint collection don't work on Windows. (#3944)
1 parent 1866643 commit 119d80a

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,24 @@ class Config {
9292
logger.warn(`${deprecatedEnvVarName} is deprecated. Use DD_PROFILING_${shortVarName} instead.`)
9393
}
9494
}
95+
// Profiler sampling contexts are not available on Windows, so features
96+
// depending on those (code hotspots and endpoint collection) need to default
97+
// to false on Windows.
98+
const samplingContextsAvailable = process.platform !== 'win32'
99+
function checkOptionAllowed (option, description) {
100+
if (option && !samplingContextsAvailable) {
101+
throw new Error(`${description} not supported on ${process.platform}.`)
102+
}
103+
}
95104
this.flushInterval = flushInterval
96105
this.uploadTimeout = uploadTimeout
97106
this.sourceMap = sourceMap
98107
this.debugSourceMaps = isTrue(coalesce(options.debugSourceMaps, DD_PROFILING_DEBUG_SOURCE_MAPS, false))
99108
this.endpointCollectionEnabled = isTrue(coalesce(options.endpointCollection,
100109
DD_PROFILING_ENDPOINT_COLLECTION_ENABLED,
101-
DD_PROFILING_EXPERIMENTAL_ENDPOINT_COLLECTION_ENABLED, true))
110+
DD_PROFILING_EXPERIMENTAL_ENDPOINT_COLLECTION_ENABLED, samplingContextsAvailable))
102111
logExperimentalVarDeprecation('ENDPOINT_COLLECTION_ENABLED')
112+
checkOptionAllowed(this.endpointCollectionEnabled, 'Endpoint collection')
103113

104114
this.pprofPrefix = pprofPrefix
105115
this.v8ProfilerBugWorkaroundEnabled = isTrue(coalesce(options.v8ProfilerBugWorkaround,
@@ -148,8 +158,9 @@ class Config {
148158

149159
this.codeHotspotsEnabled = isTrue(coalesce(options.codeHotspotsEnabled,
150160
DD_PROFILING_CODEHOTSPOTS_ENABLED,
151-
DD_PROFILING_EXPERIMENTAL_CODEHOTSPOTS_ENABLED, true))
161+
DD_PROFILING_EXPERIMENTAL_CODEHOTSPOTS_ENABLED, samplingContextsAvailable))
152162
logExperimentalVarDeprecation('CODEHOTSPOTS_ENABLED')
163+
checkOptionAllowed(this.codeHotspotsEnabled, 'Code hotspots')
153164

154165
this.cpuProfilingEnabled = isTrue(coalesce(options.cpuProfilingEnabled,
155166
DD_PROFILING_EXPERIMENTAL_CPU_ENABLED, false))

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

+36-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const WallProfiler = require('../../src/profiling/profilers/wall')
1111
const SpaceProfiler = require('../../src/profiling/profilers/space')
1212
const { ConsoleLogger } = require('../../src/profiling/loggers/console')
1313

14+
const samplingContextsAvailable = process.platform !== 'win32'
15+
1416
describe('config', () => {
1517
let Config
1618
let env
@@ -48,7 +50,7 @@ describe('config', () => {
4850
expect(config.logger).to.be.an.instanceof(ConsoleLogger)
4951
expect(config.exporters[0]).to.be.an.instanceof(AgentExporter)
5052
expect(config.profilers[0]).to.be.an.instanceof(WallProfiler)
51-
expect(config.profilers[0].codeHotspotsEnabled()).true
53+
expect(config.profilers[0].codeHotspotsEnabled()).to.equal(samplingContextsAvailable)
5254
expect(config.profilers[1]).to.be.an.instanceof(SpaceProfiler)
5355
expect(config.v8ProfilerBugWorkaroundEnabled).true
5456
expect(config.cpuProfilingEnabled).false
@@ -142,7 +144,7 @@ describe('config', () => {
142144
expect(config.profilers).to.be.an('array')
143145
expect(config.profilers.length).to.equal(1)
144146
expect(config.profilers[0]).to.be.an.instanceOf(WallProfiler)
145-
expect(config.profilers[0].codeHotspotsEnabled()).true
147+
expect(config.profilers[0].codeHotspotsEnabled()).to.equal(samplingContextsAvailable)
146148
expect(config.v8ProfilerBugWorkaroundEnabled).false
147149
expect(config.cpuProfilingEnabled).true
148150
})
@@ -181,6 +183,10 @@ describe('config', () => {
181183
})
182184

183185
it('should prioritize options over env variables', () => {
186+
if (!samplingContextsAvailable) {
187+
return
188+
}
189+
184190
process.env = {
185191
DD_PROFILING_PROFILERS: 'space',
186192
DD_PROFILING_ENDPOINT_COLLECTION_ENABLED: '1'
@@ -202,6 +208,10 @@ describe('config', () => {
202208
})
203209

204210
it('should prioritize non-experimental env variables and warn about experimental ones', () => {
211+
if (!samplingContextsAvailable) {
212+
return
213+
}
214+
205215
process.env = {
206216
DD_PROFILING_PROFILERS: 'wall',
207217
DD_PROFILING_CODEHOTSPOTS_ENABLED: '0',
@@ -238,6 +248,30 @@ describe('config', () => {
238248
expect(config.profilers[0].endpointCollectionEnabled()).false
239249
})
240250

251+
it('should prevent accidentally enabling code hotspots', () => {
252+
if (samplingContextsAvailable) {
253+
return
254+
}
255+
256+
const options = {
257+
codeHotspotsEnabled: true
258+
}
259+
// eslint-disable-next-line no-new
260+
expect(() => { new Config(options) }).to.throw('Code hotspots not supported on ')
261+
})
262+
263+
it('should prevent accidentally enabling endpoint collection', () => {
264+
if (samplingContextsAvailable) {
265+
return
266+
}
267+
268+
const options = {
269+
endpointCollection: true
270+
}
271+
// eslint-disable-next-line no-new
272+
expect(() => { new Config(options) }).to.throw('Endpoint collection not supported on ')
273+
})
274+
241275
it('should support tags', () => {
242276
const tags = {
243277
env: 'dev'

0 commit comments

Comments
 (0)