@theholocron/observability 0.5.0 → 0.6.1-alpha.1
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 +7 -12
- package/dist/create-CEY3e4NQ.d.mts +112 -0
- package/dist/index.d.mts +2 -1
- package/dist/logger.d.mts +2 -1
- package/dist/{pino-Bt_d5W1e.d.mts → pino-Dx8yblcl.d.mts} +3 -111
- package/dist/testing.d.mts +32 -4
- package/dist/testing.mjs +34 -1
- package/package.json +35 -83
package/README.md
CHANGED
|
@@ -16,18 +16,13 @@ pnpm install @theholocron/observability
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
|
-
See the [documentation](https://docs.theholocron.dev/observability/) for the API.
|
|
19
|
+
See the [documentation](https://docs.theholocron.dev/holocron/observability/) for the API.
|
|
20
20
|
|
|
21
21
|
<!-- /holocron:installation -->
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Peer dependencies
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
pnpm add @theholocron/observability
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Then add the peer dependencies for the subpaths you use — they are all
|
|
30
|
-
optional:
|
|
25
|
+
Add the peers for the subpaths you use — they are all optional:
|
|
31
26
|
|
|
32
27
|
| Subpath | Peers |
|
|
33
28
|
| -------------------------------------- | -------------------------------------- |
|
|
@@ -37,7 +32,7 @@ optional:
|
|
|
37
32
|
| `@theholocron/observability/analytics` | `posthog-node` |
|
|
38
33
|
| `@theholocron/observability/testing` | `vitest` |
|
|
39
34
|
|
|
40
|
-
##
|
|
35
|
+
## Examples
|
|
41
36
|
|
|
42
37
|
Application modules depend on the interfaces from `/core`, never a concrete
|
|
43
38
|
adapter:
|
|
@@ -88,11 +83,11 @@ expect(log.info).toHaveBeenCalledWith(expect.objectContaining({ target: "product
|
|
|
88
83
|
expect(errors.captureException).not.toHaveBeenCalled();
|
|
89
84
|
```
|
|
90
85
|
|
|
91
|
-
For a non-vitest context that
|
|
86
|
+
For a non-vitest context that needs a `Logger` with no output (an
|
|
92
87
|
example, a non-test opt-out path), use `NoopLogger` from `/core` — it
|
|
93
88
|
discards everything, `child()` returns itself.
|
|
94
89
|
|
|
95
|
-
See the [documentation](https://docs.theholocron.dev/observability/) for the
|
|
90
|
+
See the [documentation](https://docs.theholocron.dev/holocron/observability/) for the
|
|
96
91
|
full API.
|
|
97
92
|
|
|
98
93
|
## Development
|
|
@@ -115,6 +110,6 @@ full API.
|
|
|
115
110
|
<!-- holocron:releases -->
|
|
116
111
|
|
|
117
112
|
Automated via [semantic-release](https://semantic-release.gitbook.io/semantic-release/).
|
|
118
|
-
See
|
|
113
|
+
See [CHANGELOG.md](./CHANGELOG.md).
|
|
119
114
|
|
|
120
115
|
<!-- /holocron:releases -->
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { i as Logger$1, r as LogLevel } from "./logger-CxGXigv1.mjs";
|
|
2
|
+
import { TransportMultiOptions, TransportSingleOptions } from "pino";
|
|
3
|
+
//#region src/logger/transports.d.ts
|
|
4
|
+
/** Axiom credentials. The token comes from env vars or the OS keyring — never
|
|
5
|
+
* a committed config file; the dataset name may come from config. */
|
|
6
|
+
interface AxiomTransportConfig {
|
|
7
|
+
dataset: string;
|
|
8
|
+
token: string;
|
|
9
|
+
}
|
|
10
|
+
interface BuildTransportInput {
|
|
11
|
+
/** Resolved log level — applied uniformly to every transport. */
|
|
12
|
+
level: LogLevel;
|
|
13
|
+
/** Axiom credentials. When absent, no Axiom transport is wired. */
|
|
14
|
+
axiom?: AxiomTransportConfig;
|
|
15
|
+
/** `true` inside CI — suppresses pino-pretty. */
|
|
16
|
+
ci: boolean;
|
|
17
|
+
/** `process.stdout.isTTY` — pino-pretty only makes sense on a TTY. */
|
|
18
|
+
tty: boolean;
|
|
19
|
+
/** `true` when `HOLOCRON_TELEMETRY=false` — suppresses the Axiom transport only. */
|
|
20
|
+
telemetryDisabled: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Explicit override for whether human-visible console output (pretty or
|
|
23
|
+
* NDJSON) runs at all, independent of `level`. `undefined` (default)
|
|
24
|
+
* preserves the existing `ci`/`tty` auto-detection below. `false`
|
|
25
|
+
* suppresses console output entirely, regardless of `ci`/`tty` — Axiom
|
|
26
|
+
* (if configured) is unaffected. When nothing else is wired either,
|
|
27
|
+
* {@link createPinoInstance} routes to a null destination instead of
|
|
28
|
+
* falling back to Pino's own default stdout — see its doc for why that
|
|
29
|
+
* distinction matters.
|
|
30
|
+
*/
|
|
31
|
+
consoleOutput?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build the Pino `transport` option for the current environment.
|
|
35
|
+
*
|
|
36
|
+
* | Environment | Output |
|
|
37
|
+
* | -------------------------- | --------------------------------------------------- |
|
|
38
|
+
* | Local, TTY, no Axiom | `pino-pretty` only |
|
|
39
|
+
* | CI, no Axiom | `undefined` — Pino's default NDJSON to stdout |
|
|
40
|
+
* | Local, TTY, with Axiom | `pino-pretty` + Axiom |
|
|
41
|
+
* | CI, with Axiom | NDJSON to stdout + Axiom |
|
|
42
|
+
* | `consoleOutput: false`, no Axiom | `undefined` — routed to a null destination |
|
|
43
|
+
* | `consoleOutput: false`, with Axiom | Axiom only |
|
|
44
|
+
*
|
|
45
|
+
* The Axiom transport is dropped entirely when `telemetryDisabled` is set,
|
|
46
|
+
* regardless of whether credentials were supplied. Every transport runs on
|
|
47
|
+
* the same resolved `level` — there is no Axiom-only gate.
|
|
48
|
+
*
|
|
49
|
+
* Returning `undefined` lets `createLogger` fall back to a plain
|
|
50
|
+
* `pino({ ... })` with no worker thread — the cheapest path, and exactly
|
|
51
|
+
* what CI wants.
|
|
52
|
+
*
|
|
53
|
+
* `consoleOutput: false` opts out of all of the above: no pretty, no NDJSON,
|
|
54
|
+
* regardless of `ci`/`tty`. Axiom (when configured) still gets its own
|
|
55
|
+
* target, untouched by the override.
|
|
56
|
+
*/
|
|
57
|
+
declare function buildTransport(input: BuildTransportInput): TransportSingleOptions | TransportMultiOptions | undefined;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/logger/create.d.ts
|
|
60
|
+
interface LoggerConfig {
|
|
61
|
+
/**
|
|
62
|
+
* Explicit level — the highest-priority source. The caller passes the
|
|
63
|
+
* resolved `--verbose` / `--quiet` flag or a config field here. Falls
|
|
64
|
+
* through to `HOLOCRON_LOG_LEVEL`, then `"info"`.
|
|
65
|
+
*/
|
|
66
|
+
level?: LogLevel;
|
|
67
|
+
/**
|
|
68
|
+
* Axiom credentials. Resolved from env vars by default
|
|
69
|
+
* (`HOLOCRON_AXIOM_TOKEN` / `AXIOM_TOKEN` + `HOLOCRON_AXIOM_DATASET` /
|
|
70
|
+
* `AXIOM_DATASET`). Pass this only to override — e.g. to pair an OS-keyring
|
|
71
|
+
* token with a config-file dataset. The **token** must never come from a
|
|
72
|
+
* committed config file. The transport is also skipped entirely when
|
|
73
|
+
* `HOLOCRON_TELEMETRY=false`.
|
|
74
|
+
*/
|
|
75
|
+
axiom?: AxiomTransportConfig;
|
|
76
|
+
/**
|
|
77
|
+
* Explicit override for whether human-visible console output (pretty or
|
|
78
|
+
* NDJSON) runs at all, independent of `level`. `undefined` (default)
|
|
79
|
+
* preserves the existing `ci`/`tty` auto-detection — every consumer that
|
|
80
|
+
* doesn't pass this is unaffected. Pass `false` to suppress console
|
|
81
|
+
* output entirely (e.g. a CLI's quiet-by-default interactive mode);
|
|
82
|
+
* Axiom (if configured) still receives everything.
|
|
83
|
+
*/
|
|
84
|
+
consoleOutput?: boolean;
|
|
85
|
+
}
|
|
86
|
+
interface CreateLoggerResult {
|
|
87
|
+
/** The logger to thread through modules via `child()`. */
|
|
88
|
+
logger: Logger$1;
|
|
89
|
+
/**
|
|
90
|
+
* Correlation id bound to every line this logger (and its children) emit.
|
|
91
|
+
* Surface it to the user (e.g. on `--debug`) so they can pull the run out
|
|
92
|
+
* of Axiom.
|
|
93
|
+
*/
|
|
94
|
+
runId: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The single entry point for building a Pino-backed logger. Generates a
|
|
98
|
+
* `runId`, detects the environment, resolves the level, wires the right
|
|
99
|
+
* transports, and returns a ready {@link Logger}.
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* const { logger, runId } = createLogger({ level, axiom });
|
|
103
|
+
* const log = logger.child({ command: "sync-github", repo });
|
|
104
|
+
* log.info({ branch }, "opening PR");
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* For a browser / edge / React Native context, construct a `ConsoleLogger`
|
|
108
|
+
* directly instead — it needs no `createLogger`.
|
|
109
|
+
*/
|
|
110
|
+
declare function createLogger(config?: LoggerConfig): CreateLoggerResult;
|
|
111
|
+
//#endregion
|
|
112
|
+
export { BuildTransportInput as a, AxiomTransportConfig as i, LoggerConfig as n, buildTransport as o, createLogger as r, CreateLoggerResult as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -3,5 +3,6 @@ import { t as PostHogSink } from "./posthog-sink-BvVIQrGy.mjs";
|
|
|
3
3
|
import { a as NoopLogger, i as Logger, n as LogEnv, r as LogLevel, t as LOG_LEVELS } from "./logger-CxGXigv1.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 {
|
|
6
|
+
import { a as detectEnv, c as isTelemetryDisabled, d as resolveLevel, f as ConsoleLogger, i as createPinoInstance, l as parseLogLevel, n as PinoLogger, o as generateRunId, r as buildPinoOptions, s as isCI, t as CreatePinoInstanceInput, u as resolveAxiomFromEnv } from "./pino-Dx8yblcl.mjs";
|
|
7
|
+
import { a as BuildTransportInput, i as AxiomTransportConfig, n as LoggerConfig, o as buildTransport, r as createLogger, t as CreateLoggerResult } from "./create-CEY3e4NQ.mjs";
|
|
7
8
|
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/logger.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { i as Logger, n as LogEnv, r as LogLevel, t as LOG_LEVELS } from "./logger-CxGXigv1.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { a as detectEnv, c as isTelemetryDisabled, d as resolveLevel, f as ConsoleLogger, i as createPinoInstance, l as parseLogLevel, n as PinoLogger, o as generateRunId, r as buildPinoOptions, s as isCI, t as CreatePinoInstanceInput, u as resolveAxiomFromEnv } from "./pino-Dx8yblcl.mjs";
|
|
3
|
+
import { a as BuildTransportInput, i as AxiomTransportConfig, n as LoggerConfig, o as buildTransport, r as createLogger, t as CreateLoggerResult } from "./create-CEY3e4NQ.mjs";
|
|
3
4
|
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 };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { i as Logger$1, n as LogEnv, r as LogLevel } from "./logger-CxGXigv1.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { i as AxiomTransportConfig } from "./create-CEY3e4NQ.mjs";
|
|
3
|
+
import { DestinationStream, Logger, LoggerOptions } from "pino";
|
|
3
4
|
//#region src/logger/console.d.ts
|
|
4
5
|
/**
|
|
5
6
|
* A zero-dependency {@link Logger} over the platform `console` — no Pino, no
|
|
@@ -29,62 +30,6 @@ declare class ConsoleLogger implements Logger$1 {
|
|
|
29
30
|
flush(): Promise<void>;
|
|
30
31
|
}
|
|
31
32
|
//#endregion
|
|
32
|
-
//#region src/logger/transports.d.ts
|
|
33
|
-
/** Axiom credentials. The token comes from env vars or the OS keyring — never
|
|
34
|
-
* a committed config file; the dataset name may come from config. */
|
|
35
|
-
interface AxiomTransportConfig {
|
|
36
|
-
dataset: string;
|
|
37
|
-
token: string;
|
|
38
|
-
}
|
|
39
|
-
interface BuildTransportInput {
|
|
40
|
-
/** Resolved log level — applied uniformly to every transport. */
|
|
41
|
-
level: LogLevel;
|
|
42
|
-
/** Axiom credentials. When absent, no Axiom transport is wired. */
|
|
43
|
-
axiom?: AxiomTransportConfig;
|
|
44
|
-
/** `true` inside CI — suppresses pino-pretty. */
|
|
45
|
-
ci: boolean;
|
|
46
|
-
/** `process.stdout.isTTY` — pino-pretty only makes sense on a TTY. */
|
|
47
|
-
tty: boolean;
|
|
48
|
-
/** `true` when `HOLOCRON_TELEMETRY=false` — suppresses the Axiom transport only. */
|
|
49
|
-
telemetryDisabled: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Explicit override for whether human-visible console output (pretty or
|
|
52
|
-
* NDJSON) runs at all, independent of `level`. `undefined` (default)
|
|
53
|
-
* preserves the existing `ci`/`tty` auto-detection below. `false`
|
|
54
|
-
* suppresses console output entirely, regardless of `ci`/`tty` — Axiom
|
|
55
|
-
* (if configured) is unaffected. When nothing else is wired either,
|
|
56
|
-
* {@link createPinoInstance} routes to a null destination instead of
|
|
57
|
-
* falling back to Pino's own default stdout — see its doc for why that
|
|
58
|
-
* distinction matters.
|
|
59
|
-
*/
|
|
60
|
-
consoleOutput?: boolean;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Build the Pino `transport` option for the current environment.
|
|
64
|
-
*
|
|
65
|
-
* | Environment | Output |
|
|
66
|
-
* | -------------------------- | --------------------------------------------------- |
|
|
67
|
-
* | Local, TTY, no Axiom | `pino-pretty` only |
|
|
68
|
-
* | CI, no Axiom | `undefined` — Pino's default NDJSON to stdout |
|
|
69
|
-
* | Local, TTY, with Axiom | `pino-pretty` + Axiom |
|
|
70
|
-
* | CI, with Axiom | NDJSON to stdout + Axiom |
|
|
71
|
-
* | `consoleOutput: false`, no Axiom | `undefined` — routed to a null destination |
|
|
72
|
-
* | `consoleOutput: false`, with Axiom | Axiom only |
|
|
73
|
-
*
|
|
74
|
-
* The Axiom transport is dropped entirely when `telemetryDisabled` is set,
|
|
75
|
-
* regardless of whether credentials were supplied. Every transport runs on
|
|
76
|
-
* the same resolved `level` — there is no Axiom-only gate.
|
|
77
|
-
*
|
|
78
|
-
* Returning `undefined` lets `createLogger` fall back to a plain
|
|
79
|
-
* `pino({ ... })` with no worker thread — the cheapest path, and exactly
|
|
80
|
-
* what CI wants.
|
|
81
|
-
*
|
|
82
|
-
* `consoleOutput: false` opts out of all of the above: no pretty, no NDJSON,
|
|
83
|
-
* regardless of `ci`/`tty`. Axiom (when configured) still gets its own
|
|
84
|
-
* target, untouched by the override.
|
|
85
|
-
*/
|
|
86
|
-
declare function buildTransport(input: BuildTransportInput): TransportSingleOptions | TransportMultiOptions | undefined;
|
|
87
|
-
//#endregion
|
|
88
33
|
//#region src/logger/context.d.ts
|
|
89
34
|
/**
|
|
90
35
|
* A fresh correlation id for one invocation. Every log line from a single run
|
|
@@ -130,59 +75,6 @@ declare function isTelemetryDisabled(env?: NodeJS.ProcessEnv): boolean;
|
|
|
130
75
|
*/
|
|
131
76
|
declare function resolveAxiomFromEnv(env?: NodeJS.ProcessEnv): AxiomTransportConfig | undefined;
|
|
132
77
|
//#endregion
|
|
133
|
-
//#region src/logger/create.d.ts
|
|
134
|
-
interface LoggerConfig {
|
|
135
|
-
/**
|
|
136
|
-
* Explicit level — the highest-priority source. The caller passes the
|
|
137
|
-
* resolved `--verbose` / `--quiet` flag or a config field here. Falls
|
|
138
|
-
* through to `HOLOCRON_LOG_LEVEL`, then `"info"`.
|
|
139
|
-
*/
|
|
140
|
-
level?: LogLevel;
|
|
141
|
-
/**
|
|
142
|
-
* Axiom credentials. Resolved from env vars by default
|
|
143
|
-
* (`HOLOCRON_AXIOM_TOKEN` / `AXIOM_TOKEN` + `HOLOCRON_AXIOM_DATASET` /
|
|
144
|
-
* `AXIOM_DATASET`). Pass this only to override — e.g. to pair an OS-keyring
|
|
145
|
-
* token with a config-file dataset. The **token** must never come from a
|
|
146
|
-
* committed config file. The transport is also skipped entirely when
|
|
147
|
-
* `HOLOCRON_TELEMETRY=false`.
|
|
148
|
-
*/
|
|
149
|
-
axiom?: AxiomTransportConfig;
|
|
150
|
-
/**
|
|
151
|
-
* Explicit override for whether human-visible console output (pretty or
|
|
152
|
-
* NDJSON) runs at all, independent of `level`. `undefined` (default)
|
|
153
|
-
* preserves the existing `ci`/`tty` auto-detection — every consumer that
|
|
154
|
-
* doesn't pass this is unaffected. Pass `false` to suppress console
|
|
155
|
-
* output entirely (e.g. a CLI's quiet-by-default interactive mode);
|
|
156
|
-
* Axiom (if configured) still receives everything.
|
|
157
|
-
*/
|
|
158
|
-
consoleOutput?: boolean;
|
|
159
|
-
}
|
|
160
|
-
interface CreateLoggerResult {
|
|
161
|
-
/** The logger to thread through modules via `child()`. */
|
|
162
|
-
logger: Logger$1;
|
|
163
|
-
/**
|
|
164
|
-
* Correlation id bound to every line this logger (and its children) emit.
|
|
165
|
-
* Surface it to the user (e.g. on `--debug`) so they can pull the run out
|
|
166
|
-
* of Axiom.
|
|
167
|
-
*/
|
|
168
|
-
runId: string;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* The single entry point for building a Pino-backed logger. Generates a
|
|
172
|
-
* `runId`, detects the environment, resolves the level, wires the right
|
|
173
|
-
* transports, and returns a ready {@link Logger}.
|
|
174
|
-
*
|
|
175
|
-
* ```ts
|
|
176
|
-
* const { logger, runId } = createLogger({ level, axiom });
|
|
177
|
-
* const log = logger.child({ command: "sync-github", repo });
|
|
178
|
-
* log.info({ branch }, "opening PR");
|
|
179
|
-
* ```
|
|
180
|
-
*
|
|
181
|
-
* For a browser / edge / React Native context, construct a `ConsoleLogger`
|
|
182
|
-
* directly instead — it needs no `createLogger`.
|
|
183
|
-
*/
|
|
184
|
-
declare function createLogger(config?: LoggerConfig): CreateLoggerResult;
|
|
185
|
-
//#endregion
|
|
186
78
|
//#region src/logger/pino.d.ts
|
|
187
79
|
/**
|
|
188
80
|
* The Pino-backed {@link Logger}. Nothing outside this package should name it —
|
|
@@ -251,4 +143,4 @@ declare function buildPinoOptions(input: CreatePinoInstanceInput): LoggerOptions
|
|
|
251
143
|
*/
|
|
252
144
|
declare function createPinoInstance(input: CreatePinoInstanceInput): Logger;
|
|
253
145
|
//#endregion
|
|
254
|
-
export {
|
|
146
|
+
export { detectEnv as a, isTelemetryDisabled as c, resolveLevel as d, ConsoleLogger as f, createPinoInstance as i, parseLogLevel as l, PinoLogger as n, generateRunId as o, buildPinoOptions as r, isCI as s, CreatePinoInstanceInput as t, resolveAxiomFromEnv as u };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { n as CommandSpan, r as ErrorSink, t as AnalyticsSink } from "./sinks-CSEolKcN.mjs";
|
|
2
2
|
import { i as Logger } from "./logger-CxGXigv1.mjs";
|
|
3
|
+
import { r as createLogger } from "./create-CEY3e4NQ.mjs";
|
|
3
4
|
import { Mock } from "vitest";
|
|
4
5
|
//#region src/testing/fake-analytics-sink.d.ts
|
|
5
6
|
/** An {@link AnalyticsSink} whose methods are spies. */
|
|
@@ -18,7 +19,7 @@ interface FakeAnalyticsSink extends AnalyticsSink {
|
|
|
18
19
|
* expect(analytics.capture).toHaveBeenCalledWith("abc123", "deploy_triggered", { branch: "main" });
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
declare function fakeAnalyticsSink(): FakeAnalyticsSink;
|
|
22
23
|
//#endregion
|
|
23
24
|
//#region src/testing/fake-error-sink.d.ts
|
|
24
25
|
/** A {@link CommandSpan} whose methods are spies. */
|
|
@@ -45,7 +46,7 @@ interface FakeErrorSink extends ErrorSink {
|
|
|
45
46
|
* expect(errors.captureException).not.toHaveBeenCalled();
|
|
46
47
|
* ```
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
declare function fakeErrorSink(): FakeErrorSink;
|
|
49
50
|
//#endregion
|
|
50
51
|
//#region src/testing/fake-logger.d.ts
|
|
51
52
|
/** A {@link Logger} whose level methods are spies; `child()` returns itself. */
|
|
@@ -67,6 +68,33 @@ interface FakeLogger extends Logger {
|
|
|
67
68
|
* expect(log.info).toHaveBeenCalledWith(expect.objectContaining({ target: "production" }), "deploying");
|
|
68
69
|
* ```
|
|
69
70
|
*/
|
|
70
|
-
|
|
71
|
+
declare function fakeLogger(): FakeLogger;
|
|
71
72
|
//#endregion
|
|
72
|
-
|
|
73
|
+
//#region src/testing/silence-logger.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* Replace `createLogger` in the `/logger` module with one that returns a
|
|
76
|
+
* {@link NoopLogger}, so code under test that builds a real Pino logger stops
|
|
77
|
+
* writing NDJSON to stdout. Everything else the module exports passes through.
|
|
78
|
+
*
|
|
79
|
+
* The replacement is a plain function, not a `vi.fn`, so a consumer's
|
|
80
|
+
* `resetMocks` / `restoreMocks` setting cannot wipe its implementation.
|
|
81
|
+
*
|
|
82
|
+
* `vi.mock` only takes effect in the consumer's own file, so call this from a
|
|
83
|
+
* vitest setup file:
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { vi } from "vitest";
|
|
87
|
+
*
|
|
88
|
+
* vi.mock("@theholocron/observability/logger", async (importOriginal) => {
|
|
89
|
+
* const { silenceLogger } = await import("@theholocron/observability/testing");
|
|
90
|
+
* return silenceLogger(await importOriginal());
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function silenceLogger<T extends {
|
|
95
|
+
createLogger: unknown;
|
|
96
|
+
}>(actual: T): Omit<T, "createLogger"> & {
|
|
97
|
+
createLogger: typeof createLogger;
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
export { type FakeAnalyticsSink, type FakeErrorSink, type FakeLogger, type FakeSpan, fakeAnalyticsSink, fakeErrorSink, fakeLogger, silenceLogger };
|
package/dist/testing.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { n as NoopLogger } from "./logger-DIvYoEp9.mjs";
|
|
1
2
|
import { vi } from "vitest";
|
|
2
3
|
//#region src/testing/fake-analytics-sink.ts
|
|
3
4
|
/**
|
|
@@ -67,4 +68,36 @@ function fakeLogger() {
|
|
|
67
68
|
return log;
|
|
68
69
|
}
|
|
69
70
|
//#endregion
|
|
70
|
-
|
|
71
|
+
//#region src/testing/silence-logger.ts
|
|
72
|
+
const SILENT_RUN_ID = "00000000-0000-4000-8000-000000000000";
|
|
73
|
+
/**
|
|
74
|
+
* Replace `createLogger` in the `/logger` module with one that returns a
|
|
75
|
+
* {@link NoopLogger}, so code under test that builds a real Pino logger stops
|
|
76
|
+
* writing NDJSON to stdout. Everything else the module exports passes through.
|
|
77
|
+
*
|
|
78
|
+
* The replacement is a plain function, not a `vi.fn`, so a consumer's
|
|
79
|
+
* `resetMocks` / `restoreMocks` setting cannot wipe its implementation.
|
|
80
|
+
*
|
|
81
|
+
* `vi.mock` only takes effect in the consumer's own file, so call this from a
|
|
82
|
+
* vitest setup file:
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { vi } from "vitest";
|
|
86
|
+
*
|
|
87
|
+
* vi.mock("@theholocron/observability/logger", async (importOriginal) => {
|
|
88
|
+
* const { silenceLogger } = await import("@theholocron/observability/testing");
|
|
89
|
+
* return silenceLogger(await importOriginal());
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function silenceLogger(actual) {
|
|
94
|
+
return {
|
|
95
|
+
...actual,
|
|
96
|
+
createLogger: () => ({
|
|
97
|
+
logger: new NoopLogger(),
|
|
98
|
+
runId: SILENT_RUN_ID
|
|
99
|
+
})
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { fakeAnalyticsSink, fakeErrorSink, fakeLogger, silenceLogger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/observability",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1-alpha.1",
|
|
4
4
|
"description": "Logging, error tracking, and analytics — one interface, swappable backends.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -12,9 +12,13 @@
|
|
|
12
12
|
"pino",
|
|
13
13
|
"theholocron"
|
|
14
14
|
],
|
|
15
|
-
"homepage": "https://docs.theholocron.dev/observability/",
|
|
16
|
-
"bugs": "https://github.com/theholocron/
|
|
17
|
-
"repository":
|
|
15
|
+
"homepage": "https://docs.theholocron.dev/holocron/observability/",
|
|
16
|
+
"bugs": "https://github.com/theholocron/holocron/issues",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/theholocron/holocron.git",
|
|
20
|
+
"directory": "observability"
|
|
21
|
+
},
|
|
18
22
|
"license": "MIT",
|
|
19
23
|
"author": "Newton Koumantzelis",
|
|
20
24
|
"sideEffects": false,
|
|
@@ -54,75 +58,25 @@
|
|
|
54
58
|
"files": [
|
|
55
59
|
"dist"
|
|
56
60
|
],
|
|
57
|
-
"scripts": {
|
|
58
|
-
"build": "tsdown",
|
|
59
|
-
"delivery.build": "tsdown",
|
|
60
|
-
"holocron": "holocron",
|
|
61
|
-
"knowledge.wiki": "holocron run knowledge.wiki --",
|
|
62
|
-
"platform.commitStandards": "holocron run platform.commitStandards --",
|
|
63
|
-
"platform.repoSync": "holocron run platform.repoSync --",
|
|
64
|
-
"prepare": "husky",
|
|
65
|
-
"security.secretDetection": "holocron run security.secretDetection --",
|
|
66
|
-
"sourceQuality.deadCodeAnalysis": "holocron run sourceQuality.deadCodeAnalysis --",
|
|
67
|
-
"sourceQuality.formatting": "holocron run sourceQuality.formatting --",
|
|
68
|
-
"sourceQuality.staticAnalysis": "eslint .",
|
|
69
|
-
"sourceQuality.structuredDataValidation": "holocron run sourceQuality.structuredDataValidation --",
|
|
70
|
-
"test:coverage": "vitest run --coverage",
|
|
71
|
-
"verification.typeSafety": "tsc --noEmit",
|
|
72
|
-
"verification.unitTests": "vitest run"
|
|
73
|
-
},
|
|
74
61
|
"devDependencies": {
|
|
75
|
-
"@
|
|
76
|
-
"@
|
|
77
|
-
"@
|
|
78
|
-
"@
|
|
79
|
-
"@
|
|
80
|
-
"@
|
|
81
|
-
"@
|
|
82
|
-
"@
|
|
83
|
-
"@
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"@theholocron/holocron-plugin-fern": "catalog:holocron",
|
|
94
|
-
"@theholocron/holocron-plugin-github": "catalog:holocron",
|
|
95
|
-
"@theholocron/lint-staged-config": "catalog:configs",
|
|
96
|
-
"@theholocron/prettier-config": "catalog:configs",
|
|
97
|
-
"@theholocron/semantic-release-config": "catalog:configs",
|
|
98
|
-
"@theholocron/skills": "^1.3.2",
|
|
99
|
-
"@theholocron/tsconfig": "catalog:configs",
|
|
100
|
-
"@theholocron/tsdown-config": "catalog:configs",
|
|
101
|
-
"@theholocron/vitest-config": "catalog:configs",
|
|
102
|
-
"@types/node": "catalog:",
|
|
103
|
-
"@vitest/coverage-v8": "catalog:",
|
|
104
|
-
"astro": "catalog:",
|
|
105
|
-
"conventional-changelog-conventionalcommits": "catalog:",
|
|
106
|
-
"eslint": "catalog:",
|
|
107
|
-
"eslint-plugin-n": "catalog:",
|
|
108
|
-
"eslint-plugin-simple-import-sort": "catalog:",
|
|
109
|
-
"globals": "catalog:",
|
|
110
|
-
"husky": "catalog:",
|
|
111
|
-
"knip": "catalog:",
|
|
112
|
-
"lint-staged": "catalog:",
|
|
113
|
-
"pino": "catalog:",
|
|
114
|
-
"pino-pretty": "catalog:",
|
|
115
|
-
"posthog-node": "catalog:",
|
|
116
|
-
"prettier": "catalog:",
|
|
117
|
-
"react": "catalog:",
|
|
118
|
-
"react-dom": "catalog:",
|
|
119
|
-
"semantic-release": "catalog:",
|
|
120
|
-
"sort-package-json": "catalog:",
|
|
121
|
-
"tsdown": "catalog:",
|
|
122
|
-
"turbo": "^2.10.12",
|
|
123
|
-
"typescript": "catalog:",
|
|
124
|
-
"typescript-eslint": "catalog:",
|
|
125
|
-
"vitest": "catalog:"
|
|
62
|
+
"@axiomhq/pino": "^2.0.0",
|
|
63
|
+
"@sentry/node": "^10.70.0",
|
|
64
|
+
"@theholocron/eslint-config": "^8.8.2",
|
|
65
|
+
"@theholocron/tsconfig": "^8.8.2",
|
|
66
|
+
"@theholocron/tsdown-config": "^8.8.2",
|
|
67
|
+
"@theholocron/vitest-config": "^8.8.2",
|
|
68
|
+
"@types/node": "^26",
|
|
69
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
70
|
+
"@vitest/eslint-plugin": "^1.6.27",
|
|
71
|
+
"eslint": "^10.8.1",
|
|
72
|
+
"eslint-plugin-n": "^18.3.0",
|
|
73
|
+
"globals": "^17.11.0",
|
|
74
|
+
"pino": "^10.3.1",
|
|
75
|
+
"pino-pretty": "^13.1.3",
|
|
76
|
+
"posthog-node": "^5.51.6",
|
|
77
|
+
"tsdown": "^0.22.14",
|
|
78
|
+
"typescript": "^5.9.3",
|
|
79
|
+
"vitest": "^4.1.11"
|
|
126
80
|
},
|
|
127
81
|
"peerDependencies": {
|
|
128
82
|
"@axiomhq/pino": ">=2",
|
|
@@ -152,19 +106,17 @@
|
|
|
152
106
|
"optional": true
|
|
153
107
|
}
|
|
154
108
|
},
|
|
155
|
-
"packageManager": "pnpm@10.33.0",
|
|
156
109
|
"engines": {
|
|
157
|
-
"node": ">=22
|
|
110
|
+
"node": ">=22"
|
|
158
111
|
},
|
|
159
112
|
"publishConfig": {
|
|
160
113
|
"access": "public"
|
|
161
114
|
},
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
115
|
+
"scripts": {
|
|
116
|
+
"delivery.build": "tsdown",
|
|
117
|
+
"sourceQuality.staticAnalysis": "eslint .",
|
|
118
|
+
"test:watch": "vitest",
|
|
119
|
+
"verification.typeSafety": "tsc --noEmit",
|
|
120
|
+
"verification.unitTests": "vitest run"
|
|
121
|
+
}
|
|
122
|
+
}
|