@inference-net/otel-cf-workers 2.2.1 → 2.4.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 +60 -54
- 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.4.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";
|
|
@@ -292,12 +292,13 @@ class OTLPExporter {
|
|
|
292
292
|
headers: this.headers,
|
|
293
293
|
body
|
|
294
294
|
};
|
|
295
|
-
unwrap(fetch)(this.url, params).then((response) => {
|
|
295
|
+
unwrap(fetch)(this.url, params).then(async (response) => {
|
|
296
296
|
if (response.ok) {
|
|
297
297
|
onSuccess();
|
|
298
298
|
} else {
|
|
299
299
|
onError(new OTLPExporterError(`Exporter received a statusCode: ${response.status}`));
|
|
300
300
|
}
|
|
301
|
+
await response.body?.cancel();
|
|
301
302
|
}).catch((error) => {
|
|
302
303
|
onError(new OTLPExporterError(`Exception during export: ${error.toString()}`, error.code, error.stack));
|
|
303
304
|
});
|
|
@@ -600,8 +601,7 @@ function parseLogsConfig(supplied) {
|
|
|
600
601
|
processors,
|
|
601
602
|
instrumentation: {
|
|
602
603
|
instrumentConsole: supplied.instrumentation?.instrumentConsole ?? false
|
|
603
|
-
}
|
|
604
|
-
level: supplied.level ?? "info"
|
|
604
|
+
}
|
|
605
605
|
};
|
|
606
606
|
}
|
|
607
607
|
|
|
@@ -1127,38 +1127,17 @@ class WorkerLogger {
|
|
|
1127
1127
|
resource;
|
|
1128
1128
|
name;
|
|
1129
1129
|
version;
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
constructor(name, processors, resource, version, inheritedAttributes, minLevel = "info") {
|
|
1130
|
+
properties;
|
|
1131
|
+
constructor(name, processors, resource, version, properties) {
|
|
1133
1132
|
this.name = name;
|
|
1134
1133
|
this.processors = processors;
|
|
1135
1134
|
this.resource = resource;
|
|
1136
1135
|
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;
|
|
1136
|
+
this.properties = properties || {};
|
|
1158
1137
|
}
|
|
1159
1138
|
emit(logRecord) {
|
|
1160
1139
|
const mergedAttributes = {
|
|
1161
|
-
...this.
|
|
1140
|
+
...this.properties,
|
|
1162
1141
|
...logRecord.attributes || {}
|
|
1163
1142
|
};
|
|
1164
1143
|
const record = new LogRecordImpl({
|
|
@@ -1176,7 +1155,6 @@ class WorkerLogger {
|
|
|
1176
1155
|
});
|
|
1177
1156
|
}
|
|
1178
1157
|
trace(message, attributes) {
|
|
1179
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.TRACE)) return;
|
|
1180
1158
|
this.emit({
|
|
1181
1159
|
severityNumber: SEVERITY_NUMBERS.TRACE,
|
|
1182
1160
|
severityText: "TRACE",
|
|
@@ -1185,7 +1163,6 @@ class WorkerLogger {
|
|
|
1185
1163
|
});
|
|
1186
1164
|
}
|
|
1187
1165
|
debug(message, attributes) {
|
|
1188
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.DEBUG)) return;
|
|
1189
1166
|
this.emit({
|
|
1190
1167
|
severityNumber: SEVERITY_NUMBERS.DEBUG,
|
|
1191
1168
|
severityText: "DEBUG",
|
|
@@ -1194,7 +1171,6 @@ class WorkerLogger {
|
|
|
1194
1171
|
});
|
|
1195
1172
|
}
|
|
1196
1173
|
info(message, attributes) {
|
|
1197
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.INFO)) return;
|
|
1198
1174
|
this.emit({
|
|
1199
1175
|
severityNumber: SEVERITY_NUMBERS.INFO,
|
|
1200
1176
|
severityText: "INFO",
|
|
@@ -1203,7 +1179,6 @@ class WorkerLogger {
|
|
|
1203
1179
|
});
|
|
1204
1180
|
}
|
|
1205
1181
|
warn(message, attributes) {
|
|
1206
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.WARN)) return;
|
|
1207
1182
|
this.emit({
|
|
1208
1183
|
severityNumber: SEVERITY_NUMBERS.WARN,
|
|
1209
1184
|
severityText: "WARN",
|
|
@@ -1212,7 +1187,6 @@ class WorkerLogger {
|
|
|
1212
1187
|
});
|
|
1213
1188
|
}
|
|
1214
1189
|
error(message, attributes) {
|
|
1215
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.ERROR)) return;
|
|
1216
1190
|
const exception = attributes?.["error"] instanceof Error ? attributes["error"] : void 0;
|
|
1217
1191
|
const activeSpan = trace.getActiveSpan();
|
|
1218
1192
|
if (activeSpan) {
|
|
@@ -1229,7 +1203,6 @@ class WorkerLogger {
|
|
|
1229
1203
|
});
|
|
1230
1204
|
}
|
|
1231
1205
|
fatal(message, attributes) {
|
|
1232
|
-
if (!this.shouldEmit(SEVERITY_NUMBERS.FATAL)) return;
|
|
1233
1206
|
const exception = attributes?.["error"] instanceof Error ? attributes["error"] : void 0;
|
|
1234
1207
|
const activeSpan = trace.getActiveSpan();
|
|
1235
1208
|
if (activeSpan) {
|
|
@@ -1250,22 +1223,27 @@ class WorkerLogger {
|
|
|
1250
1223
|
await Promise.allSettled(promises);
|
|
1251
1224
|
}
|
|
1252
1225
|
/**
|
|
1253
|
-
* Create a child logger that inherits
|
|
1254
|
-
* Child
|
|
1226
|
+
* Create a child logger with a concatenated name (parent:child) that inherits properties from this logger
|
|
1227
|
+
* Child properties are merged with parent properties (child takes precedence)
|
|
1255
1228
|
*/
|
|
1256
|
-
child(attributes) {
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1229
|
+
child(name, attributes) {
|
|
1230
|
+
const childName = `${this.name}:${name}`;
|
|
1231
|
+
const mergedProperties = {
|
|
1232
|
+
...this.properties,
|
|
1233
|
+
...attributes || {}
|
|
1234
|
+
};
|
|
1235
|
+
return new WorkerLogger(childName, this.processors, this.resource, this.version, mergedProperties);
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Add properties to this logger that will be included in all future log records
|
|
1239
|
+
* New properties are merged with existing properties (new takes precedence)
|
|
1240
|
+
*/
|
|
1241
|
+
setProperties(attributes) {
|
|
1242
|
+
this.properties = {
|
|
1243
|
+
...this.properties,
|
|
1259
1244
|
...attributes
|
|
1260
1245
|
};
|
|
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);
|
|
1246
|
+
return this;
|
|
1269
1247
|
}
|
|
1270
1248
|
}
|
|
1271
1249
|
|
|
@@ -1280,16 +1258,14 @@ class WorkerLoggerProvider {
|
|
|
1280
1258
|
loggers = /* @__PURE__ */ new Map();
|
|
1281
1259
|
processors;
|
|
1282
1260
|
resource;
|
|
1283
|
-
|
|
1284
|
-
constructor(processors, resource, minLevel = "info") {
|
|
1261
|
+
constructor(processors, resource) {
|
|
1285
1262
|
this.processors = processors;
|
|
1286
1263
|
this.resource = resource;
|
|
1287
|
-
this.minLevel = minLevel;
|
|
1288
1264
|
}
|
|
1289
1265
|
getLogger(name, version, options) {
|
|
1290
1266
|
const key = `${name}@${version || ""}:${options?.schemaUrl || ""}`;
|
|
1291
1267
|
if (!this.loggers.has(key)) {
|
|
1292
|
-
this.loggers.set(key, new WorkerLogger(name, this.processors, this.resource, version
|
|
1268
|
+
this.loggers.set(key, new WorkerLogger(name, this.processors, this.resource, version));
|
|
1293
1269
|
}
|
|
1294
1270
|
return this.loggers.get(key);
|
|
1295
1271
|
}
|
|
@@ -1320,6 +1296,9 @@ class NoopLogger {
|
|
|
1320
1296
|
child() {
|
|
1321
1297
|
return this;
|
|
1322
1298
|
}
|
|
1299
|
+
setProperties() {
|
|
1300
|
+
return this;
|
|
1301
|
+
}
|
|
1323
1302
|
}
|
|
1324
1303
|
class NoopLoggerProvider {
|
|
1325
1304
|
logger = new NoopLogger();
|
|
@@ -3582,7 +3561,7 @@ function init(config, serviceConfig, propagator) {
|
|
|
3582
3561
|
traceProvider.register();
|
|
3583
3562
|
}
|
|
3584
3563
|
if (config.logs && config.logs.processors.length > 0) {
|
|
3585
|
-
const logsProvider = new WorkerLoggerProvider(config.logs.processors, resource
|
|
3564
|
+
const logsProvider = new WorkerLoggerProvider(config.logs.processors, resource);
|
|
3586
3565
|
logsProvider.register();
|
|
3587
3566
|
if (config.logs.instrumentation.instrumentConsole) {
|
|
3588
3567
|
import('./console-Cy5QdByD.js').then(({ instrumentConsole }) => {
|
|
@@ -3748,16 +3727,39 @@ class MultiSpanExporterAsync {
|
|
|
3748
3727
|
}
|
|
3749
3728
|
}
|
|
3750
3729
|
|
|
3730
|
+
function levelToSeverity(level) {
|
|
3731
|
+
switch (level) {
|
|
3732
|
+
case "TRACE":
|
|
3733
|
+
return SEVERITY_NUMBERS.TRACE;
|
|
3734
|
+
case "DEBUG":
|
|
3735
|
+
return SEVERITY_NUMBERS.DEBUG;
|
|
3736
|
+
case "INFO":
|
|
3737
|
+
return SEVERITY_NUMBERS.INFO;
|
|
3738
|
+
case "WARN":
|
|
3739
|
+
return SEVERITY_NUMBERS.WARN;
|
|
3740
|
+
case "ERROR":
|
|
3741
|
+
return SEVERITY_NUMBERS.ERROR;
|
|
3742
|
+
case "FATAL":
|
|
3743
|
+
return SEVERITY_NUMBERS.FATAL;
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3751
3746
|
class OTLPTransport {
|
|
3752
3747
|
name = "otlp";
|
|
3753
3748
|
headers;
|
|
3754
3749
|
url;
|
|
3750
|
+
minSeverity;
|
|
3755
3751
|
constructor(config) {
|
|
3756
3752
|
this.url = config.url;
|
|
3757
3753
|
this.headers = Object.assign({}, DEFAULT_OTLP_HEADERS, config.headers);
|
|
3754
|
+
this.minSeverity = levelToSeverity(config.level ?? "TRACE");
|
|
3758
3755
|
}
|
|
3759
3756
|
export(logs, callback) {
|
|
3760
|
-
|
|
3757
|
+
const filteredLogs = logs.filter((log) => (log.severityNumber ?? 0) >= this.minSeverity);
|
|
3758
|
+
if (filteredLogs.length === 0) {
|
|
3759
|
+
callback({ code: ExportResultCode.SUCCESS });
|
|
3760
|
+
return;
|
|
3761
|
+
}
|
|
3762
|
+
this._export(filteredLogs).then(() => {
|
|
3761
3763
|
callback({ code: ExportResultCode.SUCCESS });
|
|
3762
3764
|
}).catch((error) => {
|
|
3763
3765
|
callback({ code: ExportResultCode.FAILED, error });
|
|
@@ -3782,6 +3784,7 @@ class OTLPTransport {
|
|
|
3782
3784
|
if (!response.ok) {
|
|
3783
3785
|
throw new OTLPExporterError(`Exporter received a statusCode: ${response.status}`);
|
|
3784
3786
|
}
|
|
3787
|
+
await response.body?.cancel();
|
|
3785
3788
|
}
|
|
3786
3789
|
transformToOTLP(logs) {
|
|
3787
3790
|
const resourceLogsMap = /* @__PURE__ */ new Map();
|
|
@@ -3885,6 +3888,7 @@ class OTLPTransport {
|
|
|
3885
3888
|
class ConsoleTransport {
|
|
3886
3889
|
name = "console";
|
|
3887
3890
|
options;
|
|
3891
|
+
minSeverity;
|
|
3888
3892
|
constructor(options = {}) {
|
|
3889
3893
|
this.options = {
|
|
3890
3894
|
pretty: options.pretty ?? true,
|
|
@@ -3892,10 +3896,12 @@ class ConsoleTransport {
|
|
|
3892
3896
|
includeTimestamp: options.includeTimestamp ?? true,
|
|
3893
3897
|
transformLog: options.transformLog ?? ((l) => l)
|
|
3894
3898
|
};
|
|
3899
|
+
this.minSeverity = levelToSeverity(options.level ?? "TRACE");
|
|
3895
3900
|
}
|
|
3896
3901
|
export(logs, callback) {
|
|
3897
3902
|
try {
|
|
3898
3903
|
for (const log of logs) {
|
|
3904
|
+
if ((log.severityNumber ?? 0) < this.minSeverity) continue;
|
|
3899
3905
|
this.printLog(this.options.transformLog ? this.options.transformLog(log) : log);
|
|
3900
3906
|
}
|
|
3901
3907
|
callback({ code: ExportResultCode.SUCCESS });
|