Skip to content

Commit

Permalink
PROF-9193: Add system info to profiles (#4085)
Browse files Browse the repository at this point in the history
* Add profiling system info
  • Loading branch information
szegedi authored Feb 26, 2024
1 parent 0d17140 commit f91457f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
40 changes: 38 additions & 2 deletions packages/dd-trace/src/profiling/exporters/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const docker = require('../../exporters/common/docker')
const FormData = require('../../exporters/common/form-data')
const { storage } = require('../../../../datadog-core')
const version = require('../../../../../package.json').version
const os = require('os')
const perf = require('perf_hooks').performance

const containerId = docker.id()

Expand Down Expand Up @@ -50,14 +52,18 @@ function computeRetries (uploadTimeout) {
}

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

const [backoffTries, backoffTime] = computeRetries(uploadTimeout)

this._backoffTime = backoffTime
this._backoffTries = backoffTries
this._env = env
this._host = host
this._service = service
this._appVersion = version
}

export ({ profiles, start, end, tags }) {
Expand All @@ -83,7 +89,37 @@ class AgentExporter {
`profiler_version:${version}`,
'format:pprof',
...Object.entries(tags).map(([key, value]) => `${key}:${value}`)
].join(',')
].join(','),
info: {
application: {
env: this._env,
service: this._service,
start_time: new Date(perf.nodeTiming.nodeStart + perf.timeOrigin).toISOString(),
version: this._appVersion
},
platform: {
hostname: this._host,
kernel_name: os.type(),
kernel_release: os.release(),
kernel_version: os.version()
},
profiler: {
version
},
runtime: {
// Using `nodejs` for consistency with the existing `runtime` tag.
// Note that the event `family` property uses `node`, as that's what's
// proscribed by the Intake API, but that's an internal enum and is
// not customer visible.
engine: 'nodejs',
// strip off leading 'v'. This makes the format consistent with other
// runtimes (e.g. Ruby) but not with the existing `runtime_version` tag.
// We'll keep it like this as we want cross-engine consistency. We
// also aren't changing the format of the existing tag as we don't want
// to break it.
version: process.version.substring(1)
}
}
})

fields.push(['event', event, {
Expand Down
20 changes: 20 additions & 0 deletions packages/dd-trace/test/profiling/exporters/agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ describe('exporters/agent', function () {
'format:pprof',
`runtime-id:${RUNTIME_ID}`
].join(','))
expect(event).to.have.property('info')
expect(event.info).to.have.property('application')
expect(Object.keys(event.info.application)).to.have.length(4)
expect(event.info.application).to.have.property('env', ENV)
expect(event.info.application).to.have.property('service', SERVICE)
expect(event.info.application).to.have.property('start_time')
expect(event.info.application).to.have.property('version', '1.2.3')
expect(event.info).to.have.property('platform')
expect(Object.keys(event.info.platform)).to.have.length(4)
expect(event.info.platform).to.have.property('hostname', HOST)
expect(event.info.platform).to.have.property('kernel_name', os.type())
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(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)
expect(event.info.runtime).to.have.property('engine', 'nodejs')
expect(event.info.runtime).to.have.property('version', process.version.substring(1))

expect(req.files[1]).to.have.property('fieldname', 'wall.pprof')
expect(req.files[1]).to.have.property('originalname', 'wall.pprof')
Expand Down

0 comments on commit f91457f

Please sign in to comment.