@contrail/telemetry 2.0.5-alpha-log-body.0 → 2.0.6-alpha.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/CHANGELOG.md +0 -6
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +6 -7
- package/lib/logger/semantic-conventions.d.ts +0 -5
- package/lib/logger/semantic-conventions.js +1 -6
- package/lib/logger/stdout-writer.d.ts +6 -0
- package/lib/logger/stdout-writer.js +20 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,12 +7,6 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [2.0.5] - 2026-04-17
|
|
11
|
-
|
|
12
|
-
### Added
|
|
13
|
-
|
|
14
|
-
- **`contrail.log.body` attribute** — Every OTel log record now carries a `contrail.log.body` custom attribute that duplicates the log body. This enables grouping and filtering by log message in observability UIs (e.g. Dash0) that only expose custom attributes, not the standard `body` field.
|
|
15
|
-
|
|
16
10
|
## [2.0.4] - 2026-04-16
|
|
17
11
|
|
|
18
12
|
### Added
|
package/lib/logger/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
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
|
-
export { ATTR_LOG_MESSAGE,
|
|
4
|
+
export { ATTR_LOG_MESSAGE, ATTR_LOG_PAYLOAD } from './semantic-conventions';
|
|
5
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;
|
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.withLogAttributes = exports.loggerStorage = exports.ATTR_LOG_PAYLOAD = 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"));
|
|
@@ -28,7 +28,6 @@ Object.defineProperty(exports, "PINO_LEVEL_TO_OTEL_SEVERITY", { enumerable: true
|
|
|
28
28
|
Object.defineProperty(exports, "PINO_LEVEL_TO_NAME", { enumerable: true, get: function () { return logger_config_2.PINO_LEVEL_TO_NAME; } });
|
|
29
29
|
var semantic_conventions_3 = require("./semantic-conventions");
|
|
30
30
|
Object.defineProperty(exports, "ATTR_LOG_MESSAGE", { enumerable: true, get: function () { return semantic_conventions_3.ATTR_LOG_MESSAGE; } });
|
|
31
|
-
Object.defineProperty(exports, "ATTR_LOG_BODY", { enumerable: true, get: function () { return semantic_conventions_3.ATTR_LOG_BODY; } });
|
|
32
31
|
Object.defineProperty(exports, "ATTR_LOG_PAYLOAD", { enumerable: true, get: function () { return semantic_conventions_3.ATTR_LOG_PAYLOAD; } });
|
|
33
32
|
var log_context_1 = require("./log-context");
|
|
34
33
|
Object.defineProperty(exports, "loggerStorage", { enumerable: true, get: function () { return log_context_1.loggerStorage; } });
|
|
@@ -83,6 +82,7 @@ const otelLoggerProvider = new sdk_logs_1.LoggerProvider({
|
|
|
83
82
|
});
|
|
84
83
|
const otelLogger = otelLoggerProvider.getLogger(serviceName);
|
|
85
84
|
// --- Pino Stream Destinations ---
|
|
85
|
+
const stdout_writer_1 = require("./stdout-writer");
|
|
86
86
|
function isPinoPrettyInstalled() {
|
|
87
87
|
try {
|
|
88
88
|
require.resolve('pino-pretty');
|
|
@@ -118,14 +118,14 @@ function createStdoutStream() {
|
|
|
118
118
|
const requestId = (_d = getLambdaRequestId()) !== null && _d !== void 0 ? _d : '-';
|
|
119
119
|
const payload = logRecord[semantic_conventions_2.ATTR_LOG_PAYLOAD];
|
|
120
120
|
const payloadLine = payload && typeof payload === 'object' && Object.keys(payload).length > 0
|
|
121
|
-
?
|
|
121
|
+
? `\n${JSON.stringify(payload, null, 2)}`
|
|
122
122
|
: '';
|
|
123
|
-
line = `${time}\t${requestId}\t${level}\t${message}
|
|
123
|
+
line = `${time}\t${requestId}\t${level}\t${message}${payloadLine}`;
|
|
124
124
|
}
|
|
125
125
|
catch {
|
|
126
|
-
line = chunk.toString();
|
|
126
|
+
line = chunk.toString().replace(/\n$/, '');
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
stdout_writer_1.stdoutWriter.log(line);
|
|
129
129
|
callback();
|
|
130
130
|
},
|
|
131
131
|
}),
|
|
@@ -164,7 +164,6 @@ function createOtelStream() {
|
|
|
164
164
|
// environment, even if user code accidentally sets a conflicting key.
|
|
165
165
|
attributes: {
|
|
166
166
|
...safeAttributes,
|
|
167
|
-
[semantic_conventions_2.ATTR_LOG_BODY]: message,
|
|
168
167
|
...lambdaEnvAttributes,
|
|
169
168
|
...spanAttributes,
|
|
170
169
|
},
|
|
@@ -5,11 +5,6 @@
|
|
|
5
5
|
* Attribute key for the log message body.
|
|
6
6
|
*/
|
|
7
7
|
export declare const ATTR_LOG_MESSAGE: "contrail.message";
|
|
8
|
-
/**
|
|
9
|
-
* Custom attribute that duplicates the log body so it is available for
|
|
10
|
-
* grouping / filtering in observability UIs that only expose custom attributes.
|
|
11
|
-
*/
|
|
12
|
-
export declare const ATTR_LOG_BODY: "contrail.log.body";
|
|
13
8
|
/**
|
|
14
9
|
* Attribute key for user-provided log payload objects.
|
|
15
10
|
*/
|
|
@@ -3,16 +3,11 @@
|
|
|
3
3
|
* Log-specific semantic conventions.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ATTR_LOG_PAYLOAD = exports.
|
|
6
|
+
exports.ATTR_LOG_PAYLOAD = exports.ATTR_LOG_MESSAGE = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Attribute key for the log message body.
|
|
9
9
|
*/
|
|
10
10
|
exports.ATTR_LOG_MESSAGE = 'contrail.message';
|
|
11
|
-
/**
|
|
12
|
-
* Custom attribute that duplicates the log body so it is available for
|
|
13
|
-
* grouping / filtering in observability UIs that only expose custom attributes.
|
|
14
|
-
*/
|
|
15
|
-
exports.ATTR_LOG_BODY = 'contrail.log.body';
|
|
16
11
|
/**
|
|
17
12
|
* Attribute key for user-provided log payload objects.
|
|
18
13
|
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stdoutWriter = void 0;
|
|
4
|
+
// Capture console.log so we can use it from the pino stdout stream.
|
|
5
|
+
// Lambda treats each console.log() call as a single CloudWatch log event (even with
|
|
6
|
+
// embedded newlines), unlike process.stdout.write() which splits on \n.
|
|
7
|
+
//
|
|
8
|
+
// Guard: app-framework's hijackConsole() replaces console.log with overridenLog,
|
|
9
|
+
// which routes back into pino — using it here would create an infinite loop.
|
|
10
|
+
// We detect that specific replacement by name. Any other replacement (e.g. the
|
|
11
|
+
// OTel Lambda layer's console patch) is safe to use.
|
|
12
|
+
const _capturedConsoleLog = console.log;
|
|
13
|
+
const isAppFrameworkHijack = _capturedConsoleLog.name === 'overridenLog';
|
|
14
|
+
// Wrapped in an object so tests can jest.spyOn(stdoutWriter, 'log') regardless
|
|
15
|
+
// of Jest's console patching strategy (BufferedConsole vs CustomConsole).
|
|
16
|
+
exports.stdoutWriter = {
|
|
17
|
+
log: isAppFrameworkHijack
|
|
18
|
+
? (...args) => process.stdout.write(args.map(String).join(' ') + '\n')
|
|
19
|
+
: _capturedConsoleLog,
|
|
20
|
+
};
|