Skip to content
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
11 changes: 9 additions & 2 deletions integration-tests/profiler/profiler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@ function expectProfileMessagePromise (agent, timeout,
) {
const fileNames = expectedProfileTypes.map(type => `${type}.pprof`)
return agent.assertMessageReceived(({ headers, _, files }) => {
let event
try {
assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`)
assert.propertyVal(files[0], 'originalname', 'event.json')
const event = JSON.parse(files[0].buffer.toString())
event = JSON.parse(files[0].buffer.toString())
assert.propertyVal(event, 'family', 'node')
assert.isString(event.info.profiler.activation)
const ssiEnabled = event.info.profiler.ssi.enabled
assert.isBoolean(ssiEnabled)
if (ssiEnabled) {
assert.isString(event.info.profiler.ssi.mechanism)
}
assert.deepPropertyVal(event, 'attachments', fileNames)
for (const [index, fileName] of fileNames.entries()) {
assert.propertyVal(files[index + 1], 'originalname', fileName)
}
} catch (e) {
e.message += ` ${JSON.stringify({ headers, files })}`
e.message += ` ${JSON.stringify({ headers, files, event })}`
throw e
}
}, timeout, multiplicity)
Expand Down
18 changes: 15 additions & 3 deletions packages/dd-trace/src/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ process.once('beforeExit', () => { profiler.stop() })

module.exports = {
start: config => {
const { service, version, env, url, hostname, port, tags, repositoryUrl, commitSHA } = config
const { sourceMap, exporters } = config.profiling
const { service, version, env, url, hostname, port, tags, repositoryUrl, commitSHA, injectionEnabled } = config
const { enabled, sourceMap, exporters } = config.profiling
const logger = {
debug: (message) => log.debug(message),
info: (message) => log.info(message),
warn: (message) => log.warn(message),
error: (message) => log.error(message)
}

const libraryInjected = injectionEnabled.length > 0
let activation
if (enabled === 'auto') {
activation = 'auto'
} else if (enabled === 'true') {
activation = 'manual'
} else if (injectionEnabled.includes('profiler')) {
activation = 'injection'
} // else activation = undefined

return profiler.start({
service,
version,
Expand All @@ -29,7 +39,9 @@ module.exports = {
port,
tags,
repositoryUrl,
commitSHA
commitSHA,
libraryInjected,
activation
})
},

Expand Down
2 changes: 2 additions & 0 deletions packages/dd-trace/src/profiling/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class Config {
port
})))

this.libraryInjected = options.libraryInjected
this.activation = options.activation
this.exporters = ensureExporters(options.exporters || [
new AgentExporter(this)
], this)
Expand Down
14 changes: 13 additions & 1 deletion packages/dd-trace/src/profiling/exporter_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ function exporterFromURL (url) {
if (url.protocol === 'file:') {
return new FileExporter({ pprofPrefix: fileURLToPath(url) })
} else {
const injectionEnabled = (process.env.DD_INJECTION_ENABLED || '').split(',')
const libraryInjected = injectionEnabled.length > 0
const profilingEnabled = (process.env.DD_PROFILING_ENABLED || '').toLowerCase()
const activation = ['true', '1'].includes(profilingEnabled)
? 'manual'
: profilingEnabled === 'auto'
? 'auto'
: injectionEnabled.includes('profiling')
? 'injection'
: 'unknown'
return new AgentExporter({
url,
logger,
uploadTimeout: timeoutMs
uploadTimeout: timeoutMs,
libraryInjected,
activation
})
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/dd-trace/src/profiling/exporters/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function computeRetries (uploadTimeout) {
}

class AgentExporter {
constructor ({ url, logger, uploadTimeout, env, host, service, version } = {}) {
constructor ({ url, logger, uploadTimeout, env, host, service, version, libraryInjected, activation } = {}) {
this._url = url
this._logger = logger

Expand All @@ -65,6 +65,8 @@ class AgentExporter {
this._host = host
this._service = service
this._appVersion = version
this._libraryInjected = !!libraryInjected
this._activation = activation || 'unknown'
}

export ({ profiles, start, end, tags }) {
Expand Down Expand Up @@ -105,6 +107,11 @@ class AgentExporter {
kernel_version: os.version()
},
profiler: {
activation: this._activation,
ssi: {
enabled: this._libraryInjected,
mechanism: this._libraryInjected ? 'injected_agent' : undefined
},
version
},
runtime: {
Expand Down
5 changes: 4 additions & 1 deletion packages/dd-trace/test/profiling/exporters/agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ describe('exporters/agent', function () {
expect(event.info.platform).to.have.property('kernel_release', os.release())
expect(event.info.platform).to.have.property('kernel_version', os.version())
expect(event.info).to.have.property('profiler')
expect(Object.keys(event.info.profiler)).to.have.length(1)
expect(Object.keys(event.info.profiler)).to.have.length(3)
expect(event.info.profiler).to.have.property('activation', 'unknown')
expect(event.info.profiler).to.have.property('ssi')
expect(event.info.profiler.ssi).to.have.property('enabled', false)
expect(event.info.profiler).to.have.property('version', version)
expect(event.info).to.have.property('runtime')
expect(Object.keys(event.info.runtime)).to.have.length(2)
Expand Down