Skip to content

Commit 2b4d7d8

Browse files
feat: Added profiling configuration (#3733)
1 parent dea410b commit 2b4d7d8

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

lib/config/default.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,47 @@ defaultConfig.definition = () => {
12531253
default: true
12541254
}
12551255
},
1256+
/**
1257+
* Controls the behavior of the profiler.
1258+
*/
1259+
profiling: {
1260+
enabled: {
1261+
formatter: boolean,
1262+
default: false
1263+
},
1264+
/**
1265+
* Harvest and ingest profile data every n milliseconds
1266+
*/
1267+
sample_interval_ms: {
1268+
formatter: int,
1269+
default: 100
1270+
},
1271+
/**
1272+
* List of profile type names to enable. Only cpu and heap profiles are currently supported
1273+
*/
1274+
include: {
1275+
formatter: array,
1276+
default: ['cpu', 'heap']
1277+
},
1278+
/**
1279+
* Restart the cpu profiler every n milliseconds to report its data
1280+
*/
1281+
cpu: {
1282+
report_interval_ms: {
1283+
formatter: int,
1284+
default: 0
1285+
}
1286+
},
1287+
/**
1288+
* Restart heap profiler every n milliseconds to report its data
1289+
*/
1290+
heap: {
1291+
report_interval_ms: {
1292+
formatter: int,
1293+
default: 0
1294+
}
1295+
}
1296+
},
12561297

12571298
/**
12581299
* When `true`, the AWS Lambda instrumentation will add the necessary

test/unit/config/config-defaults.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,14 @@ test('with default properties', async (t) => {
346346
})
347347
})
348348

349+
await t.test('profiling defaults', () => {
350+
assert.equal(configuration.profiling.enabled, false)
351+
assert.equal(configuration.profiling.sample_interval_ms, 100)
352+
assert.deepEqual(configuration.profiling.include, ['cpu', 'heap'])
353+
assert.equal(configuration.profiling.cpu.report_interval_ms, 0)
354+
assert.equal(configuration.profiling.heap.report_interval_ms, 0)
355+
})
356+
349357
await t.test('opentelemetry', () => {
350358
const otel = configuration.opentelemetry
351359
assert.equal(otel.enabled, false)

test/unit/config/config-env.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,23 @@ test('when overriding configuration values via environment variables', async (t)
479479
end()
480480
})
481481

482+
await t.test('should set the profiling options', (t, end) => {
483+
const env = {
484+
NEW_RELIC_PROFILING_ENABLED: true,
485+
NEW_RELIC_PROFILING_INCLUDE: ['heap'],
486+
NEW_RELIC_PROFILING_SAMPLE_INTERVAL_MS: 150,
487+
NEW_RELIC_PROFILING_HEAP_REPORT_INTERVAL_MS: 200
488+
}
489+
490+
idempotentEnv(env, (tc) => {
491+
assert(tc.profiling.enabled, true)
492+
assert.deepStrictEqual(tc.profiling.include, ['heap'])
493+
assert.equal(tc.profiling.sample_interval_ms, 150)
494+
assert.equal(tc.profiling.heap.report_interval_ms, 200)
495+
end()
496+
})
497+
})
498+
482499
await t.test('should pick up the log filepath', (t, end) => {
483500
idempotentEnv({ NEW_RELIC_LOG: '/highway/to/the/danger/zone' }, (tc) => {
484501
assert.equal(tc.logging.filepath, '/highway/to/the/danger/zone')

test/unit/config/config.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,4 +537,23 @@ test('distributed tracing samplers', async (t) => {
537537
assert.equal(configuration.distributed_tracing.sampler.partial_granularity.enabled, true)
538538
assert.equal(configuration.distributed_tracing.sampler.partial_granularity.type, 'reduced')
539539
})
540+
541+
await t.test('should set cpu profiling options', () => {
542+
const config = {
543+
profiling: {
544+
enabled: true,
545+
sample_interval_ms: 200,
546+
include: ['cpu'],
547+
cpu: {
548+
report_interval_ms: 50
549+
}
550+
}
551+
}
552+
553+
const configuration = Config.initialize(config)
554+
assert.equal(configuration.profiling.enabled, true)
555+
assert.equal(configuration.profiling.sample_interval_ms, 200)
556+
assert.deepEqual(configuration.profiling.include, ['cpu'])
557+
assert.equal(configuration.profiling.cpu.report_interval_ms, 50)
558+
})
540559
})

0 commit comments

Comments
 (0)