Skip to content

Commit 1b3cfc4

Browse files
committed
feat: avoid throwing on missingFields
1 parent b30db52 commit 1b3cfc4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/core/src/shared/telemetry/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,9 @@ function validateMetadata(metricName: string, metadata: MetadataObj, fatal: bool
344344
logOrThrow(`"${metricName}" emitted with result=Failed but without the \`reason\` property.`, true)
345345
}
346346

347+
// TODO: there are many instances in the toolkit where we emit metrics with missing fields. If those can be removed, we can configure this to throw in CI.
347348
if (metadata.missingFields) {
348-
logOrThrow(`"${metricName} emitted with missing fields: ${metadata.missingFields}`, false)
349+
logger.warn(msgPrefix + `"${metricName} emitted with missing fields: ${metadata.missingFields}`, false)
349350
}
350351
}
351352

packages/core/src/test/shared/telemetry/util.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ describe('validateMetricEvent', function () {
376376
assertLogsContain('invalid Metric', false, 'warn')
377377
})
378378

379-
it('fails validation for metrics with missing fields when fatal=true', function () {
379+
it('does not fail validation for metrics with missing fields when fatal=true', function () {
380380
const metricEvent: MetricDatum = {
381381
MetricName: 'invalid_metric_missing_fields',
382382
Value: 1,
@@ -387,7 +387,8 @@ describe('validateMetricEvent', function () {
387387
],
388388
} as MetricDatum
389389

390-
assert.throws(() => validateMetricEvent(metricEvent, true), /emitted with missing fields/)
390+
validateMetricEvent(metricEvent, false)
391+
assertLogsContain('invalid Metric', false, 'warn')
391392
})
392393

393394
it('logs warning for metrics with missing fields when fatal=false', function () {

0 commit comments

Comments
 (0)