| 271 | } |
| 272 | |
| 273 | function buildPayload(metrics, projectName) { |
| 274 | const metricEntries = []; |
| 275 | for (const [name, def] of Object.entries(metrics)) { |
| 276 | if (def.dataPoints.length === 0) continue; |
| 277 | const entry = { name, unit: def.unit }; |
| 278 | if (def.type === 'gauge') { |
| 279 | entry.gauge = { dataPoints: def.dataPoints }; |
| 280 | } else { |
| 281 | entry.sum = { |
| 282 | aggregationTemporality: AGGREGATION_TEMPORALITY_DELTA, |
| 283 | isMonotonic: def.monotonic === true, |
| 284 | dataPoints: def.dataPoints, |
| 285 | }; |
| 286 | } |
| 287 | metricEntries.push(entry); |
| 288 | } |
| 289 | |
| 290 | return { |
| 291 | resourceMetrics: [ |
| 292 | { |
| 293 | resource: { |
| 294 | attributes: toAttributes({ |
| 295 | 'service.name': 'citadel', |
| 296 | 'citadel.project': projectName, |
| 297 | }), |
| 298 | }, |
| 299 | scopeMetrics: [ |
| 300 | { |
| 301 | scope: { name: SCOPE_NAME, version: SCOPE_VERSION }, |
| 302 | metrics: metricEntries, |
| 303 | }, |
| 304 | ], |
| 305 | }, |
| 306 | ], |
| 307 | }; |
| 308 | } |
| 309 | |
| 310 | function resolveEndpoint(raw) { |
| 311 | const url = new URL(raw); |