From 234226e2bbb79acf3b2686890677bd7326c6a0e0 Mon Sep 17 00:00:00 2001 From: mifi Date: Fri, 7 Aug 2026 12:07:01 -0300 Subject: [PATCH] feat!: API options object support to control sentry handling; removal of `logger.sentry.` # Conflicts: # README.md # src/logger.ts # src/sinks/sentry.ts # test/logger.test.ts --- CHANGELOG.md | 3 +-- README.md | 20 ++++++++++---------- src/logger.ts | 4 +--- src/sinks/sentry.ts | 5 +---- test/logger.test.ts | 4 +++- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdcc59a..ac35126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,8 @@ # [0.10.0](https://git.mifi.dev/mifi/logger/compare/v0.9.3...v0.10.0) (2026-08-05) - ### Features -* **logger:** add explicit Sentry event channel ([44f4716](https://git.mifi.dev/mifi/logger/commit/44f471653e8d4045e87886da1e1bbe04edbd60af)) +- **logger:** add explicit Sentry event channel ([44f4716](https://git.mifi.dev/mifi/logger/commit/44f471653e8d4045e87886da1e1bbe04edbd60af)) ## [0.9.3](https://git.mifi.dev/mifi/logger/compare/v0.9.2...v0.9.3) (2026-08-05) diff --git a/README.md b/README.md index e6c3cab..c782e38 100644 --- a/README.md +++ b/README.md @@ -101,12 +101,12 @@ The Sentry adapter has **no SDK dependency**. Provide the SDK your application a Destination policy when `sentry` is configured and `sinks` is not: -| Runtime + environment | Console | Sentry | -| ---------------------- | ------------------------------- | ------------------------------------------- | -| Production **browser** | Off | Issues for errors; optional Logs | -| Production **Node** | On (stderr for errors) | Issues for errors; optional Logs | -| Staging | On (default `warn`+) | Issues for errors; optional Logs | -| Development | On | Nothing | +| Runtime + environment | Console | Sentry | +| ---------------------- | ---------------------- | -------------------------------- | +| Production **browser** | Off | Issues for errors; optional Logs | +| Production **Node** | On (stderr for errors) | Issues for errors; optional Logs | +| Staging | On (default `warn`+) | Issues for errors; optional Logs | +| Development | On | Nothing | ### Issues vs Logs @@ -143,10 +143,10 @@ logger.info("investigating", { orderId }, { sentry: true }); // force Logs logger.error("expected", err, { suppressSentry: true }); // console only (when enabled) ``` -| Option | Effect | -| ----------------- | ---------------------------------------------------------------------- | -| `sentry: true` | Force this event to Sentry Logs (ignores Logs threshold; not for errors) | -| `suppressSentry: true` | Skip creating a Sentry Issue for an error | +| Option | Effect | +| ---------------------- | ------------------------------------------------------------------------ | +| `sentry: true` | Force this event to Sentry Logs (ignores Logs threshold; not for errors) | +| `suppressSentry: true` | Skip creating a Sentry Issue for an error | A last argument is treated as options only when every key is `sentry` or `suppressSentry`. Prefer the third-argument form when you also pass data. diff --git a/src/logger.ts b/src/logger.ts index 9f4a2f7..4138889 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -196,9 +196,7 @@ function resolveSentrySinkOptions( options: LoggerOptions, ): { logs: boolean; logLevel: LogLevel } | undefined { if (options.environment === "development") return undefined; - const candidate = options.sentry - ? options.sentry - : options.sinks?.find(isSentrySinkLike); + const candidate = options.sentry ? options.sentry : options.sinks?.find(isSentrySinkLike); if (!candidate) return undefined; if (isSentrySinkLike(candidate)) { return { diff --git a/src/sinks/sentry.ts b/src/sinks/sentry.ts index 373e768..0204a38 100644 --- a/src/sinks/sentry.ts +++ b/src/sinks/sentry.ts @@ -165,10 +165,7 @@ export function toSentryLogPayload(event: LogEvent): { * logger.error("expected", err, { suppressSentry: true }); * ``` */ -export function createSentrySink( - sentry: SentryLike, - options: SentrySinkOptions = {}, -): SentrySink { +export function createSentrySink(sentry: SentryLike, options: SentrySinkOptions = {}): SentrySink { return { kind: "sentry", options, diff --git a/test/logger.test.ts b/test/logger.test.ts index 51152fa..51b25ab 100644 --- a/test/logger.test.ts +++ b/test/logger.test.ts @@ -180,7 +180,9 @@ describe("createLogger", () => { logger.info("probe", { sentry: true }); expect(destination.events).toHaveLength(2); expect( - destination.events.every((event) => !event.sendToSentryIssue && !event.sendToSentryLogs), + destination.events.every( + (event) => !event.sendToSentryIssue && !event.sendToSentryLogs, + ), ).toBe(true); });