-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attach feature flags and envs to Sentry reports
- Loading branch information
Showing
11 changed files
with
168 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"ledger-live-desktop": patch | ||
"live-mobile": patch | ||
--- | ||
|
||
Log experimental and feature flags in Sentry error reports. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
apps/ledger-live-desktop/src/renderer/components/ConnectEnvsToSentry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useEffect } from "react"; | ||
import { ipcRenderer } from "electron"; | ||
import { EnvName, getEnv } from "@ledgerhq/live-common/lib/env"; | ||
import { defaultFeatures, useFeatureFlags } from "@ledgerhq/live-common/lib/featureFlags"; | ||
import { FeatureId } from "@ledgerhq/live-common/lib/types"; | ||
import { enabledExperimentalFeatures } from "../experimental"; | ||
import { setTags } from "../../sentry/renderer"; | ||
|
||
function setSentryTagsEverywhere(tags: { [_: string]: any }) { | ||
ipcRenderer.invoke("set-sentry-tags", tags); | ||
setTags(tags); | ||
} | ||
|
||
const MAX_KEYLEN = 32; | ||
function safekey(k: string) { | ||
if (k.length > MAX_KEYLEN) { | ||
const sep = ".."; | ||
const max = MAX_KEYLEN - sep.length; | ||
const split1 = Math.floor(max / 2); | ||
return k.slice(0, split1) + ".." + k.slice(k.length - (max - split1)); | ||
} | ||
return k; | ||
} | ||
|
||
export const ConnectEnvsToSentry = () => { | ||
const featureFlags = useFeatureFlags(); | ||
useEffect(() => { | ||
// This sync the Sentry tags to include the extra information in context of events | ||
const syncTheTags = () => { | ||
const tags: { [_: string]: any } = {}; | ||
// if there are experimental on, we will add them in tags | ||
enabledExperimentalFeatures().forEach((key: EnvName) => { | ||
tags[safekey(key)] = getEnv(key); | ||
}); | ||
// if there are features on, we will add them in tags | ||
const features: { [key in FeatureId]: boolean } = {}; | ||
Object.keys(defaultFeatures).forEach(key => { | ||
const value = featureFlags.getFeature(key); | ||
if (value && value.enabled !== defaultFeatures[key].enabled) { | ||
features[key] = value.enabled; | ||
} | ||
}); | ||
|
||
Object.keys(features).forEach(key => { | ||
tags[safekey(`f_${key}`)] = features[key]; | ||
}); | ||
|
||
setSentryTagsEverywhere(tags); | ||
}; | ||
// We need to wait firebase to load the data and then we set once for all the tags | ||
setTimeout(syncTheTags, 5000); | ||
// We also try to regularly update them so we are sure to get the correct tags (as these are dynamic) | ||
setInterval(syncTheTags, 60000); | ||
}, []); | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters