feat!: API options object support to control sentry handling; removal of logger.sentry.
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/publish Pipeline was successful

# Conflicts:
#	README.md
#	src/logger.ts
#	src/sinks/sentry.ts
#	test/logger.test.ts
This commit is contained in:
2026-08-07 12:10:38 -03:00
parent 6bee3a801d
commit 234226e2bb
5 changed files with 16 additions and 20 deletions
+1 -2
View File
@@ -1,9 +1,8 @@
# [0.10.0](https://git.mifi.dev/mifi/logger/compare/v0.9.3...v0.10.0) (2026-08-05) # [0.10.0](https://git.mifi.dev/mifi/logger/compare/v0.9.3...v0.10.0) (2026-08-05)
### Features ### 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) ## [0.9.3](https://git.mifi.dev/mifi/logger/compare/v0.9.2...v0.9.3) (2026-08-05)
+10 -10
View File
@@ -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: Destination policy when `sentry` is configured and `sinks` is not:
| Runtime + environment | Console | Sentry | | Runtime + environment | Console | Sentry |
| ---------------------- | ------------------------------- | ------------------------------------------- | | ---------------------- | ---------------------- | -------------------------------- |
| Production **browser** | Off | Issues for errors; optional Logs | | Production **browser** | Off | Issues for errors; optional Logs |
| Production **Node** | On (stderr for errors) | 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 | | Staging | On (default `warn`+) | Issues for errors; optional Logs |
| Development | On | Nothing | | Development | On | Nothing |
### Issues vs Logs ### 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) logger.error("expected", err, { suppressSentry: true }); // console only (when enabled)
``` ```
| Option | Effect | | Option | Effect |
| ----------------- | ---------------------------------------------------------------------- | | ---------------------- | ------------------------------------------------------------------------ |
| `sentry: true` | Force this event to Sentry Logs (ignores Logs threshold; not for errors) | | `sentry: true` | Force this event to Sentry Logs (ignores Logs threshold; not for errors) |
| `suppressSentry: true` | Skip creating a Sentry Issue for an error | | `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. 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.
+1 -3
View File
@@ -196,9 +196,7 @@ function resolveSentrySinkOptions(
options: LoggerOptions, options: LoggerOptions,
): { logs: boolean; logLevel: LogLevel } | undefined { ): { logs: boolean; logLevel: LogLevel } | undefined {
if (options.environment === "development") return undefined; if (options.environment === "development") return undefined;
const candidate = options.sentry const candidate = options.sentry ? options.sentry : options.sinks?.find(isSentrySinkLike);
? options.sentry
: options.sinks?.find(isSentrySinkLike);
if (!candidate) return undefined; if (!candidate) return undefined;
if (isSentrySinkLike(candidate)) { if (isSentrySinkLike(candidate)) {
return { return {
+1 -4
View File
@@ -165,10 +165,7 @@ export function toSentryLogPayload(event: LogEvent): {
* logger.error("expected", err, { suppressSentry: true }); * logger.error("expected", err, { suppressSentry: true });
* ``` * ```
*/ */
export function createSentrySink( export function createSentrySink(sentry: SentryLike, options: SentrySinkOptions = {}): SentrySink {
sentry: SentryLike,
options: SentrySinkOptions = {},
): SentrySink {
return { return {
kind: "sentry", kind: "sentry",
options, options,
+3 -1
View File
@@ -180,7 +180,9 @@ describe("createLogger", () => {
logger.info("probe", { sentry: true }); logger.info("probe", { sentry: true });
expect(destination.events).toHaveLength(2); expect(destination.events).toHaveLength(2);
expect( expect(
destination.events.every((event) => !event.sendToSentryIssue && !event.sendToSentryLogs), destination.events.every(
(event) => !event.sendToSentryIssue && !event.sendToSentryLogs,
),
).toBe(true); ).toBe(true);
}); });