dd-trace 3.49.0 → 3.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,45 +61,50 @@ class AgentExporter {
61
61
  }
62
62
 
63
63
  export ({ profiles, start, end, tags }) {
64
- const types = Object.keys(profiles)
65
-
66
- const fields = [
67
- ['recording-start', start.toISOString()],
68
- ['recording-end', end.toISOString()],
69
- ['language', 'javascript'],
70
- ['runtime', 'nodejs'],
71
- ['runtime_version', process.version],
72
- ['profiler_version', version],
73
- ['format', 'pprof'],
74
-
75
- ['tags[]', 'language:javascript'],
76
- ['tags[]', 'runtime:nodejs'],
77
- ['tags[]', `runtime_version:${process.version}`],
78
- ['tags[]', `process_id:${process.pid}`],
79
- ['tags[]', `profiler_version:${version}`],
80
- ['tags[]', 'format:pprof'],
81
- ...Object.entries(tags).map(([key, value]) => ['tags[]', `${key}:${value}`])
82
- ]
64
+ const fields = []
83
65
 
84
- this._logger.debug(() => {
85
- const body = fields.map(([key, value]) => ` ${key}: ${value}`).join('\n')
86
- return `Building agent export report: ${'\n' + body}`
66
+ function typeToFile (type) {
67
+ return `${type}.pprof`
68
+ }
69
+
70
+ const event = JSON.stringify({
71
+ attachments: Object.keys(profiles).map(typeToFile),
72
+ start: start.toISOString(),
73
+ end: end.toISOString(),
74
+ family: 'node',
75
+ version: '4',
76
+ tags_profiler: [
77
+ 'language:javascript',
78
+ 'runtime:nodejs',
79
+ `runtime_arch:${process.arch}`,
80
+ `runtime_os:${process.platform}`,
81
+ `runtime_version:${process.version}`,
82
+ `process_id:${process.pid}`,
83
+ `profiler_version:${version}`,
84
+ 'format:pprof',
85
+ ...Object.entries(tags).map(([key, value]) => `${key}:${value}`)
86
+ ].join(',')
87
87
  })
88
88
 
89
- for (let index = 0; index < types.length; index++) {
90
- const type = types[index]
91
- const buffer = profiles[type]
89
+ fields.push(['event', event, {
90
+ filename: 'event.json',
91
+ contentType: 'application/json'
92
+ }])
93
+
94
+ this._logger.debug(() => {
95
+ return `Building agent export report:\n${event}`
96
+ })
92
97
 
98
+ for (const [type, buffer] of Object.entries(profiles)) {
93
99
  this._logger.debug(() => {
94
100
  const bytes = buffer.toString('hex').match(/../g).join(' ')
95
101
  return `Adding ${type} profile to agent export: ` + bytes
96
102
  })
97
103
 
98
- fields.push([`types[${index}]`, type])
99
- fields.push([`data[${index}]`, buffer, {
100
- filename: `${type}.pb.gz`,
101
- contentType: 'application/octet-stream',
102
- knownLength: buffer.length
104
+ const filename = typeToFile(type)
105
+ fields.push([filename, buffer, {
106
+ filename,
107
+ contentType: 'application/octet-stream'
103
108
  }])
104
109
  }
105
110
 
@@ -121,7 +126,11 @@ class AgentExporter {
121
126
  const options = {
122
127
  method: 'POST',
123
128
  path: '/profiling/v1/input',
124
- headers: form.getHeaders(),
129
+ headers: {
130
+ 'DD-EVP-ORIGIN': 'dd-trace-js',
131
+ 'DD-EVP-ORIGIN-VERSION': version,
132
+ ...form.getHeaders()
133
+ },
125
134
  timeout: this._backoffTime * Math.pow(2, attempt)
126
135
  }
127
136