Skip to content

Commit

Permalink
Fix logger not connecting to OTEL
Browse files Browse the repository at this point in the history
  • Loading branch information
witoszekdev committed Oct 7, 2024
1 parent 6b63c3f commit c089f3d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 9 deletions.
20 changes: 20 additions & 0 deletions src/lib/logger/create-logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import packageJson from "../../../package.json";
import { attachLoggerConsoleTransport } from "./logger-console-transport";
import { createLogger, logger } from "./logger";
import { attachLoggerOtelTransport } from "./logger-otel-transport";
import { attachLoggerSentryTransport } from "./logger-sentry-transport";
import { loggerContext } from "@/logger-context";

logger.settings.maskValuesOfKeys = ["metadata", "username", "password", "apiKey"];

if (process.env.NODE_ENV !== "production") {
attachLoggerConsoleTransport(logger);
}

if (typeof window === "undefined") {
attachLoggerSentryTransport(logger);

attachLoggerOtelTransport(logger, packageJson.version, loggerContext);
}

export { createLogger, logger };
2 changes: 1 addition & 1 deletion src/pages/api/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { saleorApp } from "../../saleor-app";
import { wrapWithLoggerContext } from "@/lib/logger/logger-context";
import { withOtel } from "@/lib/otel/otel-wrapper";
import { loggerContext } from "@/logger-context";
import { createLogger } from "@/lib/logger/logger";
import { createLogger } from "@/lib/logger/create-logger";

const logger = createLogger("createAppRegisterHandler");

Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/webhooks/transaction-cancel-requested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { getZodErrorMessage } from "@/lib/zod-error";
import { getTransactionActions } from "@/lib/transaction-actions";
import { AppUrlGenerator } from "@/modules/url/app-url-generator";
import { createLogger } from "@/lib/logger/logger";
import { createLogger } from "@/lib/logger/create-logger";
import { wrapWithLoggerContext } from "@/lib/logger/logger-context";
import { withOtel } from "@/lib/otel/otel-wrapper";
import { loggerContext } from "@/logger-context";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/webhooks/transaction-charge-requested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TransactionChargeRequestedDocument,
TransactionChargeRequestedEventFragment,
} from "@/generated/graphql";
import { createLogger } from "@/lib/logger/logger";
import { createLogger } from "@/lib/logger/create-logger";
import {
ChargeRequestedResponse,
chargeRequestedInputSchema,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/webhooks/transaction-initialize-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@/generated/graphql";
import { v7 as uuidv7 } from "uuid";
import { getTransactionActions } from "@/lib/transaction-actions";
import { createLogger } from "@/lib/logger/logger";
import { createLogger } from "@/lib/logger/create-logger";
import { getZodErrorMessage } from "@/lib/zod-error";
import { dataSchema, ResponseType } from "@/modules/validation/sync-transaction";
import { AppUrlGenerator } from "@/modules/url/app-url-generator";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/webhooks/transaction-process-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TransactionProcessSessionDocument,
TransactionProcessSessionEventFragment,
} from "@/generated/graphql";
import { createLogger } from "@/lib/logger/logger";
import { createLogger } from "@/lib/logger/create-logger";
import { dataSchema, ResponseType } from "@/modules/validation/sync-transaction";
import { getZodErrorMessage } from "@/lib/zod-error";
import { getTransactionActions } from "@/lib/transaction-actions";
Expand Down
6 changes: 3 additions & 3 deletions src/pages/api/webhooks/transaction-refund-requested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
TransactionRefundRequestedDocument,
TransactionRefundRequestedEventFragment,
} from "@/generated/graphql";
import { createLogger } from "@/lib/logger/logger";
import { createLogger } from "@/lib/logger/create-logger";
import {
RefundRequestedResponse,
refundRequestedInputSchema,
Expand Down Expand Up @@ -62,9 +62,9 @@ export default wrapWithLoggerContext(
const urlGenerator = new AppUrlGenerator(ctx.authData);

const successResponse: RefundRequestedResponse = {
pspReference: uuidv7(),
// pspReference: uuidv7(),
// TODO: Add result customization
result: "REFUND_SUCCESS",
result: "REFUND_FAILURE",
message: "Great success!",
actions: transactionRefundChecker.checkIfAnotherRefundIsPossible(
amount,
Expand Down
2 changes: 1 addition & 1 deletion src/server/routers/transaction-reporter.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { v7 as uuidv7 } from "uuid";
import { getTransactionActions } from "@/lib/transaction-actions";
import { TRPCError } from "@trpc/server";
import { createLogger } from "@/lib/logger/logger";
import { createLogger } from "@/lib/logger/create-logger";
import { AppUrlGenerator } from "@/modules/url/app-url-generator";

export const transactionReporterRouter = router({
Expand Down

0 comments on commit c089f3d

Please sign in to comment.