@inference-net/otel-cf-workers 2.2.1 → 2.3.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/dist/index.d.ts +19 -13
- package/dist/index.js +57 -53
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export declare type ConfigurationOption = WorkerOtelConfig | ResolveConfigFn;
|
|
|
71
71
|
export declare class ConsoleTransport implements LogTransport {
|
|
72
72
|
readonly name = "console";
|
|
73
73
|
private options;
|
|
74
|
+
private minSeverity;
|
|
74
75
|
constructor(options?: ConsoleTransportConfig);
|
|
75
76
|
export(logs: ReadableLogRecord[], callback: ExportResultCallback): void;
|
|
76
77
|
private printLog;
|
|
@@ -84,6 +85,7 @@ export declare interface ConsoleTransportConfig {
|
|
|
84
85
|
pretty?: boolean;
|
|
85
86
|
colors?: boolean;
|
|
86
87
|
includeTimestamp?: boolean;
|
|
88
|
+
level?: LogLevel;
|
|
87
89
|
transformLog?: (logRecord: ReadableLogRecord) => ReadableLogRecord;
|
|
88
90
|
}
|
|
89
91
|
|
|
@@ -247,7 +249,8 @@ export declare interface Logger {
|
|
|
247
249
|
error(message: string, attributes?: LogAttributes): void;
|
|
248
250
|
fatal(message: string, attributes?: LogAttributes): void;
|
|
249
251
|
forceFlush(): Promise<void>;
|
|
250
|
-
child(
|
|
252
|
+
child(name: string, attributes?: LogAttributes): Logger;
|
|
253
|
+
setProperties(attributes: LogAttributes): this;
|
|
251
254
|
}
|
|
252
255
|
|
|
253
256
|
export declare interface LoggerOptions {
|
|
@@ -260,6 +263,8 @@ export declare interface LoggerProvider {
|
|
|
260
263
|
shutdown(): Promise<void>;
|
|
261
264
|
}
|
|
262
265
|
|
|
266
|
+
export declare type LogLevel = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
|
|
267
|
+
|
|
263
268
|
export declare interface LogRecord {
|
|
264
269
|
readonly timeUnixNano: HrTime;
|
|
265
270
|
readonly observedTimeUnixNano: HrTime;
|
|
@@ -282,7 +287,6 @@ export declare interface LogsConfig {
|
|
|
282
287
|
transports?: LogTransport[];
|
|
283
288
|
batching?: BatchConfig;
|
|
284
289
|
instrumentation?: LogsInstrumentationOptions;
|
|
285
|
-
level?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
286
290
|
}
|
|
287
291
|
|
|
288
292
|
export declare interface LogsInstrumentationOptions {
|
|
@@ -350,6 +354,7 @@ export declare class OTLPTransport implements LogTransport {
|
|
|
350
354
|
readonly name = "otlp";
|
|
351
355
|
private headers;
|
|
352
356
|
private url;
|
|
357
|
+
private minSeverity;
|
|
353
358
|
constructor(config: OTLPTransportConfig);
|
|
354
359
|
export(logs: ReadableLogRecord[], callback: ExportResultCallback): void;
|
|
355
360
|
private _export;
|
|
@@ -366,6 +371,7 @@ export declare class OTLPTransport implements LogTransport {
|
|
|
366
371
|
export declare interface OTLPTransportConfig {
|
|
367
372
|
url: string;
|
|
368
373
|
headers?: Record<string, string>;
|
|
374
|
+
level?: LogLevel;
|
|
369
375
|
}
|
|
370
376
|
|
|
371
377
|
export declare interface ParentRatioSamplingConfig {
|
|
@@ -393,7 +399,6 @@ export declare type ResolveConfigFn<Env = any> = (env: Env, trigger: Trigger) =>
|
|
|
393
399
|
export declare interface ResolvedLogsConfig {
|
|
394
400
|
processors: LogRecordProcessor[];
|
|
395
401
|
instrumentation: LogsInstrumentationOptions;
|
|
396
|
-
level: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
397
402
|
}
|
|
398
403
|
|
|
399
404
|
export declare interface ResolvedTraceConfig extends TraceConfigBase {
|
|
@@ -558,11 +563,8 @@ export declare class WorkerLogger implements Logger {
|
|
|
558
563
|
private readonly resource;
|
|
559
564
|
private readonly name;
|
|
560
565
|
private readonly version?;
|
|
561
|
-
private
|
|
562
|
-
|
|
563
|
-
constructor(name: string, processors: LogRecordProcessor[], resource: Resource, version?: string, inheritedAttributes?: LogAttributes, minLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal');
|
|
564
|
-
private levelToSeverity;
|
|
565
|
-
private shouldEmit;
|
|
566
|
+
private properties;
|
|
567
|
+
constructor(name: string, processors: LogRecordProcessor[], resource: Resource, version?: string, properties?: LogAttributes);
|
|
566
568
|
emit(logRecord: Partial<LogRecord>): void;
|
|
567
569
|
trace(message: string, attributes?: LogAttributes): void;
|
|
568
570
|
debug(message: string, attributes?: LogAttributes): void;
|
|
@@ -572,18 +574,22 @@ export declare class WorkerLogger implements Logger {
|
|
|
572
574
|
fatal(message: string, attributes?: LogAttributes): void;
|
|
573
575
|
forceFlush(): Promise<void>;
|
|
574
576
|
/**
|
|
575
|
-
* Create a child logger that inherits
|
|
576
|
-
* Child
|
|
577
|
+
* Create a child logger with a concatenated name (parent:child) that inherits properties from this logger
|
|
578
|
+
* Child properties are merged with parent properties (child takes precedence)
|
|
579
|
+
*/
|
|
580
|
+
child(name: string, attributes?: LogAttributes): Logger;
|
|
581
|
+
/**
|
|
582
|
+
* Add properties to this logger that will be included in all future log records
|
|
583
|
+
* New properties are merged with existing properties (new takes precedence)
|
|
577
584
|
*/
|
|
578
|
-
|
|
585
|
+
setProperties(attributes: LogAttributes): this;
|
|
579
586
|
}
|
|
580
587
|
|
|
581
588
|
export declare class WorkerLoggerProvider implements LoggerProvider {
|
|
582
589
|
private loggers;
|
|
583
590
|
private processors;
|
|
584
591
|
private resource;
|
|
585
|
-
|
|
586
|
-
constructor(processors: LogRecordProcessor[], resource: Resource, minLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal');
|
|
592
|
+
constructor(processors: LogRecordProcessor[], resource: Resource);
|
|
587
593
|
getLogger(name: string, version?: string, options?: LoggerOptions): Logger;
|
|
588
594
|
register(): void;
|
|
589
595
|
shutdown(): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -96,7 +96,7 @@ function passthroughGet(target, prop, thisArg) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
const PACKAGE_VERSION = "2.
|
|
99
|
+
const PACKAGE_VERSION = "2.3.0";
|
|
100
100
|
const PACKAGE_NAME = "@inference-net/otel-cf-workers";
|
|
101
101
|
const ATTR_CLOUDFLARE_COLO = "cloudflare.colo";
|
|
102
102
|
const ATTR_CLOUDFLARE_RAY_ID = "cloudflare.ray_id";
|
|
@@ -600,8 +600,7 @@ function parseLogsConfig(supplied) {
|
|
|
600
600
|
processors,
|
|
601
601
|
instrumentation: {
|
|
602
602
|
instrumentConsole: supplied.instrumentation?.instrumentConsole ?? false
|
|
603
|
-
}
|
|
604
|
-
level: supplied.level ?? "info"
|
|
603
|
+
}
|
|
605
604
|
};
|
|
606
605
|
}
|
|
607
606
|
|
|
@@ -1127,38 +1126,17 @@ class WorkerLogger {
|
|
|
1127
1126
|
resource;
|
|
1128
1127
|
name;
|
|
1129
1128
|
version;
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
constructor(name, processors, resource, version, inheritedAttributes, minLevel = "info") {
|
|
1129
|
+
properties;
|
|
1130
|
+
constructor(name, processors, resource, version, properties) {
|
|
1133
1131
|
this.name = name;
|
|
1134
1132
|
this.processors = processors;
|
|
1135
1133
|
this.resource = resource;
|
|
1136
1134
|
this.version = version;
|
|
1137
|
-
this.
|
|
1138
|
-
this.minSeverity = this.levelToSeverity(minLevel);
|
|
1139
|
-
}
|
|
1140
|
-
levelToSeverity(level) {
|
|
1141
|
-
switch (level) {
|
|
1142
|
-
case "trace":
|
|
1143
|
-
return SEVERITY_NUMBERS.TRACE;
|
|
1144
|
-
case "debug":
|
|
1145
|
-
return SEVERITY_NUMBERS.DEBUG;
|
|
1146
|
-
case "info":
|
|
1147
|
-
return SEVERITY_NUMBERS.INFO;
|
|
1148
|
-
case "warn":
|
|
1149
|
-
return SEVERITY_NUMBERS.WARN;
|
|
1150
|
-
case "error":
|
|
1151
|
-
return SEVERITY_NUMBERS.ERROR;
|
|
1152
|
-
case "fatal":
|
|
1153
|
-
return SEVERITY_NUMBERS.FATAL;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
shouldEmit(severityNumber) {
|
|
1157
|
-
return severityNumber >= this.minSeverity;
|
|
1135
|
+
this.properties = properties || {};
|
|
1158
1136
|
}
|
|
1159
1137
|
emit(logRecord) {
|
|
1160
1138
|
const mergedAttributes = {
|
|
1161
|
-
...this.
|
|
1139
|
+
...this.properties,
|
|
1162
1140
|
...logRecord.attributes || {}
|
|
1163
1141
|
};
|
|
1164
1142
|
const record = new LogRecordImpl({
|
|
@@ -1176,7 +1154,6 @@ class WorkerLogger {
|
|
|
1176
1154
|
});
|
|
1177
1155
|
}
|
|
1178
1156
|
trace(message, attributes) {
|
|
1179
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.TRACE)) return;
|
|
1180
1157
|
this.emit({
|
|
1181
1158
|
severityNumber: SEVERITY_NUMBERS.TRACE,
|
|
1182
1159
|
severityText: "TRACE",
|
|
@@ -1185,7 +1162,6 @@ class WorkerLogger {
|
|
|
1185
1162
|
});
|
|
1186
1163
|
}
|
|
1187
1164
|
debug(message, attributes) {
|
|
1188
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.DEBUG)) return;
|
|
1189
1165
|
this.emit({
|
|
1190
1166
|
severityNumber: SEVERITY_NUMBERS.DEBUG,
|
|
1191
1167
|
severityText: "DEBUG",
|
|
@@ -1194,7 +1170,6 @@ class WorkerLogger {
|
|
|
1194
1170
|
});
|
|
1195
1171
|
}
|
|
1196
1172
|
info(message, attributes) {
|
|
1197
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.INFO)) return;
|
|
1198
1173
|
this.emit({
|
|
1199
1174
|
severityNumber: SEVERITY_NUMBERS.INFO,
|
|
1200
1175
|
severityText: "INFO",
|
|
@@ -1203,7 +1178,6 @@ class WorkerLogger {
|
|
|
1203
1178
|
});
|
|
1204
1179
|
}
|
|
1205
1180
|
warn(message, attributes) {
|
|
1206
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.WARN)) return;
|
|
1207
1181
|
this.emit({
|
|
1208
1182
|
severityNumber: SEVERITY_NUMBERS.WARN,
|
|
1209
1183
|
severityText: "WARN",
|
|
@@ -1212,7 +1186,6 @@ class WorkerLogger {
|
|
|
1212
1186
|
});
|
|
1213
1187
|
}
|
|
1214
1188
|
error(message, attributes) {
|
|
1215
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.ERROR)) return;
|
|
1216
1189
|
const exception = attributes?.["error"] instanceof Error ? attributes["error"] : void 0;
|
|
1217
1190
|
const activeSpan = trace.getActiveSpan();
|
|
1218
1191
|
if (activeSpan) {
|
|
@@ -1229,7 +1202,6 @@ class WorkerLogger {
|
|
|
1229
1202
|
});
|
|
1230
1203
|
}
|
|
1231
1204
|
fatal(message, attributes) {
|
|
1232
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.FATAL)) return;
|
|
1233
1205
|
const exception = attributes?.["error"] instanceof Error ? attributes["error"] : void 0;
|
|
1234
1206
|
const activeSpan = trace.getActiveSpan();
|
|
1235
1207
|
if (activeSpan) {
|
|
@@ -1250,22 +1222,27 @@ class WorkerLogger {
|
|
|
1250
1222
|
await Promise.allSettled(promises);
|
|
1251
1223
|
}
|
|
1252
1224
|
/**
|
|
1253
|
-
* Create a child logger that inherits
|
|
1254
|
-
* Child
|
|
1225
|
+
* Create a child logger with a concatenated name (parent:child) that inherits properties from this logger
|
|
1226
|
+
* Child properties are merged with parent properties (child takes precedence)
|
|
1255
1227
|
*/
|
|
1256
|
-
child(attributes) {
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1228
|
+
child(name, attributes) {
|
|
1229
|
+
const childName = `${this.name}:${name}`;
|
|
1230
|
+
const mergedProperties = {
|
|
1231
|
+
...this.properties,
|
|
1232
|
+
...attributes || {}
|
|
1233
|
+
};
|
|
1234
|
+
return new WorkerLogger(childName, this.processors, this.resource, this.version, mergedProperties);
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Add properties to this logger that will be included in all future log records
|
|
1238
|
+
* New properties are merged with existing properties (new takes precedence)
|
|
1239
|
+
*/
|
|
1240
|
+
setProperties(attributes) {
|
|
1241
|
+
this.properties = {
|
|
1242
|
+
...this.properties,
|
|
1259
1243
|
...attributes
|
|
1260
1244
|
};
|
|
1261
|
-
|
|
1262
|
-
if (this.minSeverity <= SEVERITY_NUMBERS.TRACE) minLevel = "trace";
|
|
1263
|
-
else if (this.minSeverity <= SEVERITY_NUMBERS.DEBUG) minLevel = "debug";
|
|
1264
|
-
else if (this.minSeverity <= SEVERITY_NUMBERS.INFO) minLevel = "info";
|
|
1265
|
-
else if (this.minSeverity <= SEVERITY_NUMBERS.WARN) minLevel = "warn";
|
|
1266
|
-
else if (this.minSeverity <= SEVERITY_NUMBERS.ERROR) minLevel = "error";
|
|
1267
|
-
else minLevel = "fatal";
|
|
1268
|
-
return new WorkerLogger(this.name, this.processors, this.resource, this.version, mergedAttributes, minLevel);
|
|
1245
|
+
return this;
|
|
1269
1246
|
}
|
|
1270
1247
|
}
|
|
1271
1248
|
|
|
@@ -1280,16 +1257,14 @@ class WorkerLoggerProvider {
|
|
|
1280
1257
|
loggers = /* @__PURE__ */ new Map();
|
|
1281
1258
|
processors;
|
|
1282
1259
|
resource;
|
|
1283
|
-
|
|
1284
|
-
constructor(processors, resource, minLevel = "info") {
|
|
1260
|
+
constructor(processors, resource) {
|
|
1285
1261
|
this.processors = processors;
|
|
1286
1262
|
this.resource = resource;
|
|
1287
|
-
this.minLevel = minLevel;
|
|
1288
1263
|
}
|
|
1289
1264
|
getLogger(name, version, options) {
|
|
1290
1265
|
const key = `${name}@${version || ""}:${options?.schemaUrl || ""}`;
|
|
1291
1266
|
if (!this.loggers.has(key)) {
|
|
1292
|
-
this.loggers.set(key, new WorkerLogger(name, this.processors, this.resource, version
|
|
1267
|
+
this.loggers.set(key, new WorkerLogger(name, this.processors, this.resource, version));
|
|
1293
1268
|
}
|
|
1294
1269
|
return this.loggers.get(key);
|
|
1295
1270
|
}
|
|
@@ -1320,6 +1295,9 @@ class NoopLogger {
|
|
|
1320
1295
|
child() {
|
|
1321
1296
|
return this;
|
|
1322
1297
|
}
|
|
1298
|
+
setProperties() {
|
|
1299
|
+
return this;
|
|
1300
|
+
}
|
|
1323
1301
|
}
|
|
1324
1302
|
class NoopLoggerProvider {
|
|
1325
1303
|
logger = new NoopLogger();
|
|
@@ -3582,7 +3560,7 @@ function init(config, serviceConfig, propagator) {
|
|
|
3582
3560
|
traceProvider.register();
|
|
3583
3561
|
}
|
|
3584
3562
|
if (config.logs && config.logs.processors.length > 0) {
|
|
3585
|
-
const logsProvider = new WorkerLoggerProvider(config.logs.processors, resource
|
|
3563
|
+
const logsProvider = new WorkerLoggerProvider(config.logs.processors, resource);
|
|
3586
3564
|
logsProvider.register();
|
|
3587
3565
|
if (config.logs.instrumentation.instrumentConsole) {
|
|
3588
3566
|
import('./console-Cy5QdByD.js').then(({ instrumentConsole }) => {
|
|
@@ -3748,16 +3726,39 @@ class MultiSpanExporterAsync {
|
|
|
3748
3726
|
}
|
|
3749
3727
|
}
|
|
3750
3728
|
|
|
3729
|
+
function levelToSeverity(level) {
|
|
3730
|
+
switch (level) {
|
|
3731
|
+
case "TRACE":
|
|
3732
|
+
return SEVERITY_NUMBERS.TRACE;
|
|
3733
|
+
case "DEBUG":
|
|
3734
|
+
return SEVERITY_NUMBERS.DEBUG;
|
|
3735
|
+
case "INFO":
|
|
3736
|
+
return SEVERITY_NUMBERS.INFO;
|
|
3737
|
+
case "WARN":
|
|
3738
|
+
return SEVERITY_NUMBERS.WARN;
|
|
3739
|
+
case "ERROR":
|
|
3740
|
+
return SEVERITY_NUMBERS.ERROR;
|
|
3741
|
+
case "FATAL":
|
|
3742
|
+
return SEVERITY_NUMBERS.FATAL;
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3751
3745
|
class OTLPTransport {
|
|
3752
3746
|
name = "otlp";
|
|
3753
3747
|
headers;
|
|
3754
3748
|
url;
|
|
3749
|
+
minSeverity;
|
|
3755
3750
|
constructor(config) {
|
|
3756
3751
|
this.url = config.url;
|
|
3757
3752
|
this.headers = Object.assign({}, DEFAULT_OTLP_HEADERS, config.headers);
|
|
3753
|
+
this.minSeverity = levelToSeverity(config.level ?? "TRACE");
|
|
3758
3754
|
}
|
|
3759
3755
|
export(logs, callback) {
|
|
3760
|
-
|
|
3756
|
+
const filteredLogs = logs.filter((log) => (log.severityNumber ?? 0) >= this.minSeverity);
|
|
3757
|
+
if (filteredLogs.length === 0) {
|
|
3758
|
+
callback({ code: ExportResultCode.SUCCESS });
|
|
3759
|
+
return;
|
|
3760
|
+
}
|
|
3761
|
+
this._export(filteredLogs).then(() => {
|
|
3761
3762
|
callback({ code: ExportResultCode.SUCCESS });
|
|
3762
3763
|
}).catch((error) => {
|
|
3763
3764
|
callback({ code: ExportResultCode.FAILED, error });
|
|
@@ -3885,6 +3886,7 @@ class OTLPTransport {
|
|
|
3885
3886
|
class ConsoleTransport {
|
|
3886
3887
|
name = "console";
|
|
3887
3888
|
options;
|
|
3889
|
+
minSeverity;
|
|
3888
3890
|
constructor(options = {}) {
|
|
3889
3891
|
this.options = {
|
|
3890
3892
|
pretty: options.pretty ?? true,
|
|
@@ -3892,10 +3894,12 @@ class ConsoleTransport {
|
|
|
3892
3894
|
includeTimestamp: options.includeTimestamp ?? true,
|
|
3893
3895
|
transformLog: options.transformLog ?? ((l) => l)
|
|
3894
3896
|
};
|
|
3897
|
+
this.minSeverity = levelToSeverity(options.level ?? "TRACE");
|
|
3895
3898
|
}
|
|
3896
3899
|
export(logs, callback) {
|
|
3897
3900
|
try {
|
|
3898
3901
|
for (const log of logs) {
|
|
3902
|
+
if ((log.severityNumber ?? 0) < this.minSeverity) continue;
|
|
3899
3903
|
this.printLog(this.options.transformLog ? this.options.transformLog(log) : log);
|
|
3900
3904
|
}
|
|
3901
3905
|
callback({ code: ExportResultCode.SUCCESS });
|