Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROF-8714: Code hotspots and endpoint collection shouldn't be enabled on Windows #3944

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/dd-trace/src/profiling/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,24 @@ class Config {
logger.warn(`${deprecatedEnvVarName} is deprecated. Use DD_PROFILING_${shortVarName} instead.`)
}
}
// Profiler sampling contexts are not available on Windows, so features
// depending on those (code hotspots and endpoint collection) need to default
// to false on Windows.
const samplingContextsAvailable = process.platform !== 'win32'
function checkOptionAllowed (option, description) {
if (option && !samplingContextsAvailable) {
throw new Error(`${description} not supported on ${process.platform}.`)
}
}
this.flushInterval = flushInterval
this.uploadTimeout = uploadTimeout
this.sourceMap = sourceMap
this.debugSourceMaps = isTrue(coalesce(options.debugSourceMaps, DD_PROFILING_DEBUG_SOURCE_MAPS, false))
this.endpointCollectionEnabled = isTrue(coalesce(options.endpointCollection,
DD_PROFILING_ENDPOINT_COLLECTION_ENABLED,
DD_PROFILING_EXPERIMENTAL_ENDPOINT_COLLECTION_ENABLED, true))
DD_PROFILING_EXPERIMENTAL_ENDPOINT_COLLECTION_ENABLED, samplingContextsAvailable))
logExperimentalVarDeprecation('ENDPOINT_COLLECTION_ENABLED')
checkOptionAllowed(this.endpointCollectionEnabled, 'Endpoint collection')

this.pprofPrefix = pprofPrefix
this.v8ProfilerBugWorkaroundEnabled = isTrue(coalesce(options.v8ProfilerBugWorkaround,
Expand Down Expand Up @@ -148,8 +158,9 @@ class Config {

this.codeHotspotsEnabled = isTrue(coalesce(options.codeHotspotsEnabled,
DD_PROFILING_CODEHOTSPOTS_ENABLED,
DD_PROFILING_EXPERIMENTAL_CODEHOTSPOTS_ENABLED, true))
DD_PROFILING_EXPERIMENTAL_CODEHOTSPOTS_ENABLED, samplingContextsAvailable))
logExperimentalVarDeprecation('CODEHOTSPOTS_ENABLED')
checkOptionAllowed(this.codeHotspotsEnabled, 'Code hotspots')

this.cpuProfilingEnabled = isTrue(coalesce(options.cpuProfilingEnabled,
DD_PROFILING_EXPERIMENTAL_CPU_ENABLED, false))
Expand Down
38 changes: 36 additions & 2 deletions packages/dd-trace/test/profiling/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const WallProfiler = require('../../src/profiling/profilers/wall')
const SpaceProfiler = require('../../src/profiling/profilers/space')
const { ConsoleLogger } = require('../../src/profiling/loggers/console')

const samplingContextsAvailable = process.platform !== 'win32'

describe('config', () => {
let Config
let env
Expand Down Expand Up @@ -48,7 +50,7 @@ describe('config', () => {
expect(config.logger).to.be.an.instanceof(ConsoleLogger)
expect(config.exporters[0]).to.be.an.instanceof(AgentExporter)
expect(config.profilers[0]).to.be.an.instanceof(WallProfiler)
expect(config.profilers[0].codeHotspotsEnabled()).true
expect(config.profilers[0].codeHotspotsEnabled()).to.equal(samplingContextsAvailable)
expect(config.profilers[1]).to.be.an.instanceof(SpaceProfiler)
expect(config.v8ProfilerBugWorkaroundEnabled).true
expect(config.cpuProfilingEnabled).false
Expand Down Expand Up @@ -142,7 +144,7 @@ describe('config', () => {
expect(config.profilers).to.be.an('array')
expect(config.profilers.length).to.equal(1)
expect(config.profilers[0]).to.be.an.instanceOf(WallProfiler)
expect(config.profilers[0].codeHotspotsEnabled()).true
expect(config.profilers[0].codeHotspotsEnabled()).to.equal(samplingContextsAvailable)
expect(config.v8ProfilerBugWorkaroundEnabled).false
expect(config.cpuProfilingEnabled).true
})
Expand Down Expand Up @@ -181,6 +183,10 @@ describe('config', () => {
})

it('should prioritize options over env variables', () => {
if (!samplingContextsAvailable) {
return
}

process.env = {
DD_PROFILING_PROFILERS: 'space',
DD_PROFILING_ENDPOINT_COLLECTION_ENABLED: '1'
Expand All @@ -202,6 +208,10 @@ describe('config', () => {
})

it('should prioritize non-experimental env variables and warn about experimental ones', () => {
if (!samplingContextsAvailable) {
return
}

process.env = {
DD_PROFILING_PROFILERS: 'wall',
DD_PROFILING_CODEHOTSPOTS_ENABLED: '0',
Expand Down Expand Up @@ -238,6 +248,30 @@ describe('config', () => {
expect(config.profilers[0].endpointCollectionEnabled()).false
})

it('should prevent accidentally enabling code hotspots', () => {
if (samplingContextsAvailable) {
return
}

const options = {
codeHotspotsEnabled: true
}
// eslint-disable-next-line no-new
expect(() => { new Config(options) }).to.throw('Code hotspots not supported on ')
})

it('should prevent accidentally enabling endpoint collection', () => {
if (samplingContextsAvailable) {
return
}

const options = {
endpointCollection: true
}
// eslint-disable-next-line no-new
expect(() => { new Config(options) }).to.throw('Endpoint collection not supported on ')
})

it('should support tags', () => {
const tags = {
env: 'dev'
Expand Down