@theholocron/observability 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/core.d.mts +2 -2
- package/dist/core.mjs +2 -2
- package/dist/{create-D9zLARVf.mjs → create-f88HLYhg.mjs} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/logger-BJJRLMAe.mjs +30 -0
- package/dist/{logger-UDRkgXWQ.d.mts → logger-CIRNGqYs.d.mts} +19 -1
- package/dist/logger.d.mts +2 -2
- package/dist/logger.mjs +2 -2
- package/dist/{pino-TxwJ9Q2h.d.mts → pino-DwMkjUai.d.mts} +1 -1
- package/dist/testing.d.mts +71 -0
- package/dist/testing.mjs +69 -0
- package/package.json +14 -2
- package/dist/logger--ic6Hr3c.mjs +0 -10
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ optional:
|
|
|
21
21
|
| `@theholocron/observability/logger` | `pino`, `pino-pretty`, `@axiomhq/pino` |
|
|
22
22
|
| `@theholocron/observability/errors` | `@sentry/node` |
|
|
23
23
|
| `@theholocron/observability/analytics` | `posthog-node` |
|
|
24
|
+
| `@theholocron/observability/testing` | `vitest` |
|
|
24
25
|
|
|
25
26
|
## Usage
|
|
26
27
|
|
|
@@ -60,6 +61,23 @@ For the browser, an edge runtime, or React Native, import
|
|
|
60
61
|
`@theholocron/observability/core` (zero dependencies) and use `ConsoleLogger`
|
|
61
62
|
from `/logger` in place of Pino.
|
|
62
63
|
|
|
64
|
+
Testing code that depends on `Logger` / `ErrorSink` / `AnalyticsSink`? Use the
|
|
65
|
+
spy doubles from `/testing` instead of hand-rolling one per repo:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { fakeLogger, fakeErrorSink } from "@theholocron/observability/testing";
|
|
69
|
+
|
|
70
|
+
const log = fakeLogger();
|
|
71
|
+
const errors = fakeErrorSink();
|
|
72
|
+
await deploy({ logger: log, errors, target: "production" });
|
|
73
|
+
expect(log.info).toHaveBeenCalledWith(expect.objectContaining({ target: "production" }), "deploying");
|
|
74
|
+
expect(errors.captureException).not.toHaveBeenCalled();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
For a non-vitest context that just needs a `Logger` with no output (an
|
|
78
|
+
example, a non-test opt-out path), use `NoopLogger` from `/core` — it
|
|
79
|
+
discards everything, `child()` returns itself.
|
|
80
|
+
|
|
63
81
|
See the [documentation](https://docs.theholocron.dev/observability/) for the
|
|
64
82
|
full API.
|
|
65
83
|
|
package/dist/core.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { a as NoopErrorSink, i as NoopAnalyticsSink, n as CommandSpan, r as ErrorSink, t as AnalyticsSink } from "./sinks-CSEolKcN.mjs";
|
|
2
|
-
import { i as Logger, n as LogEnv, r as LogLevel, t as LOG_LEVELS } from "./logger-
|
|
2
|
+
import { a as NoopLogger, i as Logger, n as LogEnv, r as LogLevel, t as LOG_LEVELS } from "./logger-CIRNGqYs.mjs";
|
|
3
3
|
import { a as redactOptions, i as redactObject, n as REDACT_CENSOR, r as redact, t as REDACTED_PATHS } from "./core-jXa8qbEx.mjs";
|
|
4
|
-
export { type AnalyticsSink, type CommandSpan, type ErrorSink, LOG_LEVELS, type LogEnv, type LogLevel, type Logger, NoopAnalyticsSink, NoopErrorSink, REDACTED_PATHS, REDACT_CENSOR, redact, redactObject, redactOptions };
|
|
4
|
+
export { type AnalyticsSink, type CommandSpan, type ErrorSink, LOG_LEVELS, type LogEnv, type LogLevel, type Logger, NoopAnalyticsSink, NoopErrorSink, NoopLogger, REDACTED_PATHS, REDACT_CENSOR, redact, redactObject, redactOptions };
|
package/dist/core.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as LOG_LEVELS } from "./logger
|
|
1
|
+
import { n as NoopLogger, t as LOG_LEVELS } from "./logger-BJJRLMAe.mjs";
|
|
2
2
|
import { a as redactOptions, i as redactObject, n as REDACT_CENSOR, r as redact, t as REDACTED_PATHS } from "./redact-BMWG62k9.mjs";
|
|
3
3
|
import { n as NoopErrorSink, t as NoopAnalyticsSink } from "./sinks-scWbkOMp.mjs";
|
|
4
|
-
export { LOG_LEVELS, NoopAnalyticsSink, NoopErrorSink, REDACTED_PATHS, REDACT_CENSOR, redact, redactObject, redactOptions };
|
|
4
|
+
export { LOG_LEVELS, NoopAnalyticsSink, NoopErrorSink, NoopLogger, REDACTED_PATHS, REDACT_CENSOR, redact, redactObject, redactOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as NoopErrorSink, i as NoopAnalyticsSink, n as CommandSpan, r as ErrorSink, t as AnalyticsSink } from "./sinks-CSEolKcN.mjs";
|
|
2
2
|
import { t as PostHogSink } from "./posthog-sink-BvVIQrGy.mjs";
|
|
3
|
-
import { i as Logger, n as LogEnv, r as LogLevel, t as LOG_LEVELS } from "./logger-
|
|
3
|
+
import { a as NoopLogger, i as Logger, n as LogEnv, r as LogLevel, t as LOG_LEVELS } from "./logger-CIRNGqYs.mjs";
|
|
4
4
|
import { a as redactOptions, i as redactObject, n as REDACT_CENSOR, r as redact, t as REDACTED_PATHS } from "./core-jXa8qbEx.mjs";
|
|
5
5
|
import { n as scrubError, t as SentrySink } from "./sentry-sink-Dk0H3MG5.mjs";
|
|
6
|
-
import { _ as buildTransport, a as CreateLoggerResult, c as detectEnv, d as isTelemetryDisabled, f as parseLogLevel, g as BuildTransportInput, h as AxiomTransportConfig, i as createPinoInstance, l as generateRunId, m as resolveLevel, n as PinoLogger, o as LoggerConfig, p as resolveAxiomFromEnv, r as buildPinoOptions, s as createLogger, t as CreatePinoInstanceInput, u as isCI, v as ConsoleLogger } from "./pino-
|
|
7
|
-
export { type AnalyticsSink, type AxiomTransportConfig, type BuildTransportInput, type CommandSpan, ConsoleLogger, type CreateLoggerResult, type CreatePinoInstanceInput, type ErrorSink, LOG_LEVELS, type LogEnv, type LogLevel, type Logger, type LoggerConfig, NoopAnalyticsSink, NoopErrorSink, PinoLogger, PostHogSink, REDACTED_PATHS, REDACT_CENSOR, SentrySink, buildPinoOptions, buildTransport, createLogger, createPinoInstance, detectEnv, generateRunId, isCI, isTelemetryDisabled, parseLogLevel, redact, redactObject, redactOptions, resolveAxiomFromEnv, resolveLevel, scrubError };
|
|
6
|
+
import { _ as buildTransport, a as CreateLoggerResult, c as detectEnv, d as isTelemetryDisabled, f as parseLogLevel, g as BuildTransportInput, h as AxiomTransportConfig, i as createPinoInstance, l as generateRunId, m as resolveLevel, n as PinoLogger, o as LoggerConfig, p as resolveAxiomFromEnv, r as buildPinoOptions, s as createLogger, t as CreatePinoInstanceInput, u as isCI, v as ConsoleLogger } from "./pino-DwMkjUai.mjs";
|
|
7
|
+
export { type AnalyticsSink, type AxiomTransportConfig, type BuildTransportInput, type CommandSpan, ConsoleLogger, type CreateLoggerResult, type CreatePinoInstanceInput, type ErrorSink, LOG_LEVELS, type LogEnv, type LogLevel, type Logger, type LoggerConfig, NoopAnalyticsSink, NoopErrorSink, NoopLogger, PinoLogger, PostHogSink, REDACTED_PATHS, REDACT_CENSOR, SentrySink, buildPinoOptions, buildTransport, createLogger, createPinoInstance, detectEnv, generateRunId, isCI, isTelemetryDisabled, parseLogLevel, redact, redactObject, redactOptions, resolveAxiomFromEnv, resolveLevel, scrubError };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as LOG_LEVELS } from "./logger
|
|
1
|
+
import { n as NoopLogger, t as LOG_LEVELS } from "./logger-BJJRLMAe.mjs";
|
|
2
2
|
import { a as redactOptions, i as redactObject, n as REDACT_CENSOR, r as redact, t as REDACTED_PATHS } from "./redact-BMWG62k9.mjs";
|
|
3
3
|
import { n as NoopErrorSink, t as NoopAnalyticsSink } from "./sinks-scWbkOMp.mjs";
|
|
4
4
|
import "./core.mjs";
|
|
5
|
-
import { a as buildTransport, c as isCI, d as resolveAxiomFromEnv, f as resolveLevel, i as createPinoInstance, l as isTelemetryDisabled, n as PinoLogger, o as detectEnv, p as ConsoleLogger, r as buildPinoOptions, s as generateRunId, t as createLogger, u as parseLogLevel } from "./create-
|
|
5
|
+
import { a as buildTransport, c as isCI, d as resolveAxiomFromEnv, f as resolveLevel, i as createPinoInstance, l as isTelemetryDisabled, n as PinoLogger, o as detectEnv, p as ConsoleLogger, r as buildPinoOptions, s as generateRunId, t as createLogger, u as parseLogLevel } from "./create-f88HLYhg.mjs";
|
|
6
6
|
import { n as scrubError, t as SentrySink } from "./sentry-sink-BOuueung.mjs";
|
|
7
7
|
import { t as PostHogSink } from "./posthog-sink-ClNks-Le.mjs";
|
|
8
|
-
export { ConsoleLogger, LOG_LEVELS, NoopAnalyticsSink, NoopErrorSink, PinoLogger, PostHogSink, REDACTED_PATHS, REDACT_CENSOR, SentrySink, buildPinoOptions, buildTransport, createLogger, createPinoInstance, detectEnv, generateRunId, isCI, isTelemetryDisabled, parseLogLevel, redact, redactObject, redactOptions, resolveAxiomFromEnv, resolveLevel, scrubError };
|
|
8
|
+
export { ConsoleLogger, LOG_LEVELS, NoopAnalyticsSink, NoopErrorSink, NoopLogger, PinoLogger, PostHogSink, REDACTED_PATHS, REDACT_CENSOR, SentrySink, buildPinoOptions, buildTransport, createLogger, createPinoInstance, detectEnv, generateRunId, isCI, isTelemetryDisabled, parseLogLevel, redact, redactObject, redactOptions, resolveAxiomFromEnv, resolveLevel, scrubError };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/core/logger.ts
|
|
2
|
+
/** The four levels, in ascending severity — useful for validation. */
|
|
3
|
+
const LOG_LEVELS = [
|
|
4
|
+
"debug",
|
|
5
|
+
"info",
|
|
6
|
+
"warn",
|
|
7
|
+
"error"
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* The disabled-logging path made explicit — one shared no-op instead of a
|
|
11
|
+
* scatter of `if (!enabled) return` guards at every call site. Symmetric with
|
|
12
|
+
* {@link NoopErrorSink} / {@link NoopAnalyticsSink} in `./sinks.js`. `child()`
|
|
13
|
+
* returns `this` — a whole tree of child loggers collapses to one instance.
|
|
14
|
+
*
|
|
15
|
+
* Use it for the opted-out path, for non-vitest tests/examples that need a
|
|
16
|
+
* `Logger` but no output, or anywhere else a real transport is not worth the
|
|
17
|
+
* dependency. Vitest-based test doubles (`fakeLogger`, which records calls
|
|
18
|
+
* instead of discarding them) live in `@theholocron/observability/testing`.
|
|
19
|
+
*/
|
|
20
|
+
var NoopLogger = class {
|
|
21
|
+
debug(_objOrMsg, _msg) {}
|
|
22
|
+
info(_objOrMsg, _msg) {}
|
|
23
|
+
warn(_objOrMsg, _msg) {}
|
|
24
|
+
error(_objOrMsg, _msg) {}
|
|
25
|
+
child(_bindings) {
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { NoopLogger as n, LOG_LEVELS as t };
|
|
@@ -33,5 +33,23 @@ type LogLevel = "debug" | "info" | "warn" | "error";
|
|
|
33
33
|
declare const LOG_LEVELS: readonly LogLevel[];
|
|
34
34
|
/** Runtime environment a logger was constructed in. */
|
|
35
35
|
type LogEnv = "ci" | "local";
|
|
36
|
+
/**
|
|
37
|
+
* The disabled-logging path made explicit — one shared no-op instead of a
|
|
38
|
+
* scatter of `if (!enabled) return` guards at every call site. Symmetric with
|
|
39
|
+
* {@link NoopErrorSink} / {@link NoopAnalyticsSink} in `./sinks.js`. `child()`
|
|
40
|
+
* returns `this` — a whole tree of child loggers collapses to one instance.
|
|
41
|
+
*
|
|
42
|
+
* Use it for the opted-out path, for non-vitest tests/examples that need a
|
|
43
|
+
* `Logger` but no output, or anywhere else a real transport is not worth the
|
|
44
|
+
* dependency. Vitest-based test doubles (`fakeLogger`, which records calls
|
|
45
|
+
* instead of discarding them) live in `@theholocron/observability/testing`.
|
|
46
|
+
*/
|
|
47
|
+
declare class NoopLogger implements Logger {
|
|
48
|
+
debug(_objOrMsg?: Record<string, unknown> | string, _msg?: string): void;
|
|
49
|
+
info(_objOrMsg?: Record<string, unknown> | string, _msg?: string): void;
|
|
50
|
+
warn(_objOrMsg?: Record<string, unknown> | string, _msg?: string): void;
|
|
51
|
+
error(_objOrMsg?: Record<string, unknown> | string, _msg?: string): void;
|
|
52
|
+
child(_bindings?: Record<string, unknown>): Logger;
|
|
53
|
+
}
|
|
36
54
|
//#endregion
|
|
37
|
-
export { Logger as i, LogEnv as n, LogLevel as r, LOG_LEVELS as t };
|
|
55
|
+
export { NoopLogger as a, Logger as i, LogEnv as n, LogLevel as r, LOG_LEVELS as t };
|
package/dist/logger.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as Logger, n as LogEnv, r as LogLevel, t as LOG_LEVELS } from "./logger-
|
|
2
|
-
import { _ as buildTransport, a as CreateLoggerResult, c as detectEnv, d as isTelemetryDisabled, f as parseLogLevel, g as BuildTransportInput, h as AxiomTransportConfig, i as createPinoInstance, l as generateRunId, m as resolveLevel, n as PinoLogger, o as LoggerConfig, p as resolveAxiomFromEnv, r as buildPinoOptions, s as createLogger, t as CreatePinoInstanceInput, u as isCI, v as ConsoleLogger } from "./pino-
|
|
1
|
+
import { i as Logger, n as LogEnv, r as LogLevel, t as LOG_LEVELS } from "./logger-CIRNGqYs.mjs";
|
|
2
|
+
import { _ as buildTransport, a as CreateLoggerResult, c as detectEnv, d as isTelemetryDisabled, f as parseLogLevel, g as BuildTransportInput, h as AxiomTransportConfig, i as createPinoInstance, l as generateRunId, m as resolveLevel, n as PinoLogger, o as LoggerConfig, p as resolveAxiomFromEnv, r as buildPinoOptions, s as createLogger, t as CreatePinoInstanceInput, u as isCI, v as ConsoleLogger } from "./pino-DwMkjUai.mjs";
|
|
3
3
|
export { type AxiomTransportConfig, type BuildTransportInput, ConsoleLogger, type CreateLoggerResult, type CreatePinoInstanceInput, LOG_LEVELS, type LogEnv, type LogLevel, type Logger, type LoggerConfig, PinoLogger, buildPinoOptions, buildTransport, createLogger, createPinoInstance, detectEnv, generateRunId, isCI, isTelemetryDisabled, parseLogLevel, resolveAxiomFromEnv, resolveLevel };
|
package/dist/logger.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as LOG_LEVELS } from "./logger
|
|
2
|
-
import { a as buildTransport, c as isCI, d as resolveAxiomFromEnv, f as resolveLevel, i as createPinoInstance, l as isTelemetryDisabled, n as PinoLogger, o as detectEnv, p as ConsoleLogger, r as buildPinoOptions, s as generateRunId, t as createLogger, u as parseLogLevel } from "./create-
|
|
1
|
+
import { t as LOG_LEVELS } from "./logger-BJJRLMAe.mjs";
|
|
2
|
+
import { a as buildTransport, c as isCI, d as resolveAxiomFromEnv, f as resolveLevel, i as createPinoInstance, l as isTelemetryDisabled, n as PinoLogger, o as detectEnv, p as ConsoleLogger, r as buildPinoOptions, s as generateRunId, t as createLogger, u as parseLogLevel } from "./create-f88HLYhg.mjs";
|
|
3
3
|
export { ConsoleLogger, LOG_LEVELS, PinoLogger, buildPinoOptions, buildTransport, createLogger, createPinoInstance, detectEnv, generateRunId, isCI, isTelemetryDisabled, parseLogLevel, resolveAxiomFromEnv, resolveLevel };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as Logger$1, n as LogEnv, r as LogLevel } from "./logger-
|
|
1
|
+
import { i as Logger$1, n as LogEnv, r as LogLevel } from "./logger-CIRNGqYs.mjs";
|
|
2
2
|
import { DestinationStream, Logger, LoggerOptions, TransportMultiOptions, TransportSingleOptions } from "pino";
|
|
3
3
|
//#region src/logger/console.d.ts
|
|
4
4
|
/**
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { n as CommandSpan, r as ErrorSink, t as AnalyticsSink } from "./sinks-CSEolKcN.mjs";
|
|
2
|
+
import { i as Logger } from "./logger-CIRNGqYs.mjs";
|
|
3
|
+
import { Mock } from "vitest";
|
|
4
|
+
//#region src/testing/fake-analytics-sink.d.ts
|
|
5
|
+
/** An {@link AnalyticsSink} whose methods are spies. */
|
|
6
|
+
interface FakeAnalyticsSink extends AnalyticsSink {
|
|
7
|
+
identify: Mock;
|
|
8
|
+
capture: Mock;
|
|
9
|
+
shutdown: Mock<() => Promise<void>>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Build a spy {@link AnalyticsSink} for asserting what a unit under test
|
|
13
|
+
* reported. `shutdown()` resolves immediately.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const analytics = fakeAnalyticsSink();
|
|
17
|
+
* await deploy({ analytics, branch: "main" });
|
|
18
|
+
* expect(analytics.capture).toHaveBeenCalledWith("abc123", "deploy_triggered", { branch: "main" });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function fakeAnalyticsSink(): FakeAnalyticsSink;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/testing/fake-error-sink.d.ts
|
|
24
|
+
/** A {@link CommandSpan} whose methods are spies. */
|
|
25
|
+
interface FakeSpan extends CommandSpan {
|
|
26
|
+
setStatus: Mock;
|
|
27
|
+
end: Mock;
|
|
28
|
+
}
|
|
29
|
+
/** An {@link ErrorSink} whose methods are spies; `startSpan()` returns a {@link FakeSpan}. */
|
|
30
|
+
interface FakeErrorSink extends ErrorSink {
|
|
31
|
+
init: Mock;
|
|
32
|
+
startSpan: Mock<(name: string) => FakeSpan>;
|
|
33
|
+
captureException: Mock;
|
|
34
|
+
endSession: Mock;
|
|
35
|
+
flush: Mock<() => Promise<void>>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build a spy {@link ErrorSink} for asserting what a unit under test reported.
|
|
39
|
+
* `flush()` resolves immediately; `startSpan()` always returns the same spy
|
|
40
|
+
* span (its own `setStatus` / `end` are separately assertable).
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const errors = fakeErrorSink();
|
|
44
|
+
* await deploy({ errors, branch: "main" });
|
|
45
|
+
* expect(errors.captureException).not.toHaveBeenCalled();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function fakeErrorSink(): FakeErrorSink;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/testing/fake-logger.d.ts
|
|
51
|
+
/** A {@link Logger} whose level methods are spies; `child()` returns itself. */
|
|
52
|
+
interface FakeLogger extends Logger {
|
|
53
|
+
debug: Mock;
|
|
54
|
+
info: Mock;
|
|
55
|
+
warn: Mock;
|
|
56
|
+
error: Mock;
|
|
57
|
+
child: Mock;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build a spy {@link Logger} for asserting what a unit under test logged.
|
|
61
|
+
* Pass it wherever a real `Logger` is expected.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const log = fakeLogger();
|
|
65
|
+
* await deploy({ logger: log, target: "production" });
|
|
66
|
+
* expect(log.info).toHaveBeenCalledWith(expect.objectContaining({ target: "production" }), "deploying");
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function fakeLogger(): FakeLogger;
|
|
70
|
+
//#endregion
|
|
71
|
+
export type { FakeAnalyticsSink, FakeErrorSink, FakeLogger, FakeSpan };
|
package/dist/testing.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
//#region src/testing/fake-analytics-sink.ts
|
|
3
|
+
/**
|
|
4
|
+
* Build a spy {@link AnalyticsSink} for asserting what a unit under test
|
|
5
|
+
* reported. `shutdown()` resolves immediately.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const analytics = fakeAnalyticsSink();
|
|
9
|
+
* await deploy({ analytics, branch: "main" });
|
|
10
|
+
* expect(analytics.capture).toHaveBeenCalledWith("abc123", "deploy_triggered", { branch: "main" });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
function fakeAnalyticsSink() {
|
|
14
|
+
return {
|
|
15
|
+
identify: vi.fn(),
|
|
16
|
+
capture: vi.fn(),
|
|
17
|
+
shutdown: vi.fn().mockResolvedValue(void 0)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/testing/fake-error-sink.ts
|
|
22
|
+
/**
|
|
23
|
+
* Build a spy {@link ErrorSink} for asserting what a unit under test reported.
|
|
24
|
+
* `flush()` resolves immediately; `startSpan()` always returns the same spy
|
|
25
|
+
* span (its own `setStatus` / `end` are separately assertable).
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const errors = fakeErrorSink();
|
|
29
|
+
* await deploy({ errors, branch: "main" });
|
|
30
|
+
* expect(errors.captureException).not.toHaveBeenCalled();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function fakeErrorSink() {
|
|
34
|
+
const span = {
|
|
35
|
+
setStatus: vi.fn(),
|
|
36
|
+
end: vi.fn()
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
init: vi.fn(),
|
|
40
|
+
startSpan: vi.fn(() => span),
|
|
41
|
+
captureException: vi.fn(),
|
|
42
|
+
endSession: vi.fn(),
|
|
43
|
+
flush: vi.fn().mockResolvedValue(void 0)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/testing/fake-logger.ts
|
|
48
|
+
/**
|
|
49
|
+
* Build a spy {@link Logger} for asserting what a unit under test logged.
|
|
50
|
+
* Pass it wherever a real `Logger` is expected.
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* const log = fakeLogger();
|
|
54
|
+
* await deploy({ logger: log, target: "production" });
|
|
55
|
+
* expect(log.info).toHaveBeenCalledWith(expect.objectContaining({ target: "production" }), "deploying");
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function fakeLogger() {
|
|
59
|
+
const log = {
|
|
60
|
+
debug: vi.fn(),
|
|
61
|
+
info: vi.fn(),
|
|
62
|
+
warn: vi.fn(),
|
|
63
|
+
error: vi.fn(),
|
|
64
|
+
child: vi.fn(() => log)
|
|
65
|
+
};
|
|
66
|
+
return log;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { fakeAnalyticsSink, fakeErrorSink, fakeLogger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/observability",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Logging, error tracking, and analytics — one interface, swappable backends.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"observability",
|
|
@@ -46,6 +46,11 @@
|
|
|
46
46
|
"types": "./dist/analytics.d.mts",
|
|
47
47
|
"import": "./dist/analytics.mjs",
|
|
48
48
|
"default": "./dist/analytics.mjs"
|
|
49
|
+
},
|
|
50
|
+
"./testing": {
|
|
51
|
+
"types": "./dist/testing.d.mts",
|
|
52
|
+
"import": "./dist/testing.mjs",
|
|
53
|
+
"default": "./dist/testing.mjs"
|
|
49
54
|
}
|
|
50
55
|
},
|
|
51
56
|
"files": [
|
|
@@ -62,6 +67,7 @@
|
|
|
62
67
|
"typecheck": "tsc --noEmit"
|
|
63
68
|
},
|
|
64
69
|
"devDependencies": {
|
|
70
|
+
"@astrojs/react": "catalog:",
|
|
65
71
|
"@astrojs/starlight": "catalog:",
|
|
66
72
|
"@axiomhq/pino": "catalog:",
|
|
67
73
|
"@commitlint/cli": "catalog:",
|
|
@@ -101,6 +107,8 @@
|
|
|
101
107
|
"pino-pretty": "catalog:",
|
|
102
108
|
"posthog-node": "catalog:",
|
|
103
109
|
"prettier": "catalog:",
|
|
110
|
+
"react": "catalog:",
|
|
111
|
+
"react-dom": "catalog:",
|
|
104
112
|
"semantic-release": "catalog:",
|
|
105
113
|
"sort-package-json": "catalog:",
|
|
106
114
|
"tsdown": "catalog:",
|
|
@@ -113,7 +121,8 @@
|
|
|
113
121
|
"@sentry/node": ">=10",
|
|
114
122
|
"pino": ">=10",
|
|
115
123
|
"pino-pretty": ">=13",
|
|
116
|
-
"posthog-node": ">=5"
|
|
124
|
+
"posthog-node": ">=5",
|
|
125
|
+
"vitest": ">=4"
|
|
117
126
|
},
|
|
118
127
|
"peerDependenciesMeta": {
|
|
119
128
|
"@axiomhq/pino": {
|
|
@@ -130,6 +139,9 @@
|
|
|
130
139
|
},
|
|
131
140
|
"posthog-node": {
|
|
132
141
|
"optional": true
|
|
142
|
+
},
|
|
143
|
+
"vitest": {
|
|
144
|
+
"optional": true
|
|
133
145
|
}
|
|
134
146
|
},
|
|
135
147
|
"packageManager": "pnpm@10.33.0",
|