Skip to content

Commit fe5b2bc

Browse files
committed
Use new span API for sentry
1 parent 9a50ce4 commit fe5b2bc

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

handler-standalone.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ const wildbuttonApp = require('./wildbutton')
1212

1313
// Create a no-op helper for when Sentry is not used.
1414
let sentryHelper = {
15-
captureException: () => null,
16-
startTransaction: (ctx) => ({
17-
finish: () => null
18-
})
15+
startSpan: (ctx, cb) => cb()
1916
}
2017

2118
const sentryInitCallback = {
@@ -30,8 +27,7 @@ const sentryInitCallback = {
3027
]
3128
})
3229
sentryHelper = {
33-
captureException: Sentry.captureException,
34-
startTransaction: Sentry.startTransaction
30+
startSpan: Sentry.startSpan
3531
}
3632
console.debug('Sentry configured')
3733
}
@@ -48,18 +44,16 @@ wildbuttonApp(asyncEventHandler, sentryInitCallback).listen(process.env.PORT, ()
4844

4945
function initSchedule () {
5046
const wrapHourlyCheck = async () => {
51-
const transaction = sentryHelper.startTransaction({
47+
await sentryHelper.startSpan({
5248
op: 'hourly',
5349
name: 'Hourly check'
50+
}, async () => {
51+
try {
52+
await hourlyCheck()
53+
} catch (e) {
54+
console.error(`Failed to perform hourly check, got error: ${e} in JSON: ${JSON.stringify(e)}`)
55+
}
5456
})
55-
56-
try {
57-
await hourlyCheck()
58-
} catch (e) {
59-
console.error(`Failed to perform hourly check, got error: ${e} in JSON: ${JSON.stringify(e)}`)
60-
} finally {
61-
transaction.finish()
62-
}
6357
}
6458
schedule.scheduleJob('*/10 * * * *', wrapHourlyCheck)
6559
}
@@ -70,10 +64,11 @@ initSchedule()
7064
// to the next event loop to allow us to acknowledge Slack before doing event.
7165
async function asyncEventHandler (eventObject) {
7266
setImmediate(() => {
73-
const transaction = sentryHelper.startTransaction({
67+
sentryHelper.startSpan({
7468
op: `async_${eventObject.method}`,
7569
name: `Async handling of ${eventObject.method}`
70+
}, () => {
71+
asyncEventRouter(eventObject).catch(Sentry.captureException)
7672
})
77-
asyncEventRouter(eventObject).catch(Sentry.captureException).finally(() => transaction.finish())
7873
})
7974
}

0 commit comments

Comments
 (0)