Skip to content

Commit c8e61ac

Browse files
Update Sentry to 9.6.1 (#1793)
1 parent bf1f952 commit c8e61ac

File tree

67 files changed

+1211
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1211
-625
lines changed

.changeset/calm-monkeys-grab.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"saleor-app-products-feed": patch
3+
"saleor-app-klaviyo": patch
4+
"saleor-app-segment": patch
5+
"saleor-app-avatax": patch
6+
"saleor-app-search": patch
7+
"saleor-app-smtp": patch
8+
"saleor-app-cms": patch
9+
---
10+
11+
Updated Sentry to 9.6.1

apps/avatax/next.config.js

+12-25
Original file line numberDiff line numberDiff line change
@@ -78,34 +78,21 @@ const nextConfig = {
7878
// Ignore opentelemetry warnings - https://github.com/open-telemetry/opentelemetry-js/issues/4173
7979
config.ignoreWarnings = [{ module: /require-in-the-middle/ }];
8080
}
81+
8182
return config;
8283
},
8384
};
8485

85-
const configWithSentry = withSentryConfig(
86-
nextConfig,
87-
{
88-
org: process.env.SENTRY_ORG,
89-
project: process.env.SENTRY_PROJECT,
90-
silent: true,
91-
},
92-
{
93-
hideSourceMaps: true,
94-
widenClientFileUpload: true,
95-
disableLogger: true,
96-
transpileClientSDK: true,
97-
tunnelRoute: "/monitoring",
98-
},
99-
);
100-
101-
const withBundleAnalyzer = withBundleAnalyzerConfig({
86+
const configWithBundleAnalyzer = withBundleAnalyzerConfig({
10287
enabled: process.env.ANALYZE_BUNDLE === "true",
103-
});
104-
105-
const isSentryPropertiesInEnvironment =
106-
process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_PROJECT && process.env.SENTRY_ORG;
88+
})(nextConfig);
10789

108-
const config = isSentryPropertiesInEnvironment ? configWithSentry : nextConfig;
109-
110-
// @ts-expect-error bundle analyzer requires NextConfig when Sentry is returning NextConfigFunction | NextConfigObject
111-
export default withBundleAnalyzer(config);
90+
// Make sure to export sentry config as the last one - https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#apply-instrumentation-to-your-app
91+
export default withSentryConfig(configWithBundleAnalyzer, {
92+
org: process.env.SENTRY_ORG,
93+
project: process.env.SENTRY_PROJECT,
94+
silent: true,
95+
disableLogger: true,
96+
widenClientFileUpload: true,
97+
tunnelRoute: "/monitoring",
98+
});

apps/avatax/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"@saleor/webhook-utils": "workspace:*",
4848
"@sentry/cli": "catalog:",
4949
"@sentry/nextjs": "catalog:",
50-
"@sentry/node": "catalog:",
5150
"@t3-oss/env-nextjs": "0.11.1",
5251
"@trpc/client": "catalog:",
5352
"@trpc/next": "catalog:",

apps/avatax/scripts/run-webhooks-migration.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SaleorCloudAPL } from "@saleor/app-sdk/APL";
22
import { WebhookManifest } from "@saleor/app-sdk/types";
33
import { WebhookMigrationRunner } from "@saleor/webhook-utils";
4-
import * as Sentry from "@sentry/node";
4+
import * as Sentry from "@sentry/nextjs";
55

66
import { env } from "@/env";
77

@@ -16,9 +16,9 @@ const logger = createMigrationScriptLogger("WebhooksMigrationScript");
1616

1717
Sentry.init({
1818
dsn: env.NEXT_PUBLIC_SENTRY_DSN,
19-
enableTracing: false,
2019
environment: env.ENV,
2120
includeLocalVariables: true,
21+
skipOpenTelemetrySetup: true,
2222
ignoreErrors: [],
2323
integrations: [],
2424
});

