Skip to content

Commit

Permalink
feat(logs): Add more logs for Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Oct 31, 2023
1 parent cd266a0 commit 5408ec2
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/init/src/lib/setupSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function setupSentry(): void {
environment: isStableVersion
? import.meta.env.MODE || "production"
: "alpha",
// Increase the default truncation length of 250 to 2500 (x10)
// Increase the default truncation length of 250 to 12500 (x50)
// to have enough details in Sentry
maxValueLength: 2_500,
maxValueLength: 12_500,
});
}
5 changes: 5 additions & 0 deletions packages/init/src/lib/updateSentryContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ export async function updateSentryContext({
if (framework) {
Sentry.setTag("framework", framework);
}

Sentry.setContext("Process", {
"Command used": process.argv.join(" "),
cwd: process.cwd(),
});
}
10 changes: 8 additions & 2 deletions packages/manager/src/auth/PrismicAuthManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ export class PrismicAuthManager {

await this._writePersistedAuthState(authState);
} else {
throw new InternalError("Failed to refresh authentication token.");
throw new InternalError("Failed to refresh authentication token.", {
cause: text,
});
}
} else {
throw new UnauthenticatedError();
Expand All @@ -320,9 +322,9 @@ export class PrismicAuthManager {
"User-Agent": SLICE_MACHINE_USER_AGENT,
},
});
const json = await res.json();

if (res.ok) {
const json = await res.json();
const { value: profile, error } = decode(PrismicUserProfile, json);

if (error) {
Expand All @@ -333,8 +335,12 @@ export class PrismicAuthManager {

return profile;
} else {
const text = await res.text();
throw new InternalError(
"Failed to retrieve profile from the Prismic user service.",
{
cause: text,
},
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/manager/src/lib/fetchGitHubReleaseBodyForRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ const fetchAllGitHubReleases = async (

return value;
} else {
throw new Error(`Invalid GitHub Release response.`);
const text = await res.text();
throw new Error(`Invalid GitHub Release response.`, {
cause: text,
});
}
};

Expand Down
6 changes: 6 additions & 0 deletions packages/manager/src/lib/installDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export const installDependencies = async (
if (!command) {
throw new Error(
"Failed to begin dependency installation (could not parse command)",
{
cause: {
packageManager: args.packageManager,
dependencies: args.dependencies,
},
},
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ export class CustomTypesManager extends BaseManager {
} else if (error instanceof prismicCustomTypesClient.ForbiddenError) {
throw new UnauthorizedError(
"You do not have access to push types to this Prismic repository.",
{
cause: error,
},
);
} else {
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export class PrismicRepositoryManager extends BaseManager {
async readAll(): Promise<PrismicRepository[]> {
const url = new URL("./repositories", API_ENDPOINTS.PrismicUser);
const res = await this._fetch({ url });
const json = await res.json();

if (res.ok) {
const json = await res.json();
const { value: repositories, error } = decode(
t.array(PrismicRepository),
json,
Expand All @@ -81,7 +81,8 @@ export class PrismicRepositoryManager extends BaseManager {

return repositories;
} else {
throw new Error(`Failed to read repositories`, { cause: json });
const text = await res.text();
throw new Error(`Failed to read repositories`, { cause: text });
}
}

Expand Down Expand Up @@ -413,7 +414,9 @@ export class PrismicRepositoryManager extends BaseManager {
const text = await response.text();
throw new Error(text);
default:
throw new Error(`Unexpected status code ${response.status}`);
throw new Error(`Unexpected status code ${response.status}`, {
cause: await response.text(),
});
}
} catch (err) {
console.error("An error happened while pushing your changes");
Expand Down
4 changes: 3 additions & 1 deletion packages/manager/src/managers/project/ProjectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export class ProjectManager extends BaseManager {

if (error) {
// TODO: Write a more friendly and useful message.
throw new Error(`Invalid config. ${error.errors.join(", ")}`);
throw new Error(`Invalid config. ${error.errors.join(", ")}`, {
cause: { rawConfig },
});
}

// Allow cached config reading using `SliceMachineManager.prototype.getProjectConfig()`.
Expand Down
19 changes: 17 additions & 2 deletions packages/manager/src/managers/screenshots/ScreenshotsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export class ScreenshotsManager extends BaseManager {
// Response is not JSON
throw new Error(
`Invalid AWS ACL response from ${awsACLURL}: ${awsACLText}`,
{
cause: error,
},
);
}

Expand All @@ -162,12 +165,16 @@ export class ScreenshotsManager extends BaseManager {
);

if (error) {
throw new Error(`Invalid AWS ACL response from ${awsACLURL}`);
throw new Error(`Invalid AWS ACL response from ${awsACLURL}`, {
cause: error,
});
}

const errorMessage = awsACL.error || awsACL.message || awsACL.Message;
if (errorMessage) {
throw new Error(`Failed to create an AWS ACL: ${errorMessage}`);
throw new Error(`Failed to create an AWS ACL: ${errorMessage}`, {
cause: error,
});
}

this._s3ACL = {
Expand Down Expand Up @@ -302,8 +309,12 @@ export class ScreenshotsManager extends BaseManager {
url: url.toString(),
};
} else {
const text = await res.text();
throw new Error(
`Unable to upload screenshot with status code: ${res.status}`,
{
cause: text,
},
);
}
}
Expand All @@ -319,8 +330,12 @@ export class ScreenshotsManager extends BaseManager {
url: new URL("delete-folder", API_ENDPOINTS.AwsAclProvider),
});
if (!res.ok) {
const text = await res.text();
throw new Error(
`Unable to delete screenshot folder with status code: ${res.status}`,
{
cause: text,
},
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/start-slicemachine/src/lib/sentryErrorHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const node = (name: string, error: unknown): void => {
if (checkIsSentryEnabled()) {
Sentry.withScope(function (scope) {
scope.setTransactionName(name);
Sentry.captureException(error);
Sentry.captureException(error, {
...(error instanceof Error ? { extra: { cause: error.cause } } : {}),
});
});
}
};
Expand Down
3 changes: 3 additions & 0 deletions packages/start-slicemachine/src/lib/setupSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const setupSentry = async (
environment: isStableVersion
? import.meta.env.MODE || "production"
: "alpha",
// Increase the default truncation length of 250 to 12500 (x50)
// to have enough details in Sentry
maxValueLength: 12_500,
});
if (userProfile) {
Sentry.setUser({ id: userProfile.shortId });
Expand Down

0 comments on commit 5408ec2

Please sign in to comment.