Skip to content

Commit

Permalink
Set user id in Sentry (#769)
Browse files Browse the repository at this point in the history
Depends on: #768

To improve user events debugging in Sentry, we set the user ID to the
user's bitcoin address.
  • Loading branch information
kkosiorowska authored Nov 26, 2024
2 parents fff5028 + f346c6b commit 1d32751
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dapp/src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useDisconnect,
} from "wagmi"
import { orangeKit } from "#/utils"
import sentry from "#/sentry"
import {
OnErrorCallback,
OrangeKitConnector,
Expand Down Expand Up @@ -75,6 +76,7 @@ export function useWallet(): UseWalletReturn {

dispatch(setAddress(bitcoinAddress))
setAddressInLocalStorage(bitcoinAddress)
sentry.setUser(bitcoinAddress)
},
},
})
Expand All @@ -86,6 +88,7 @@ export function useWallet(): UseWalletReturn {
dispatch(setAddress(undefined))
removeAddressFromLocalStorage()
resetWalletState()
sentry.setUser(undefined)
},
},
})
Expand Down Expand Up @@ -124,6 +127,7 @@ export function useWallet(): UseWalletReturn {

dispatch(setAddress(bitcoinAddress))
setAddressInLocalStorage(bitcoinAddress)
sentry.setUser(bitcoinAddress)
},
},
queryClient,
Expand Down
5 changes: 5 additions & 0 deletions dapp/src/sentry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ const initialize = (dsn: string) => {
})
}

const setUser = (bitcoinAddress: string | undefined) => {
Sentry.setUser(bitcoinAddress ? { id: bitcoinAddress } : null)
}

const captureException = (exception: unknown) =>
Sentry.captureException(exception)

export default {
initialize,
setUser,
captureException,
}

0 comments on commit 1d32751

Please sign in to comment.