Skip to content

Commit

Permalink
Use vercel log drain in merchant apps (#1657)
Browse files Browse the repository at this point in the history
* Use vercel log drain

* Add changeset
  • Loading branch information
poulch authored Dec 16, 2024
1 parent f62403e commit bb269a5
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 34 deletions.
9 changes: 9 additions & 0 deletions .changeset/empty-ligers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"products-feed": patch
"klaviyo": patch
"cms-v2": patch
"search": patch
"smtp": patch
---

Added new `LoggerVercelTransport` support. It will help us send logs to our infrastructure without need of OTEL unstable logs API.
21 changes: 14 additions & 7 deletions apps/cms-v2/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ if (process.env.NODE_ENV !== "production") {
}

if (typeof window === "undefined") {
import("@saleor/apps-logger/node").then(
async ({ attachLoggerOtelTransport, attachLoggerSentryTransport, LoggerContext }) => {
const loggerContext = await import("./logger-context").then((m) => m.loggerContext);
// Don't remove require - it's necessary for proper logger initialization
const {
attachLoggerSentryTransport,
attachLoggerVercelRuntimeTransport,
} = require("@saleor/apps-logger/node");

attachLoggerSentryTransport(rootLogger);
attachLoggerOtelTransport(rootLogger, packageJson.version, loggerContext);
},
);
attachLoggerSentryTransport(rootLogger);

if (process.env.NODE_ENV === "production") {
attachLoggerVercelRuntimeTransport(
rootLogger,
packageJson.version,
require("./logger-context").loggerContext,
);
}
}

export const createLogger = (name: string, params?: Record<string, unknown>) =>
Expand Down
21 changes: 14 additions & 7 deletions apps/klaviyo/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ if (process.env.NODE_ENV !== "production") {
}

if (typeof window === "undefined") {
import("@saleor/apps-logger/node").then(
async ({ attachLoggerOtelTransport, attachLoggerSentryTransport }) => {
const loggerContext = await import("./logger-context").then((m) => m.loggerContext);
// Don't remove require - it's necessary for proper logger initialization
const {
attachLoggerSentryTransport,
attachLoggerVercelRuntimeTransport,
} = require("@saleor/apps-logger/node");

attachLoggerSentryTransport(rootLogger);
attachLoggerOtelTransport(rootLogger, packageJson.version, loggerContext);
},
);
attachLoggerSentryTransport(rootLogger);

if (process.env.NODE_ENV === "production") {
attachLoggerVercelRuntimeTransport(
rootLogger,
packageJson.version,
require("./logger-context").loggerContext,
);
}
}

export const createLogger = (name: string, params?: Record<string, unknown>) =>
Expand Down
21 changes: 14 additions & 7 deletions apps/products-feed/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ if (process.env.NODE_ENV !== "production") {
}

if (typeof window === "undefined") {
import("@saleor/apps-logger/node").then(
async ({ attachLoggerOtelTransport, attachLoggerSentryTransport }) => {
const loggerContext = await import("./logger-context").then((m) => m.loggerContext);
// Don't remove require - it's necessary for proper logger initialization
const {
attachLoggerSentryTransport,
attachLoggerVercelRuntimeTransport,
} = require("@saleor/apps-logger/node");

attachLoggerSentryTransport(rootLogger);
attachLoggerOtelTransport(rootLogger, packageJson.version, loggerContext);
},
);
attachLoggerSentryTransport(rootLogger);

if (process.env.NODE_ENV === "production") {
attachLoggerVercelRuntimeTransport(
rootLogger,
packageJson.version,
require("./logger-context").loggerContext,
);
}
}

export const createLogger = (name: string, params?: Record<string, unknown>) =>
Expand Down
21 changes: 15 additions & 6 deletions apps/search/src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ if (process.env.NODE_ENV !== "production") {
}

if (typeof window === "undefined") {
import("@saleor/apps-logger/node").then(
({ attachLoggerOtelTransport, attachLoggerSentryTransport }) => {
attachLoggerSentryTransport(rootLogger);
attachLoggerOtelTransport(rootLogger, packageJson.version);
},
);
// Don't remove require - it's necessary for proper logger initialization
const {
attachLoggerSentryTransport,
attachLoggerVercelRuntimeTransport,
} = require("@saleor/apps-logger/node");

attachLoggerSentryTransport(rootLogger);

if (process.env.NODE_ENV === "production") {
attachLoggerVercelRuntimeTransport(
rootLogger,
packageJson.version,
require("./logger-context").loggerContext,
);
}
}

export const createLogger = (name: string, params?: Record<string, unknown>) =>
Expand Down
21 changes: 14 additions & 7 deletions apps/smtp/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ if (process.env.NODE_ENV !== "production") {
}

if (typeof window === "undefined") {
import("@saleor/apps-logger/node").then(
async ({ attachLoggerOtelTransport, attachLoggerSentryTransport }) => {
const loggerContext = await import("./logger-context").then((m) => m.loggerContext);
// Don't remove require - it's necessary for proper logger initialization
const {
attachLoggerSentryTransport,
attachLoggerVercelRuntimeTransport,
} = require("@saleor/apps-logger/node");

attachLoggerSentryTransport(rootLogger);
attachLoggerOtelTransport(rootLogger, packageJson.version, loggerContext);
},
);
attachLoggerSentryTransport(rootLogger);

if (process.env.NODE_ENV === "production") {
attachLoggerVercelRuntimeTransport(
rootLogger,
packageJson.version,
require("./logger-context").loggerContext,
);
}
}

export const createLogger = (name: string, params?: Record<string, unknown>) =>
Expand Down

0 comments on commit bb269a5

Please sign in to comment.