feat(logger): add explicit Sentry event channel
This commit is contained in:
@@ -78,6 +78,26 @@ describe("createLogger", () => {
|
||||
consoleError.mockRestore();
|
||||
});
|
||||
|
||||
it("sends explicitly selected production events to Sentry without writing them to the console", () => {
|
||||
const destination = sink();
|
||||
const consoleInfo = vi.spyOn(console, "info").mockImplementation(() => undefined);
|
||||
const logger = createLogger({
|
||||
environment: "production",
|
||||
runtime: "browser",
|
||||
sentry: destination.sink,
|
||||
});
|
||||
logger.sentry.info("Cache warmed");
|
||||
expect(destination.events).toHaveLength(1);
|
||||
expect(destination.events[0]).toMatchObject({
|
||||
level: "info",
|
||||
arguments: ["Cache warmed"],
|
||||
sendToSentry: true,
|
||||
sendToConsole: false,
|
||||
});
|
||||
expect(consoleInfo).not.toHaveBeenCalled();
|
||||
consoleInfo.mockRestore();
|
||||
});
|
||||
|
||||
it("keeps production Node errors on stderr as well as sending them to Sentry", () => {
|
||||
const destination = sink();
|
||||
const consoleError = vi.spyOn(console, "error").mockImplementation(() => undefined);
|
||||
|
||||
+4
-1
@@ -3,7 +3,7 @@ import { createLogger } from "../src/index.js";
|
||||
import { createSentrySink } from "../src/sentry.js";
|
||||
|
||||
describe("createSentrySink", () => {
|
||||
it("captures errors with namespace and structured context, but ignores warnings", () => {
|
||||
it("captures errors and explicitly selected events with namespace and structured context", () => {
|
||||
const scope = { setLevel: vi.fn(), setTag: vi.fn(), setExtras: vi.fn() };
|
||||
const sentry = {
|
||||
withScope: (callback: (value: typeof scope) => void) => callback(scope),
|
||||
@@ -17,8 +17,11 @@ describe("createSentrySink", () => {
|
||||
});
|
||||
const error = new Error("offline");
|
||||
logger.warn("ignored");
|
||||
logger.sentry.info("Cache warmed");
|
||||
logger.error("Request failed", error, { requestId: "req_1" });
|
||||
expect(sentry.captureMessage).toHaveBeenCalledWith("Cache warmed", "info");
|
||||
expect(sentry.captureException).toHaveBeenCalledWith(error);
|
||||
expect(scope.setLevel).toHaveBeenCalledWith("info");
|
||||
expect(scope.setTag).toHaveBeenCalledWith("logger.namespace", "API");
|
||||
expect(scope.setExtras).toHaveBeenCalledWith({ context_0: { requestId: "req_1" } });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user