@contrail/telemetry 2.0.3 → 2.0.4-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/CHANGELOG.md +6 -0
- package/lib/logger/index.js +24 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.0.4] - 2026-04-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Duplicate module detection** — logs a `stderr` warning at cold start if two copies of `@contrail/telemetry` are loaded, so silent log loss and broken context propagation are immediately visible.
|
|
15
|
+
|
|
10
16
|
## [2.0.3] - 2026-04-15
|
|
11
17
|
|
|
12
18
|
### Changed
|
package/lib/logger/index.js
CHANGED
|
@@ -32,6 +32,30 @@ Object.defineProperty(exports, "ATTR_LOG_PAYLOAD", { enumerable: true, get: func
|
|
|
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
34
|
Object.defineProperty(exports, "withLogAttributes", { enumerable: true, get: function () { return log_context_1.withLogAttributes; } });
|
|
35
|
+
// --- Singleton Guard ---
|
|
36
|
+
// The logger uses AsyncLocalStorage for request context propagation. If two copies
|
|
37
|
+
// of this module are loaded (e.g. due to a version mismatch causing npm to install
|
|
38
|
+
// a nested duplicate), each copy has its own AsyncLocalStorage instance and its own
|
|
39
|
+
// OTel LoggerProvider. Context set in one copy won't be visible in the other, and
|
|
40
|
+
// flushLogs() will only flush the provider it closes over — silently dropping logs.
|
|
41
|
+
//
|
|
42
|
+
// Symbol.for uses the global symbol registry, which is shared across all module
|
|
43
|
+
// instances, so this check fires correctly even when two copies are loaded.
|
|
44
|
+
//
|
|
45
|
+
// Local dev note: running `npm i` inside a lib package directory causes npm v7+ to
|
|
46
|
+
// auto-install peer deps locally. If that package is then symlinked into a service,
|
|
47
|
+
// the nested node_modules travels with it and re-creates the duplicate. Published
|
|
48
|
+
// tarballs don't ship node_modules, so this is local-only.
|
|
49
|
+
const TELEMETRY_SINGLETON_KEY = Symbol.for('@contrail/telemetry/logger-initialized');
|
|
50
|
+
if (global[TELEMETRY_SINGLETON_KEY]) {
|
|
51
|
+
process.stderr.write('[WARN] @contrail/telemetry loaded twice — duplicate module instance detected. ' +
|
|
52
|
+
'flushLogs() will only flush one provider and log context may not propagate correctly. ' +
|
|
53
|
+
'Ensure @contrail/telemetry is listed as a peerDependency in any library that re-exports ' +
|
|
54
|
+
'it, and that the host service lists it in its own package.json.\n');
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
global[TELEMETRY_SINGLETON_KEY] = true;
|
|
58
|
+
}
|
|
35
59
|
// --- Environment & Resource Setup ---
|
|
36
60
|
const semantic_conventions_4 = require("../semantic-conventions");
|
|
37
61
|
const LAMBDA_ENV_OTEL_ATTRIBUTES = getLambdaEnvAttributes();
|