Skip to content

Commit

Permalink
feat(app): datadog front-end logging cleanup (passportxyz#187)
Browse files Browse the repository at this point in the history
Co-authored-by: David Hayes <[email protected]>
  • Loading branch information
farque65 and david-focused authored Jun 9, 2022
1 parent 4fddf89 commit ed788d7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
8 changes: 7 additions & 1 deletion app/components/ProviderCards/BrightidCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function BrightIdCard(): JSX.Element {
const toast = useToast();

const handleFetchCredential = (): void => {
datadogLogs.logger.info("starting provider verification", { provider: providerId });
setCredentialResponseIsLoading(true);
fetchVerifiableCredential(
iamUrl,
Expand All @@ -66,13 +67,16 @@ export default function BrightIdCard(): JSX.Element {
credential: verified.credential,
});
})
.catch((e: any): void => {})
.catch((e: any): void => {
datadogRum.addError(`Error ${e}`, { provider: providerId });
})
.finally((): void => {
setCredentialResponseIsLoading(false);
});
};

async function handleSponsorship(): Promise<void> {
datadogLogs.logger.info("Sponsoring user on BrightId", { provider: providerId });
setCredentialResponseIsLoading(true);
const res = fetch(`${process.env.NEXT_PUBLIC_DPOPP_PROCEDURE_URL?.replace(/\/*?$/, "")}/brightid/sponsor`, {
method: "POST",
Expand Down Expand Up @@ -112,6 +116,7 @@ export default function BrightIdCard(): JSX.Element {
</div>
),
});
datadogLogs.logger.info("Successfully sponsored user on BrightId", { provider: providerId });
} else {
toast({
title: "Failure",
Expand All @@ -120,6 +125,7 @@ export default function BrightIdCard(): JSX.Element {
duration: 9000,
isClosable: true,
});
datadogRum.addError(data?.response?.error || "Failed to sponsor user on BrightId", { provider: providerId });
}
setCredentialResponseIsLoading(false);
setVerificationInProgress(false);
Expand Down
5 changes: 4 additions & 1 deletion app/components/ProviderCards/EnsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function EnsCard(): JSX.Element {
const toast = useToast();

const handleFetchCredential = (): void => {
datadogLogs.logger.info("Saving Stamp", { provider: providerId });
datadogLogs.logger.info("starting provider verification", { provider: providerId });
setCredentialResponseIsLoading(true);
fetchVerifiableCredential(
iamUrl,
Expand All @@ -58,6 +58,8 @@ export default function EnsCard(): JSX.Element {
});
})
.catch((e: any): void => {
datadogLogs.logger.error("1) error providing verification", { error: e, provider: providerId });
console.error("2) error providing verification");
datadogRum.addError(e, { provider: providerId });
})
.finally((): void => {
Expand All @@ -66,6 +68,7 @@ export default function EnsCard(): JSX.Element {
};

const handleUserVerify = (): void => {
datadogLogs.logger.info("Saving Stamp", { provider: providerId });
handleAddStamp(credentialResponse!)
.then(() => datadogLogs.logger.info("Successfully saved Stamp", { provider: providerId }))
.catch((e: any): void => {
Expand Down
1 change: 0 additions & 1 deletion app/components/ProviderCards/FacebookCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export default function FacebookCard(): JSX.Element {
})
.catch((e): void => {
datadogRum.addError(e, { provider: providerId });
throw e;
})
.finally(() => {
setLoading(false);
Expand Down
3 changes: 2 additions & 1 deletion app/components/ProviderCards/GoogleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ export default function GoogleCard(): JSX.Element {
});
})
.catch((e): void => {
datadogLogs.logger.error("1) error providing verification", { error: e, provider: providerId });
console.error("2) error providing verification");
datadogRum.addError(e, { provider: providerId });
throw e;
})
.finally(() => {
setLoading(false);
Expand Down
3 changes: 3 additions & 0 deletions app/components/ProviderCards/PoapCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export default function PoapCard(): JSX.Element {
const handleUserVerify = (): void => {
handleAddStamp(credentialResponse!)
.then(() => datadogLogs.logger.info("Successfully saved Stamp", { provider: providerId }))
.catch((e: any): void => {
datadogLogs.logger.error(`error saving stamp: ${e}`, { provider: providerId });
})
.finally(() => {
setVerificationInProgress(false);
});
Expand Down
7 changes: 4 additions & 3 deletions app/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ datadogRum.init({
clientToken: process.env.NEXT_PUBLIC_DATADOG_CLIENT_TOKEN || "",
site: "datadoghq.eu",
service: "passport-frontend",
env: "review",
env: process.env.NEXT_PUBLIC_DATADOG_ENV || "",
// Specify a version number to identify the deployed version of your application in Datadog
// version: '1.0.0',
sampleRate: 100,
premiumSampleRate: 100,
premiumSampleRate: 0,
trackInteractions: true,
defaultPrivacyLevel: "mask-user-input",
});
Expand All @@ -35,7 +35,8 @@ datadogLogs.init({
site: "datadoghq.eu",
forwardErrorsToLogs: true,
sampleRate: 100,
service: "passport-frontend",
service: `passport-frontend`,
env: process.env.NEXT_PUBLIC_DATADOG_ENV || "",
});

const App: NextPage = () => {
Expand Down

0 comments on commit ed788d7

Please sign in to comment.