@contrail/telemetry 2.0.2 → 2.0.3
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/CHANGELOG.md +9 -2
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +4 -3
- package/lib/logger/log-context.d.ts +4 -4
- package/lib/logger/log-context.js +5 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,14 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [2.0.
|
|
10
|
+
## [2.0.3] - 2026-04-15
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **`withLogContext` renamed to `withLogAttributes`** — Aligns the export name with the API documented in 2.0.0. Any code importing `withLogContext` directly must update to `withLogAttributes`.
|
|
15
|
+
- **`addStream` fixed** — Uses `pino.symbols.streamSym` to access the underlying multistream, replacing an internal `(logger as any).stream` access that broke across pino versions.
|
|
16
|
+
|
|
17
|
+
## [2.0.2] - 2026-04-15
|
|
11
18
|
|
|
12
19
|
### Fixed
|
|
13
20
|
|
|
@@ -18,7 +25,7 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
18
25
|
### Added
|
|
19
26
|
|
|
20
27
|
- **Request context on every log** — `logger` is now context-aware. During a request, all logs (including from library code like `@contrail/dynamodb` or `@contrail/auth`) automatically include `user.id`, `org.slug`, `url.path`, and other request fields. No import changes needed.
|
|
21
|
-
- **`
|
|
28
|
+
- **`withLogAttributes(fields, fn)`** — Wrap any block of code with extra log context. Context stacks on top of any existing request context and is removed when the callback exits.
|
|
22
29
|
- **`addStream(streamEntry)`** — Hook a custom pino stream into the logger to tap into all log records (e.g. collect logs in memory for a UI panel).
|
|
23
30
|
- **`flushLogs()`** — Flush pending logs to the OTLP collector before a Lambda execution environment freezes.
|
|
24
31
|
- **OTel log export** — Logs are sent to an OTLP HTTP endpoint (when `OTEL_EXPORTER_OTLP_ENDPOINT` is set) with Lambda attributes, span context, and flattened structured fields.
|
package/lib/logger/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import pino from 'pino';
|
|
|
2
2
|
export { parseOtelResourceAttributes } from './parse-otel-resource-attributes';
|
|
3
3
|
export { PINO_LEVEL_TO_OTEL_SEVERITY, PINO_LEVEL_TO_NAME } from './logger-config';
|
|
4
4
|
export { ATTR_LOG_MESSAGE, ATTR_LOG_PAYLOAD } from './semantic-conventions';
|
|
5
|
-
export { loggerStorage,
|
|
5
|
+
export { loggerStorage, withLogAttributes } from './log-context';
|
|
6
6
|
export declare const baseLogger: pino.Logger<never, boolean>;
|
|
7
7
|
export declare const logger: pino.Logger;
|
|
8
8
|
/**
|
package/lib/logger/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.logger = exports.baseLogger = exports.
|
|
7
|
+
exports.logger = exports.baseLogger = exports.withLogAttributes = exports.loggerStorage = exports.ATTR_LOG_PAYLOAD = exports.ATTR_LOG_MESSAGE = exports.PINO_LEVEL_TO_NAME = exports.PINO_LEVEL_TO_OTEL_SEVERITY = exports.parseOtelResourceAttributes = void 0;
|
|
8
8
|
exports.addStream = addStream;
|
|
9
9
|
exports.flushLogs = flushLogs;
|
|
10
10
|
const pino_1 = __importDefault(require("pino"));
|
|
@@ -31,7 +31,7 @@ Object.defineProperty(exports, "ATTR_LOG_MESSAGE", { enumerable: true, get: func
|
|
|
31
31
|
Object.defineProperty(exports, "ATTR_LOG_PAYLOAD", { enumerable: true, get: function () { return semantic_conventions_3.ATTR_LOG_PAYLOAD; } });
|
|
32
32
|
var log_context_1 = require("./log-context");
|
|
33
33
|
Object.defineProperty(exports, "loggerStorage", { enumerable: true, get: function () { return log_context_1.loggerStorage; } });
|
|
34
|
-
Object.defineProperty(exports, "
|
|
34
|
+
Object.defineProperty(exports, "withLogAttributes", { enumerable: true, get: function () { return log_context_1.withLogAttributes; } });
|
|
35
35
|
// --- Environment & Resource Setup ---
|
|
36
36
|
const semantic_conventions_4 = require("../semantic-conventions");
|
|
37
37
|
const LAMBDA_ENV_OTEL_ATTRIBUTES = getLambdaEnvAttributes();
|
|
@@ -243,7 +243,8 @@ exports.logger = (0, log_context_2.createContextAwareLogger)(exports.baseLogger)
|
|
|
243
243
|
* Use this to wire additional log sinks (e.g. InMemoryLogStream in app-framework).
|
|
244
244
|
*/
|
|
245
245
|
function addStream(streamEntry) {
|
|
246
|
-
const
|
|
246
|
+
const streamSym = pino_1.default.symbols.streamSym;
|
|
247
|
+
const ms = exports.baseLogger[streamSym];
|
|
247
248
|
if (ms && typeof ms.add === 'function') {
|
|
248
249
|
ms.add(streamEntry);
|
|
249
250
|
}
|
|
@@ -3,7 +3,7 @@ import type { Logger } from 'pino';
|
|
|
3
3
|
/**
|
|
4
4
|
* Stores the current request-scoped child logger per async context.
|
|
5
5
|
* Used by `createContextAwareLogger` to make the `logger` export context-aware,
|
|
6
|
-
* and by `
|
|
6
|
+
* and by `withLogAttributes` to set context for a block of code.
|
|
7
7
|
*/
|
|
8
8
|
export declare const loggerStorage: AsyncLocalStorage<Logger>;
|
|
9
9
|
/**
|
|
@@ -49,13 +49,13 @@ export declare function createContextAwareLogger(baseLogger: Logger): Logger;
|
|
|
49
49
|
*
|
|
50
50
|
* @example
|
|
51
51
|
* // In a NestJS interceptor:
|
|
52
|
-
*
|
|
52
|
+
* withLogAttributes({ user: { id: 'abc' }, url: { path: '/api/items' } }, () => {
|
|
53
53
|
* next.handle().subscribe(...);
|
|
54
54
|
* });
|
|
55
55
|
*
|
|
56
56
|
* // In a Lambda handler:
|
|
57
|
-
*
|
|
57
|
+
* withLogAttributes({ 'batch.id': batchId }, async () => {
|
|
58
58
|
* await processBatch(items);
|
|
59
59
|
* });
|
|
60
60
|
*/
|
|
61
|
-
export declare function
|
|
61
|
+
export declare function withLogAttributes<T>(fields: Record<string, unknown>, fn: () => T): T;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loggerStorage = void 0;
|
|
4
4
|
exports.createContextAwareLogger = createContextAwareLogger;
|
|
5
|
-
exports.
|
|
5
|
+
exports.withLogAttributes = withLogAttributes;
|
|
6
6
|
const async_hooks_1 = require("async_hooks");
|
|
7
7
|
/**
|
|
8
8
|
* Stores the current request-scoped child logger per async context.
|
|
9
9
|
* Used by `createContextAwareLogger` to make the `logger` export context-aware,
|
|
10
|
-
* and by `
|
|
10
|
+
* and by `withLogAttributes` to set context for a block of code.
|
|
11
11
|
*/
|
|
12
12
|
exports.loggerStorage = new async_hooks_1.AsyncLocalStorage();
|
|
13
13
|
let _baseLogger;
|
|
@@ -63,16 +63,16 @@ function createContextAwareLogger(baseLogger) {
|
|
|
63
63
|
*
|
|
64
64
|
* @example
|
|
65
65
|
* // In a NestJS interceptor:
|
|
66
|
-
*
|
|
66
|
+
* withLogAttributes({ user: { id: 'abc' }, url: { path: '/api/items' } }, () => {
|
|
67
67
|
* next.handle().subscribe(...);
|
|
68
68
|
* });
|
|
69
69
|
*
|
|
70
70
|
* // In a Lambda handler:
|
|
71
|
-
*
|
|
71
|
+
* withLogAttributes({ 'batch.id': batchId }, async () => {
|
|
72
72
|
* await processBatch(items);
|
|
73
73
|
* });
|
|
74
74
|
*/
|
|
75
|
-
function
|
|
75
|
+
function withLogAttributes(fields, fn) {
|
|
76
76
|
var _a;
|
|
77
77
|
const parent = (_a = exports.loggerStorage.getStore()) !== null && _a !== void 0 ? _a : _baseLogger;
|
|
78
78
|
const child = parent.child(fields);
|