Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sentry): capture error in Sentry when departure fetch fails #1754

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tavla/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The project integrates with Sentry for error tracking and performance monitoring
2. Add the following lines to your `.env.local` file:

```bash
SENTRY_DSN_URL=your-sentry-dsn-url
NEXT_PUBLIC_SENTRY_DSN_URL=your-sentry-dsn-url
SENTRY_AUTH_TOKEN=your-sentry-auth-token
```

Expand Down
2 changes: 1 addition & 1 deletion tavla/helm/tavla/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ common:
name: sentry
key: auth-token

- name: SENTRY_DSN_URL
- name: NEXT_PUBLIC_SENTRY_DSN_URL
valueFrom:
secretKeyRef:
name: sentry
Expand Down
31 changes: 27 additions & 4 deletions tavla/pages/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { TGetQuayQuery, TStopPlaceQuery } from 'graphql/index'
import { isUnsupportedBrowser } from 'utils/browserDetection'
import { GetServerSideProps } from 'next'
import { SSRQuayQuery, SSRStopPlaceQuery } from 'graphql/ssrQueries'
import * as Sentry from '@sentry/nextjs'

export const getServerSideProps: GetServerSideProps = async (context) => {
const { params, req } = context
Expand Down Expand Up @@ -113,8 +114,19 @@ const getTileData = async (board: TBoard) => {
addMinutesToDate(new Date(), tile.offset ?? 0),
),
}
const data = await fetchQuery(SSRStopPlaceQuery, variables)
return data
try {
const data = await fetchQuery(SSRStopPlaceQuery, variables)
return data
} catch (error) {
Sentry.captureException(error, {
extra: {
message:
'Server-side fetching of departures for stopPlace failed',
queryVariables: variables,
SelmaBergstrand marked this conversation as resolved.
Show resolved Hide resolved
},
})
return null
}
} else if (tile.type === 'quay') {
const variables = {
quayId: tile.placeId,
Expand All @@ -124,8 +136,19 @@ const getTileData = async (board: TBoard) => {
addMinutesToDate(new Date(), tile.offset ?? 0),
),
}
const data = await fetchQuery(SSRQuayQuery, variables)
return data
try {
const data = await fetchQuery(SSRQuayQuery, variables)
return data
} catch (error) {
Sentry.captureException(error, {
extra: {
message:
'Server-side fetching of departures for quay failed',
queryVariables: variables,
},
})
return null
}
} else {
return null
}
Expand Down
2 changes: 1 addition & 1 deletion tavla/sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as Sentry from '@sentry/nextjs'

Sentry.init({
dsn: process.env.SENTRY_DSN_URL,
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN_URL,

tracesSampleRate: 1,

Expand Down
2 changes: 1 addition & 1 deletion tavla/sentry.edge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as Sentry from '@sentry/nextjs'

Sentry.init({
dsn: process.env.SENTRY_DSN_URL,
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN_URL,

tracesSampleRate: 1,

Expand Down
2 changes: 1 addition & 1 deletion tavla/sentry.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as Sentry from '@sentry/nextjs'

Sentry.init({
dsn: process.env.SENTRY_DSN_URL,
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN_URL,

tracesSampleRate: 1,

Expand Down
11 changes: 11 additions & 0 deletions tavla/src/Board/scenarios/QuayTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FetchErrorTypes,
} from 'Board/components/DataFetchingFailed'
import { TTheme } from 'types/settings'
import * as Sentry from '@sentry/nextjs'

export function QuayTile({
placeId,
Expand Down Expand Up @@ -42,6 +43,16 @@ export function QuayTile({
}

if (error || !data || !data.quay) {
if (!error) {
Sentry.captureException(
new Error('Departure fetch for quay returned no data'),
{
extra: {
quayId: placeId,
},
},
)
}
emilielr marked this conversation as resolved.
Show resolved Hide resolved
return (
<Tile>
<DataFetchingFailed
Expand Down
11 changes: 11 additions & 0 deletions tavla/src/Board/scenarios/StopPlaceTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
FetchErrorTypes,
} from 'Board/components/DataFetchingFailed'
import { TTheme } from 'types/settings'
import * as Sentry from '@sentry/nextjs'

export function StopPlaceTile({
placeId,
Expand Down Expand Up @@ -41,6 +42,16 @@ export function StopPlaceTile({
}

if (error || !data || !data.stopPlace) {
if (!error) {
Sentry.captureException(
new Error('Departure fetch for stopPlace returned no data'),
{
extra: {
stopPlaceId: placeId,
},
},
)
}
return (
<Tile>
<DataFetchingFailed
Expand Down
14 changes: 14 additions & 0 deletions tavla/src/Shared/graphql/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TypedDocumentString } from './index'
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
import { formatDateToISO, addMinutesToDate } from 'utils/time'
import { FetchErrorTypes } from 'Board/components/DataFetchingFailed'
import * as Sentry from '@sentry/nextjs'

async function fetchWithTimeout(
url: RequestInfo | URL,
Expand All @@ -21,8 +22,21 @@ async function fetchWithTimeout(
} catch (error) {
clearTimeout(timeoutScheduler)
if (signal.aborted) {
Sentry.captureException(new Error('Departure fetch timed out'), {
extra: {
url: url,
fetchOptions: options,
},
})
throw new Error(FetchErrorTypes.TIMEOUT)
}
Sentry.captureException(error, {
extra: {
message: 'Unknown error occured during fetch',
url: url,
fetchOptions: options,
},
})
throw error
}
}
Expand Down