Skip to content

Commit 12e7487

Browse files
authored
Reduce frequency of temporal telemetry (#2914)
1 parent a437460 commit 12e7487

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

services/archetypes/worker/src/activities/activityInterceptor.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ActivityMonitoringInterceptor implements ActivityInboundCallsInterc
1818
activity_type: this.ctx.info.activityType,
1919
}
2020

21-
const timer = telemetry.timer('temporal.activity_execution_duration', tags)
21+
const start = new Date()
2222

2323
try {
2424
const res = await next(input)
@@ -36,7 +36,13 @@ export class ActivityMonitoringInterceptor implements ActivityInboundCallsInterc
3636
log.error(err, 'Error while processing an activity!')
3737
throw err
3838
} finally {
39-
timer.stop()
39+
const end = new Date()
40+
const duration = end.getTime() - start.getTime()
41+
42+
// Only send telemetry if duration is more than 2 hours
43+
if (duration > 2 * 60 * 60 * 1000) {
44+
telemetry.distribution('temporal.activity_execution_duration', duration, tags)
45+
}
4046
}
4147
}
4248
}

services/archetypes/worker/src/interceptors.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export class WorkflowMonitoringInterceptor implements WorkflowInboundCallsInterc
3434
} finally {
3535
const end = new Date()
3636
const duration = end.getTime() - start.getTime()
37-
await activity.telemetryDistribution('temporal.workflow_execution_duration', duration, tags)
37+
38+
// Only send telemetry if duration is more than 2 hours
39+
if (duration > 3 * 60 * 60 * 1000) {
40+
await activity.telemetryDistribution('temporal.workflow_execution_duration', duration, tags)
41+
}
3842
}
3943
}
4044
}

0 commit comments

Comments
 (0)