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

Port sentry logic #5570

Merged
merged 34 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ec4cef7
firs code logic + tests
ChristopherDedominici Aug 3, 2024
c5df13c
fix windows test, handle \r
ChristopherDedominici Aug 3, 2024
ab7f042
only push args to subprocess if they are not undefined
ChristopherDedominici Aug 3, 2024
e3d0564
extract logic to send msg to sentry from subprocess file and update t…
ChristopherDedominici Aug 3, 2024
e429d8e
Add general logic explanation
ChristopherDedominici Aug 5, 2024
145f90c
Merge branch 'feature/add-logic-to-send-telemetry-data' of github.com…
ChristopherDedominici Aug 5, 2024
7b80e13
try to fix failing windows test
ChristopherDedominici Aug 5, 2024
87f9d8f
helper function: wait for file to be readable
ChristopherDedominici Aug 5, 2024
3ebfeea
Merge branch 'feature/add-logic-to-send-telemetry-data' of github.com…
ChristopherDedominici Aug 5, 2024
480589a
add comments to explain logic
ChristopherDedominici Aug 6, 2024
ce56aa0
do not initialize Sentry if telemetry consent is not given
ChristopherDedominici Aug 6, 2024
bdb9042
use "cause" as key for linked errors
ChristopherDedominici Aug 6, 2024
d28340e
remove verbose property + add configPath variable
ChristopherDedominici Aug 6, 2024
4f70a72
rename: canSendTelemetry -> shouldBeReported
ChristopherDedominici Aug 6, 2024
afebc1d
move the subprocess code in a single file and modify test config vari…
ChristopherDedominici Aug 6, 2024
26f65b4
adjust test because there is no synch execution in the test runner so…
ChristopherDedominici Aug 6, 2024
d8349b2
improve variables naming and values
ChristopherDedominici Aug 6, 2024
a0d248b
delete redundant test file
ChristopherDedominici Aug 6, 2024
b6b8277
convert all subprocess files in json files
ChristopherDedominici Aug 6, 2024
bed832c
do not send to Sentry errors that are raised from external packages
ChristopherDedominici Aug 7, 2024
d467076
modify function to check for error raised by external package
ChristopherDedominici Aug 9, 2024
a4ee490
add debug module
ChristopherDedominici Aug 9, 2024
de20582
merge from analytics branch
ChristopherDedominici Aug 9, 2024
26aa5d3
Merge branch 'v-next' of github.com:NomicFoundation/hardhat into feat…
ChristopherDedominici Aug 9, 2024
bc63e1a
update pnpm file
ChristopherDedominici Aug 9, 2024
d2685aa
Merge branch 'feature/add-logic-to-send-telemetry-data' of github.com…
ChristopherDedominici Aug 9, 2024
6fca3f8
Merge branch 'v-next' of github.com:NomicFoundation/hardhat into feat…
ChristopherDedominici Aug 15, 2024
4137186
Merge branch 'feature/add-logic-to-send-telemetry-data' of github.com…
ChristopherDedominici Aug 15, 2024
0357b43
add check for ProviderError
ChristopherDedominici Aug 15, 2024
fdfc90f
fix lint error
ChristopherDedominici Aug 15, 2024
f6030a0
Merge branch 'v-next' into features/port-sentry-to-V3
kanej Aug 21, 2024
46ef231
remove fp-ts
ChristopherDedominici Aug 22, 2024
111acc8
Merge branch 'features/port-sentry-to-V3' of github.com:NomicFoundati…
ChristopherDedominici Aug 22, 2024
2f2cc1b
export AnonymizeResult
ChristopherDedominici Aug 22, 2024
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
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion v-next/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"debug": "^4.1.1",
"enquirer": "^2.3.0",
"ethereum-cryptography": "1.1.1",
"fp-ts": "1.19.3",
"tsx": "^4.11.0",
"zod": "^3.23.8"
}
Expand Down
13 changes: 8 additions & 5 deletions v-next/hardhat/src/internal/cli/telemetry/sentry/anonymizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ import * as korean from "ethereum-cryptography/bip39/wordlists/korean.js";
import * as simplifiedChinese from "ethereum-cryptography/bip39/wordlists/simplified-chinese.js";
import * as SPANISH from "ethereum-cryptography/bip39/wordlists/spanish.js";
import * as traditionalChinese from "ethereum-cryptography/bip39/wordlists/traditional-chinese.js";
import { either } from "fp-ts";

interface WordMatch {
index: number;
word: string;
}

type AnonymizeResult =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should export this type as its part of the Anonymizer API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

| { success: true; event: Event }
| { success: false; error: string };

const ANONYMIZED_FILE = "<user-file>";
const ANONYMIZED_MNEMONIC = "<mnemonic>";
const MNEMONIC_PHRASE_LENGTH_THRESHOLD = 7;
Expand All @@ -41,12 +44,12 @@ export class Anonymizer {
* (https://develop.sentry.dev/sdk/event-payloads/exception/), return an
* anonymized version of the event.
*/
public async anonymize(event: any): Promise<either.Either<string, Event>> {
public async anonymize(event: any): Promise<AnonymizeResult> {
if (event === null || event === undefined) {
return either.left("event is null or undefined");
return { success: false, error: "event is null or undefined" };
}
if (typeof event !== "object") {
return either.left("event is not an object");
return { success: false, error: "event is not an object" };
}

const result: Event = {
Expand All @@ -65,7 +68,7 @@ export class Anonymizer {
};
}

return either.right(result);
return { success: true, event: result };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ try {
const anonymizer = new Anonymizer(configPath);
const anonymizedEvent = await anonymizer.anonymize(sentryEvent);

if (anonymizedEvent.isRight()) {
if (anonymizer.raisedByHardhat(anonymizedEvent.value)) {
await sendEventToSentry(anonymizedEvent.value);
if (anonymizedEvent.success) {
if (anonymizer.raisedByHardhat(anonymizedEvent.event)) {
await sendEventToSentry(anonymizedEvent.event);
}
} else {
await sendMsgToSentry(
`There was an error anonymizing an event: ${anonymizedEvent.value}`,
`There was an error anonymizing an event: ${anonymizedEvent.error}`,
);
}
} catch (error: any) {
Expand Down
2 changes: 2 additions & 0 deletions v-next/hardhat/src/internal/cli/telemetry/sentry/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export async function getSubprocessTransport(): Promise<any> {

class SubprocessTransport extends Transports.BaseTransport {
public override async sendEvent(event: Event): Promise<Response> {
// Be aware that any error thrown here will not be propagated to the main process

const extra: { configPath?: string } = event.extra ?? {};
const { configPath } = extra;

Expand Down