Title: Check-ins not working · Issue #8100 · getsentry/sentry-javascript · GitHub
Open Graph Title: Check-ins not working · Issue #8100 · getsentry/sentry-javascript
X Title: Check-ins not working · Issue #8100 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/8100
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Check-ins not working","articleBody":"### Is there an existing issue for this?\n\n- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [X] I have reviewed the documentation https://docs.sentry.io/\n- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/browser\n\n### SDK Version\n\n7.51.2\n\n### Framework Version\n\nNest.js 9.3.9\n\n### Link to Sentry event\n\nhttps://doubble.sentry.io/crons/sync-amplitude/?environment=production&project=4505119808946176\n\n### SDK Setup\n\n```js\r\nSentry.init({\r\n\tintegrations: [\r\n\t\tnew RewriteFrames({\r\n\t\t\troot: global.__rootdir__,\r\n\t\t}),\r\n\t],\r\n\tdsn: process.env.SENTRY_DSN,\r\n\tserverName:\r\n\t\tprocess.env.HOST_REGION || process.env.HOSTNAME\r\n\t\t\t? `${process.env.HOST_REGION ? `${process.env.HOST_REGION}_` : ''}${process.env.HOSTNAME || 'unknown'}`\r\n\t\t\t: undefined,\r\n\trelease: process.env.APP_VERSION,\r\n\tenvironment: process.env.NODE_ENV, // XXX-production\r\n\tshutdownTimeout: 10000,\r\n});\r\n```\n\n### Steps to Reproduce\n\nBasically I follow the documentation:\r\n\r\n```\r\n this.monitorCheckInId = Sentry.captureCheckIn({\r\n monitorSlug: this.monitorSlug,\r\n status: status as any,\r\n ...(this.monitorCheckInId && {\r\n checkInId: this.monitorCheckInId,\r\n }),\r\n });\r\n```\r\n\r\nIf I inspect the crons running I see:\r\n\r\n```\r\n[Nest] 1 - 05/11/2023, 9:15:30 AM LOG [CRON] Will check in with Sentry: in_progress for slug YYYYY...\r\n[Nest] 1 - 05/11/2023, 9:15:30 AM LOG [CRON] Refreshing XXXX view...\r\n[Nest] 1 - 05/11/2023, 9:18:19 AM LOG [CRON] Done\r\n[Nest] 1 - 05/11/2023, 9:18:19 AM LOG [CRON] Will check in with Sentry: ok for slug YYYYY (b3eb88439b864bb8b72ee6d358195789)...\r\n```\r\n\r\nHeres an example of what I did before, and how I refactored the code to use the built-in feature:\r\n\r\n```diff\r\nenum SentryJobStatus {\r\n JobStarted = 'in_progress',\r\n@@ -128,7 +126,9 @@ export abstract class BaseCommand extends CommandRunner {\r\n public async notifyJobCompleted(): Promise\u003cvoid> {\r\n await this.jobCheckin(SentryJobStatus.JobCompleted);\r\n\r\n- Sentry.setContext('completed-job', {});\r\n+ Sentry.configureScope((scope) => {\r\n+ scope.setContext('completed-job', {});\r\n+ });\r\n }\r\n\r\n private async jobCheckin(status: SentryJobStatus, isRunning = true) {\r\n@@ -142,43 +142,30 @@ export abstract class BaseCommand extends CommandRunner {\r\n\r\n- Sentry.setContext('monitor', {\r\n- slug: this.monitorSlug,\r\n+ Sentry.configureScope((scope) => {\r\n+ scope.setContext('monitor', {\r\n+ slug: this.monitorSlug,\r\n+ });\r\n });\r\n\r\n- const endpointUrl = `https://sentry.io/api/0/organizations/XXXX/monitors/${this.monitorSlug}/checkins${\r\n- isRunning ? `/${this.monitorCheckInId ? this.monitorCheckInId : `/latest`}` : ''\r\n- }/`;\r\n-\r\n- this.log(`Will check in with Sentry: ${status}...`);\r\n- await fetch(endpointUrl, {\r\n- method: !isRunning ? 'POST' : 'PUT',\r\n- headers: {\r\n- Authorization: `DSN ${dsn}`,\r\n- 'Content-Type': 'application/json',\r\n- },\r\n- body: JSON.stringify({ status }),\r\n- })\r\n- .then(async (response) => {\r\n- if (!response.ok) {\r\n- return response.text().then((body) => {\r\n- throw new Error(`Request failed with status ${response.status}: ${body}`);\r\n- });\r\n- }\r\n- return response.json();\r\n- })\r\n- .then((data) => {\r\n- this.log(`Checked in with Sentry: ${data.id}`);\r\n- this.monitorCheckInId = data.id;\r\n- })\r\n- .catch((error) => {\r\n- this.error(`Job monitoring HTTP error. Status: ${error}`);\r\n- });\r\n+ this.log(\r\n+ `Will check in with Sentry: ${status} for slug ${this.monitorSlug}${\r\n+ this.monitorCheckInId ? ` (${this.monitorCheckInId})` : ''\r\n+ }...`,\r\n+ );\r\n+\r\n+ this.monitorCheckInId = Sentry.captureCheckIn({\r\n+ monitorSlug: this.monitorSlug,\r\n+ status: status as any,\r\n+ ...(isRunning && {\r\n+ checkInId: this.monitorCheckInId,\r\n+ }),\r\n+ });\r\n }\r\n```\n\n### Expected Result\n\nIt should report OK in the Cron status console, because they are all running as expected\n\n### Actual Result\n\nThey all report \"MISSED\"\r\n\r\n\r\n\r\nIt worked fine when we weren't using the Sentry SDK but just sending normal http requests.","author":{"url":"https://github.com/simplenotezy","@type":"Person","name":"simplenotezy"},"datePublished":"2023-05-11T09:28:16Z","url":"https://github.com/getsentry/sentry-javascript/issues/8100"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:964ecfdd-9fbd-d886-6df7-7b5b2f9a4651 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C248:3B6A24:97E853:CE5279:6B053DA5 |
| html-safe-nonce | 875f80abbd6c742c6653101045a3704ab204aa9abcf64e1d57688d0003cb8244 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjQ4OjNCNkEyNDo5N0U4NTM6Q0U1Mjc5OjZCMDUzREE1IiwidmlzaXRvcl9pZCI6IjcwMjI1NTA0MzczNDE3NzMyMjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6e76e8d9340598659c06b043589c8b6034d8d2e75e60c95f8e5b0b98fc8260bd |
| hovercard-subject-tag | issue:1705428978 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/8100/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4eb02b51f68c887063bd5ca3f61e3b921a8f8f7775a478f4b20bd3a6aad9ce16/getsentry/sentry-javascript/issues/8100 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4eb02b51f68c887063bd5ca3f61e3b921a8f8f7775a478f4b20bd3a6aad9ce16/getsentry/sentry-javascript/issues/8100 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | simplenotezy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 854d880890b5e847b3fce9d1b31f032107baeddeebad2aa379c48aa4f1451f6b |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 220e980097d94ce616d5d11fbd5316d208e3fc93 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width