Skip to content

Commit d966088

Browse files
authored
chore: temporal alerting (#3426)
Signed-off-by: Uroš Marolt <[email protected]>
1 parent 9cd7c7b commit d966088

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ export class ActivityMonitoringInterceptor implements ActivityInboundCallsInterc
1919
attempts: this.ctx.info.attempt,
2020
}
2121

22+
const log = getServiceChildLogger('activity-interceptor', {
23+
activityType: this.ctx.info.activityType,
24+
activityId: this.ctx.info.activityId,
25+
workflowType: this.ctx.info.workflowType,
26+
taskQueue: this.ctx.info.taskQueue,
27+
workflowId: this.ctx.info.workflowExecution.workflowId,
28+
runId: this.ctx.info.workflowExecution.runId,
29+
})
30+
31+
if (this.ctx.info.attempt > 10) {
32+
log.warn(
33+
{ slackNotify: true },
34+
`Activity ${this.ctx.info.activityType} with id ${this.ctx.info.activityId} was retried ${this.ctx.info.attempt} times!`,
35+
)
36+
}
37+
2238
telemetry.increment('temporal.activity_execution', 1, tags)
2339

2440
const start = new Date()
@@ -27,15 +43,6 @@ export class ActivityMonitoringInterceptor implements ActivityInboundCallsInterc
2743
const res = await next(input)
2844
return res
2945
} catch (err) {
30-
const log = getServiceChildLogger('activity-interceptor', {
31-
activityType: this.ctx.info.activityType,
32-
activityId: this.ctx.info.activityId,
33-
workflowType: this.ctx.info.workflowType,
34-
taskQueue: this.ctx.info.taskQueue,
35-
workflowId: this.ctx.info.workflowExecution.workflowId,
36-
runId: this.ctx.info.workflowExecution.runId,
37-
})
38-
3946
log.error(err, 'Error while processing an activity!')
4047
throw err
4148
} finally {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { getServiceChildLogger } from '@crowd/logging'
12
import telemetry from '@crowd/telemetry'
23

4+
const log = getServiceChildLogger('activity-interceptor')
5+
36
async function telemetryDistribution(
47
name: string,
58
value: number,
@@ -16,4 +19,8 @@ async function telemetryIncrement(
1619
telemetry.increment(name, value, tags)
1720
}
1821

19-
export { telemetryDistribution, telemetryIncrement }
22+
async function slackNotify(message: string) {
23+
log.warn({ slackNotify: true }, message)
24+
}
25+
26+
export { telemetryDistribution, telemetryIncrement, slackNotify }

services/archetypes/worker/src/interceptors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export class WorkflowMonitoringInterceptor implements WorkflowInboundCallsInterc
3434
return result
3535
} catch (err) {
3636
await activity.telemetryIncrement('temporal.workflow_execution_error', 1, tags)
37+
await activity.slackNotify(
38+
`Workflow ${info.workflowType} with id ${info.workflowId} failed with error: ${err.message}!`,
39+
)
3740
throw err
3841
} finally {
3942
const end = new Date()

0 commit comments

Comments
 (0)