apps/avatax/sentry.client.config.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
/*
2-
* This file configures the initialization of Sentry on the browser.
3-
* The config you add here will be used whenever a page is visited.
4-
* https://docs.sentry.io/platforms/javascript/guides/nextjs/
5-
*/
6-
71
import * as Sentry from "@sentry/nextjs";
82

93
import { env } from "@/env";
104

115
Sentry.init({
126
dsn: env.NEXT_PUBLIC_SENTRY_DSN,
13-
enableTracing: false,
147
environment: env.ENV,
8+
// we don't follow OTEL guide from Sentry https://docs.sentry.io/platforms/javascript/guides/nextjs/opentelemetry/custom-setup/ as we use Sentry just for error tracking
9+
skipOpenTelemetrySetup: true,
1510
includeLocalVariables: true,
1611
ignoreErrors: ["TRPCClientError"],
1712
integrations: [],

apps/avatax/src/instrumentation.ts

+8
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ export async function register() {
44
if (process.env.NEXT_RUNTIME === "nodejs" && process.env.OTEL_ENABLED === "true") {
55
await import("./instrumentations/otel-node");
66
}
7+
8+
if (process.env.NEXT_RUNTIME === "nodejs" && process.env.NEXT_PUBLIC_SENTRY_DSN) {
9+
await import("./instrumentations/sentry-node");
10+
}
11+
12+
if (process.env.NEXT_RUNTIME === "edge" && process.env.NEXT_PUBLIC_SENTRY_DSN) {
13+
await import("./instrumentations/sentry-edge");
14+
}
715
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Sentry from "@sentry/nextjs";
2+
3+
import { env } from "@/env";
4+
5+
Sentry.init({
6+
dsn: env.NEXT_PUBLIC_SENTRY_DSN,
7+
environment: env.ENV,
8+
// we don't follow OTEL guide from Sentry https://docs.sentry.io/platforms/javascript/guides/nextjs/opentelemetry/custom-setup/ as we use Sentry just for error tracking
9+
skipOpenTelemetrySetup: true,
10+
includeLocalVariables: true,
11+
integrations: [Sentry.extraErrorDataIntegration()],
12+
});

apps/avatax/sentry.edge.config.ts apps/avatax/src/instrumentations/sentry-node.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { env } from "@/env";
44

55
Sentry.init({
66
dsn: env.NEXT_PUBLIC_SENTRY_DSN,
7-
enableTracing: false,
87
environment: env.ENV,
8+
// we don't follow OTEL guide from Sentry https://docs.sentry.io/platforms/javascript/guides/nextjs/opentelemetry/custom-setup/ as we use Sentry just for error tracking
9+
skipOpenTelemetrySetup: true,
910
includeLocalVariables: true,
1011
integrations: [
1112
Sentry.localVariablesIntegration({

apps/avatax/src/modules/avatax/avatax-errors-parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Sentry from "@sentry/nextjs";
1+
import { captureException } from "@sentry/nextjs";
22
import { z } from "zod";
33

44
import { BaseError } from "../../error";
@@ -38,7 +38,7 @@ export class AvataxErrorsParser {
3838
),
3939
});
4040

41-
parse(err: unknown, injectedErrorCapture = Sentry.captureException) {
41+
parse(err: unknown, injectedErrorCapture = captureException) {
4242
const parsedError = AvataxErrorsParser.schema.safeParse(err);
4343

4444
if (!parsedError.success) {

apps/avatax/src/modules/avatax/calculate-taxes/avatax-calculate-taxes-payload-lines-transformer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Sentry from "@sentry/nextjs";
1+
import { captureException } from "@sentry/nextjs";
22
import { LineItemModel } from "avatax/lib/models/LineItemModel";
33
import Decimal from "decimal.js-light";
44

@@ -56,7 +56,7 @@ export class AvataxCalculateTaxesPayloadLinesTransformer {
5656
.toNumber();
5757

5858
if (shippingAmountMinusDiscounts < 0) {
59-
Sentry.captureException(
59+
captureException(
6060
new Error("Saleor returned shipping discounts with higher values than shipping amount"),
6161
);
6262
}

apps/avatax/src/modules/avatax/order-confirmed/avatax-order-confirmed-payload-transformer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Sentry from "@sentry/nextjs";
1+
import { captureException } from "@sentry/nextjs";
22
import { DocumentType } from "avatax/lib/enums/DocumentType";
33
import { err, ok } from "neverthrow";
44

@@ -89,7 +89,7 @@ export class AvataxOrderConfirmedPayloadTransformer {
8989
const addressPayload = this.getSaleorAddress(confirmedOrderEvent);
9090

9191
if (addressPayload.isErr()) {
92-
Sentry.captureException(addressPayload.error);
92+
captureException(addressPayload.error);
9393
this.logger.error("Error while transforming OrderConfirmedPayload", {
9494
error: addressPayload.error,
9595
});

apps/avatax/src/pages/api/trpc/[trpc].ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { withSpanAttributes } from "@saleor/apps-otel/src/with-span-attributes";
22
import { compose } from "@saleor/apps-shared";
3-
import * as Sentry from "@sentry/nextjs";
3+
import { captureException } from "@sentry/nextjs";
44
import * as trpcNext from "@trpc/server/adapters/next";
55

66
import { createLogger } from "../../../logger";
@@ -18,7 +18,7 @@ const handler = trpcNext.createNextApiHandler({
1818
createContext: createTrpcContext,
1919
onError: ({ path, error }) => {
2020
if (error.code === "INTERNAL_SERVER_ERROR") {
21-
Sentry.captureException(error);
21+
captureException(error);
2222
logger.error(`${path} returned error:`, error);
2323
return;
2424
}

apps/avatax/src/pages/api/webhooks/checkout-calculate-taxes.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
22
import { ObservabilityAttributes } from "@saleor/apps-otel/src/observability-attributes";
33
import { withSpanAttributes } from "@saleor/apps-otel/src/with-span-attributes";
44
import { compose } from "@saleor/apps-shared";
5-
import * as Sentry from "@sentry/nextjs";
6-
import { captureException } from "@sentry/nextjs";
5+
import { captureException, setTag } from "@sentry/nextjs";
76

87
import { AppConfigExtractor } from "@/lib/app-config-extractor";
98
import { AppConfigurationLogger } from "@/lib/app-configuration-logger";
@@ -65,7 +64,7 @@ const handler = checkoutCalculateTaxesSyncWebhook.createHandler(async (req, res,
6564
loggerContext.set(ObservabilityAttributes.CHECKOUT_ID, ctx.payload.taxBase.sourceObject.id);
6665

6766
if (payload.version) {
68-
Sentry.setTag(ObservabilityAttributes.SALEOR_VERSION, payload.version);
67+
setTag(ObservabilityAttributes.SALEOR_VERSION, payload.version);
6968
loggerContext.set(ObservabilityAttributes.SALEOR_VERSION, payload.version);
7069
span.setAttribute(ObservabilityAttributes.SALEOR_VERSION, payload.version);
7170
}
@@ -196,7 +195,7 @@ const handler = checkoutCalculateTaxesSyncWebhook.createHandler(async (req, res,
196195
});
197196
}
198197

199-
Sentry.captureException(error);
198+
captureException(error);
200199

201200
span.setStatus({
202201
code: SpanStatusCode.ERROR,

apps/avatax/src/pages/api/webhooks/order-calculate-taxes.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { AuthData } from "@saleor/app-sdk/APL";
33
import { ObservabilityAttributes } from "@saleor/apps-otel/src/observability-attributes";
44
import { withSpanAttributes } from "@saleor/apps-otel/src/with-span-attributes";
55
import { compose } from "@saleor/apps-shared";
6-
import * as Sentry from "@sentry/nextjs";
7-
import { captureException } from "@sentry/nextjs";
6+
import { captureException, setTag } from "@sentry/nextjs";
87

98
import { AppConfigExtractor } from "@/lib/app-config-extractor";
109
import { AppConfigurationLogger } from "@/lib/app-configuration-logger";
@@ -128,7 +127,7 @@ const handler = orderCalculateTaxesSyncWebhook.createHandler(async (req, res, ct
128127
loggerContext.set("orderId", orderId);
129128

130129
if (payload.version) {
131-
Sentry.setTag(ObservabilityAttributes.SALEOR_VERSION, payload.version);
130+
setTag(ObservabilityAttributes.SALEOR_VERSION, payload.version);
132131
loggerContext.set(ObservabilityAttributes.SALEOR_VERSION, payload.version);
133132
span.setAttribute(ObservabilityAttributes.SALEOR_VERSION, payload.version);
134133
}
@@ -369,7 +368,7 @@ const handler = orderCalculateTaxesSyncWebhook.createHandler(async (req, res, ct
369368
});
370369
}
371370

372-
Sentry.captureException(error);
371+
captureException(error);
373372

374373
CalculateTaxesLogRequest.createErrorLog({
375374
sourceId: orderId,

apps/avatax/src/pages/api/webhooks/order-cancelled.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
22
import { ObservabilityAttributes } from "@saleor/apps-otel/src/observability-attributes";
33
import { withSpanAttributes } from "@saleor/apps-otel/src/with-span-attributes";
44
import { compose } from "@saleor/apps-shared";
5-
import * as Sentry from "@sentry/nextjs";
6-
import { captureException } from "@sentry/nextjs";
5+
import { captureException, setTag } from "@sentry/nextjs";
76

87
import { AppConfigExtractor } from "@/lib/app-config-extractor";
98
import { AppConfigurationLogger } from "@/lib/app-configuration-logger";
@@ -54,7 +53,7 @@ const handler = orderCancelledAsyncWebhook.createHandler(async (req, res, ctx) =
5453
subscriptionErrorChecker.checkPayload(payload);
5554

5655
if (payload.version) {
57-
Sentry.setTag(ObservabilityAttributes.SALEOR_VERSION, payload.version);
56+
setTag(ObservabilityAttributes.SALEOR_VERSION, payload.version);
5857
loggerContext.set(ObservabilityAttributes.SALEOR_VERSION, payload.version);
5958
span.setAttribute(ObservabilityAttributes.SALEOR_VERSION, payload.version);
6059
}
@@ -70,7 +69,7 @@ const handler = orderCancelledAsyncWebhook.createHandler(async (req, res, ctx) =
7069
switch (true) {
7170
case error instanceof OrderCancelPayloadOrderError: {
7271
logger.error("Insufficient order data", { error });
73-
Sentry.captureException("Insufficient order data");
72+
captureException("Insufficient order data");
7473

7574
OrderCancelledLogRequest.createErrorLog({
7675
sourceId: payload.order?.id,
@@ -116,7 +115,7 @@ const handler = orderCancelledAsyncWebhook.createHandler(async (req, res, ctx) =
116115
}
117116
case error instanceof SaleorCancelledOrderEvent.ParsingError: {
118117
logger.error("Error parsing order payload", { error });
119-
Sentry.captureException(error);
118+
captureException(error);
120119

121120
OrderCancelledLogRequest.createErrorLog({
122121
sourceId: payload.order?.id,
@@ -138,7 +137,7 @@ const handler = orderCancelledAsyncWebhook.createHandler(async (req, res, ctx) =
138137
}
139138
default: {
140139
logger.error("Unhandled error", { error });
141-
Sentry.captureException(error);
140+
captureException(error);
142141

143142
OrderCancelledLogRequest.createErrorLog({
144143
sourceId: payload.order?.id,

apps/avatax/src/pages/api/webhooks/order-confirmed.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { AuthData } from "@saleor/app-sdk/APL";
33
import { ObservabilityAttributes } from "@saleor/apps-otel/src/observability-attributes";
44
import { withSpanAttributes } from "@saleor/apps-otel/src/with-span-attributes";
55
import { compose } from "@saleor/apps-shared";
6-
import * as Sentry from "@sentry/nextjs";
7-
import { captureException } from "@sentry/nextjs";
6+
import { captureException, setTag } from "@sentry/nextjs";
87

98
import { AppConfigExtractor } from "@/lib/app-config-extractor";
109
import { AppConfigurationLogger } from "@/lib/app-configuration-logger";
@@ -87,7 +86,7 @@ const handler = orderConfirmedAsyncWebhook.createHandler(async (req, res, ctx) =
8786
const { saleorApiUrl, token } = authData;
8887

8988
if (payload.version) {
90-
Sentry.setTag(ObservabilityAttributes.SALEOR_VERSION, payload.version);
89+
setTag(ObservabilityAttributes.SALEOR_VERSION, payload.version);
9190
loggerContext.set(ObservabilityAttributes.SALEOR_VERSION, payload.version);
9291
span.setAttribute(ObservabilityAttributes.SALEOR_VERSION, payload.version);
9392
}
@@ -99,7 +98,7 @@ const handler = orderConfirmedAsyncWebhook.createHandler(async (req, res, ctx) =
9998
const error = confirmedOrderFromPayload.error;
10099

101100
// Capture error when there is problem with parsing webhook payload - it should not happen
102-
Sentry.captureException(error);
101+
captureException(error);
103102
logger.error("Error parsing webhook payload into Saleor order", { error });
104103

105104
OrderConfirmedLogRequest.createErrorLog({
@@ -353,7 +352,7 @@ const handler = orderConfirmedAsyncWebhook.createHandler(async (req, res, ctx) =
353352
});
354353
}
355354
}
356-
Sentry.captureException(error);
355+
captureException(error);
357356
logger.error("Unhandled error executing webhook", { error: error });
358357

359358
OrderConfirmedLogRequest.createErrorLog({
@@ -374,7 +373,7 @@ const handler = orderConfirmedAsyncWebhook.createHandler(async (req, res, ctx) =
374373
}
375374
} catch (error) {
376375
span.recordException(error as Error);
377-
Sentry.captureException(error);
376+
captureException(error);
378377
logger.error("Unhandled error executing webhook", { error: error });
379378

380379
OrderConfirmedLogRequest.createErrorLog({

apps/cms/next.config.js

+10-19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const nextConfig = () => {
2828
"@saleor/react-hook-form-macaw",
2929
],
3030
experimental: {
31+
optimizePackageImports: ["@sentry/nextjs", "@sentry/node"],
3132
bundlePagesExternals: true,
3233
instrumentationHook: true,
3334
},
@@ -42,22 +43,12 @@ const nextConfig = () => {
4243
};
4344
};
4445

45-
const isSentryPropertiesInEnvironment =
46-
process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_PROJECT && process.env.SENTRY_ORG;
47-
48-
const configWithSentry = withSentryConfig(
49-
nextConfig,
50-
{
51-
org: process.env.SENTRY_ORG,
52-
project: process.env.SENTRY_PROJECT,
53-
silent: true,
54-
},
55-
{
56-
hideSourceMaps: true,
57-
widenClientFileUpload: true,
58-
disableLogger: true,
59-
tunnelRoute: "/monitoring",
60-
},
61-
);
62-
63-
export default isSentryPropertiesInEnvironment ? configWithSentry : nextConfig;
46+
// Make sure to export sentry config as the last one - https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#apply-instrumentation-to-your-app
47+
export default withSentryConfig(nextConfig, {
48+
org: process.env.SENTRY_ORG,
49+
project: process.env.SENTRY_PROJECT,
50+
silent: true,
51+
disableLogger: true,
52+
widenClientFileUpload: true,
53+
tunnelRoute: "/monitoring",
54+
});

0 commit comments

Comments
 (0)