@foam-ai/node-cliengo 0.1.0-alpha.11 → 0.1.0-alpha.13
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.
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
* features (trace propagation, log enrichment, NR bridging) still work.
|
|
25
25
|
* - Token undefined + forceExport: throws (fail-fast — you asked to force
|
|
26
26
|
* export but provided no credentials).
|
|
27
|
-
* -
|
|
28
|
-
* default Foam endpoint; custom endpoints are only for dev/staging.
|
|
27
|
+
* - Endpoint is always the production Foam endpoint — not configurable.
|
|
29
28
|
* - Auto-shutdown (SIGTERM/SIGINT): flushes all providers with 5s timeout,
|
|
30
29
|
* then calls process.exit(0). Without the explicit exit, registering
|
|
31
30
|
* process.on('SIGTERM') replaces Node's default terminate behavior — services
|
|
@@ -50,4 +49,4 @@
|
|
|
50
49
|
* global registrations.
|
|
51
50
|
*/
|
|
52
51
|
import type { InitOptions, FoamInstance } from './types';
|
|
53
|
-
export declare function init(serviceName: string,
|
|
52
|
+
export declare function init(serviceName: string, options?: InitOptions): FoamInstance;
|
|
@@ -25,8 +25,7 @@
|
|
|
25
25
|
* features (trace propagation, log enrichment, NR bridging) still work.
|
|
26
26
|
* - Token undefined + forceExport: throws (fail-fast — you asked to force
|
|
27
27
|
* export but provided no credentials).
|
|
28
|
-
* -
|
|
29
|
-
* default Foam endpoint; custom endpoints are only for dev/staging.
|
|
28
|
+
* - Endpoint is always the production Foam endpoint — not configurable.
|
|
30
29
|
* - Auto-shutdown (SIGTERM/SIGINT): flushes all providers with 5s timeout,
|
|
31
30
|
* then calls process.exit(0). Without the explicit exit, registering
|
|
32
31
|
* process.on('SIGTERM') replaces Node's default terminate behavior — services
|
|
@@ -104,6 +103,11 @@ function createInertInstance(serviceName) {
|
|
|
104
103
|
createPinoDestination: () => new node_stream_1.Writable({
|
|
105
104
|
write: (_c, _e, cb) => cb(),
|
|
106
105
|
}),
|
|
106
|
+
createPinoLogger: (opts = {}) => {
|
|
107
|
+
const pino = require('pino');
|
|
108
|
+
return pino({ ...opts });
|
|
109
|
+
},
|
|
110
|
+
createPinoHttpConfig: () => ({}),
|
|
107
111
|
buildTraceparent: trace_bridge_1.buildTraceparent,
|
|
108
112
|
injectSnsAttributes: sns_1.injectSnsAttributes,
|
|
109
113
|
injectJobData: job_1.injectJobData,
|
|
@@ -117,7 +121,7 @@ function createInertInstance(serviceName) {
|
|
|
117
121
|
};
|
|
118
122
|
}
|
|
119
123
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call */
|
|
120
|
-
function init(serviceName,
|
|
124
|
+
function init(serviceName, options = {}) {
|
|
121
125
|
const existing = instances.get(serviceName);
|
|
122
126
|
if (existing) {
|
|
123
127
|
// eslint-disable-next-line no-console
|
|
@@ -134,23 +138,21 @@ function init(serviceName, token, options = {}) {
|
|
|
134
138
|
}
|
|
135
139
|
// Resolve NR
|
|
136
140
|
(0, nr_1.resolveNewRelic)(options.newrelic);
|
|
141
|
+
const token = options.token;
|
|
137
142
|
// Production gate
|
|
138
143
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
139
144
|
const shouldExport = isProduction || (options.forceExport === true);
|
|
140
145
|
// Token validation
|
|
141
146
|
if (shouldExport && !token) {
|
|
142
147
|
if (options.forceExport) {
|
|
143
|
-
throw new Error('[foam] forceExport is true but no
|
|
148
|
+
throw new Error('[foam] forceExport is true but no token provided — cannot export telemetry');
|
|
144
149
|
}
|
|
145
150
|
// eslint-disable-next-line no-console
|
|
146
|
-
console.warn('[foam] no
|
|
151
|
+
console.warn('[foam] no token provided — OTLP export disabled');
|
|
147
152
|
}
|
|
148
153
|
const hasToken = Boolean(token);
|
|
149
154
|
const canExport = shouldExport && hasToken;
|
|
150
|
-
|
|
151
|
-
throw new Error('[foam] custom endpoint requires forceExport: true — production always uses the default Foam endpoint');
|
|
152
|
-
}
|
|
153
|
-
const endpoint = options.endpoint ?? constants_1.FOAM_OTEL_ENDPOINT;
|
|
155
|
+
const endpoint = constants_1.FOAM_OTEL_ENDPOINT;
|
|
154
156
|
const resource = (0, resources_1.resourceFromAttributes)({ 'service.name': serviceName });
|
|
155
157
|
const authHeaders = token
|
|
156
158
|
? { Authorization: `Bearer ${token}` }
|
|
@@ -342,6 +344,19 @@ function init(serviceName, token, options = {}) {
|
|
|
342
344
|
createPinoMixin: () => (0, pino_mixin_1.createPinoMixin)(),
|
|
343
345
|
createPinoHttpOptions: () => (0, express_1.createPinoHttpOptions)(),
|
|
344
346
|
createPinoDestination: () => (0, pino_destination_1.createPinoDestination)(loggerProvider, serviceName),
|
|
347
|
+
createPinoLogger: (opts = {}) => {
|
|
348
|
+
const pino = require('pino');
|
|
349
|
+
const mixin = (0, pino_mixin_1.createPinoMixin)();
|
|
350
|
+
const dest = (0, pino_destination_1.createPinoDestination)(loggerProvider, serviceName);
|
|
351
|
+
return pino({ ...opts, mixin }, pino.multistream([
|
|
352
|
+
{ stream: process.stdout },
|
|
353
|
+
{ stream: dest },
|
|
354
|
+
]));
|
|
355
|
+
},
|
|
356
|
+
createPinoHttpConfig: () => {
|
|
357
|
+
const pinoHttpOpts = (0, express_1.createPinoHttpOptions)();
|
|
358
|
+
return { ...pinoHttpOpts };
|
|
359
|
+
},
|
|
345
360
|
buildTraceparent: trace_bridge_1.buildTraceparent,
|
|
346
361
|
injectSnsAttributes: sns_1.injectSnsAttributes,
|
|
347
362
|
injectJobData: job_1.injectJobData,
|
|
@@ -27,12 +27,12 @@ import type { MeterProvider } from '@opentelemetry/sdk-metrics';
|
|
|
27
27
|
import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
|
|
28
28
|
export interface InitOptions {
|
|
29
29
|
enabled?: boolean;
|
|
30
|
+
token?: string;
|
|
30
31
|
newrelic?: NewRelicAgent;
|
|
31
32
|
winston?: WinstonLogger;
|
|
32
33
|
enableTraces?: boolean;
|
|
33
34
|
enableLogs?: boolean;
|
|
34
35
|
enableMetrics?: boolean;
|
|
35
|
-
endpoint?: string;
|
|
36
36
|
forceExport?: boolean;
|
|
37
37
|
autoShutdown?: boolean;
|
|
38
38
|
}
|
|
@@ -65,6 +65,8 @@ export interface FoamInstance {
|
|
|
65
65
|
customProps: (req: any) => Record<string, string>;
|
|
66
66
|
};
|
|
67
67
|
createPinoDestination(): NodeJS.WritableStream;
|
|
68
|
+
createPinoLogger(options?: Record<string, any>): any;
|
|
69
|
+
createPinoHttpConfig(): Record<string, any>;
|
|
68
70
|
buildTraceparent(): string;
|
|
69
71
|
injectSnsAttributes(attrs: Record<string, SnsMessageAttributeValue>): Record<string, SnsMessageAttributeValue>;
|
|
70
72
|
injectJobData<T extends Record<string, unknown>>(data: T): T & {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foam-ai/node-cliengo",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.13",
|
|
4
4
|
"description": "Unified observability (traces, logs, metrics) for Cliengo Node.js services, connecting New Relic APM with Foam's OTel collector.",
|
|
5
5
|
"main": "dist/node-cliengo/src/index.js",
|
|
6
6
|
"types": "dist/node-cliengo/src/index.d.ts",
|