@inference-net/otel-cf-workers 2.0.3 → 2.0.5
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 +6 -2
- package/dist/index.js +79 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -522,7 +522,10 @@ export declare class WorkerLogger implements Logger {
|
|
|
522
522
|
private readonly name;
|
|
523
523
|
private readonly version?;
|
|
524
524
|
private readonly inheritedAttributes;
|
|
525
|
-
|
|
525
|
+
private readonly minSeverity;
|
|
526
|
+
constructor(name: string, processors: LogRecordProcessor[], resource: Resource, version?: string, inheritedAttributes?: LogAttributes, minLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal');
|
|
527
|
+
private levelToSeverity;
|
|
528
|
+
private shouldEmit;
|
|
526
529
|
emit(logRecord: Partial<LogRecord>): void;
|
|
527
530
|
trace(message: string, attributes?: LogAttributes): void;
|
|
528
531
|
debug(message: string, attributes?: LogAttributes): void;
|
|
@@ -542,7 +545,8 @@ export declare class WorkerLoggerProvider implements LoggerProvider {
|
|
|
542
545
|
private loggers;
|
|
543
546
|
private processors;
|
|
544
547
|
private resource;
|
|
545
|
-
|
|
548
|
+
private minLevel;
|
|
549
|
+
constructor(processors: LogRecordProcessor[], resource: Resource, minLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal');
|
|
546
550
|
getLogger(name: string, version?: string, options?: LoggerOptions): Logger;
|
|
547
551
|
register(): void;
|
|
548
552
|
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.0.
|
|
99
|
+
const PACKAGE_VERSION = "2.0.5";
|
|
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";
|
|
@@ -1080,12 +1080,33 @@ class WorkerLogger {
|
|
|
1080
1080
|
name;
|
|
1081
1081
|
version;
|
|
1082
1082
|
inheritedAttributes;
|
|
1083
|
-
|
|
1083
|
+
minSeverity;
|
|
1084
|
+
constructor(name, processors, resource, version, inheritedAttributes, minLevel = "info") {
|
|
1084
1085
|
this.name = name;
|
|
1085
1086
|
this.processors = processors;
|
|
1086
1087
|
this.resource = resource;
|
|
1087
1088
|
this.version = version;
|
|
1088
1089
|
this.inheritedAttributes = inheritedAttributes || {};
|
|
1090
|
+
this.minSeverity = this.levelToSeverity(minLevel);
|
|
1091
|
+
}
|
|
1092
|
+
levelToSeverity(level) {
|
|
1093
|
+
switch (level) {
|
|
1094
|
+
case "trace":
|
|
1095
|
+
return SEVERITY_NUMBERS.TRACE;
|
|
1096
|
+
case "debug":
|
|
1097
|
+
return SEVERITY_NUMBERS.DEBUG;
|
|
1098
|
+
case "info":
|
|
1099
|
+
return SEVERITY_NUMBERS.INFO;
|
|
1100
|
+
case "warn":
|
|
1101
|
+
return SEVERITY_NUMBERS.WARN;
|
|
1102
|
+
case "error":
|
|
1103
|
+
return SEVERITY_NUMBERS.ERROR;
|
|
1104
|
+
case "fatal":
|
|
1105
|
+
return SEVERITY_NUMBERS.FATAL;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
shouldEmit(severityNumber) {
|
|
1109
|
+
return severityNumber >= this.minSeverity;
|
|
1089
1110
|
}
|
|
1090
1111
|
emit(logRecord) {
|
|
1091
1112
|
const mergedAttributes = {
|
|
@@ -1107,6 +1128,7 @@ class WorkerLogger {
|
|
|
1107
1128
|
});
|
|
1108
1129
|
}
|
|
1109
1130
|
trace(message, attributes) {
|
|
1131
|
+
if (!this.shouldEmit(SEVERITY_NUMBERS.TRACE)) return;
|
|
1110
1132
|
this.emit({
|
|
1111
1133
|
severityNumber: SEVERITY_NUMBERS.TRACE,
|
|
1112
1134
|
severityText: "TRACE",
|
|
@@ -1115,6 +1137,7 @@ class WorkerLogger {
|
|
|
1115
1137
|
});
|
|
1116
1138
|
}
|
|
1117
1139
|
debug(message, attributes) {
|
|
1140
|
+
if (!this.shouldEmit(SEVERITY_NUMBERS.DEBUG)) return;
|
|
1118
1141
|
this.emit({
|
|
1119
1142
|
severityNumber: SEVERITY_NUMBERS.DEBUG,
|
|
1120
1143
|
severityText: "DEBUG",
|
|
@@ -1123,6 +1146,7 @@ class WorkerLogger {
|
|
|
1123
1146
|
});
|
|
1124
1147
|
}
|
|
1125
1148
|
info(message, attributes) {
|
|
1149
|
+
if (!this.shouldEmit(SEVERITY_NUMBERS.INFO)) return;
|
|
1126
1150
|
this.emit({
|
|
1127
1151
|
severityNumber: SEVERITY_NUMBERS.INFO,
|
|
1128
1152
|
severityText: "INFO",
|
|
@@ -1131,6 +1155,7 @@ class WorkerLogger {
|
|
|
1131
1155
|
});
|
|
1132
1156
|
}
|
|
1133
1157
|
warn(message, attributes) {
|
|
1158
|
+
if (!this.shouldEmit(SEVERITY_NUMBERS.WARN)) return;
|
|
1134
1159
|
this.emit({
|
|
1135
1160
|
severityNumber: SEVERITY_NUMBERS.WARN,
|
|
1136
1161
|
severityText: "WARN",
|
|
@@ -1139,6 +1164,7 @@ class WorkerLogger {
|
|
|
1139
1164
|
});
|
|
1140
1165
|
}
|
|
1141
1166
|
error(message, attributes) {
|
|
1167
|
+
if (!this.shouldEmit(SEVERITY_NUMBERS.ERROR)) return;
|
|
1142
1168
|
let body;
|
|
1143
1169
|
let attrs = { ...attributes };
|
|
1144
1170
|
if (message instanceof Error) {
|
|
@@ -1160,6 +1186,7 @@ class WorkerLogger {
|
|
|
1160
1186
|
});
|
|
1161
1187
|
}
|
|
1162
1188
|
fatal(message, attributes) {
|
|
1189
|
+
if (!this.shouldEmit(SEVERITY_NUMBERS.FATAL)) return;
|
|
1163
1190
|
this.emit({
|
|
1164
1191
|
severityNumber: SEVERITY_NUMBERS.FATAL,
|
|
1165
1192
|
severityText: "FATAL",
|
|
@@ -1180,7 +1207,14 @@ class WorkerLogger {
|
|
|
1180
1207
|
...this.inheritedAttributes,
|
|
1181
1208
|
...attributes
|
|
1182
1209
|
};
|
|
1183
|
-
|
|
1210
|
+
let minLevel = "info";
|
|
1211
|
+
if (this.minSeverity <= SEVERITY_NUMBERS.TRACE) minLevel = "trace";
|
|
1212
|
+
else if (this.minSeverity <= SEVERITY_NUMBERS.DEBUG) minLevel = "debug";
|
|
1213
|
+
else if (this.minSeverity <= SEVERITY_NUMBERS.INFO) minLevel = "info";
|
|
1214
|
+
else if (this.minSeverity <= SEVERITY_NUMBERS.WARN) minLevel = "warn";
|
|
1215
|
+
else if (this.minSeverity <= SEVERITY_NUMBERS.ERROR) minLevel = "error";
|
|
1216
|
+
else minLevel = "fatal";
|
|
1217
|
+
return new WorkerLogger(this.name, this.processors, this.resource, this.version, mergedAttributes, minLevel);
|
|
1184
1218
|
}
|
|
1185
1219
|
}
|
|
1186
1220
|
|
|
@@ -1195,14 +1229,16 @@ class WorkerLoggerProvider {
|
|
|
1195
1229
|
loggers = /* @__PURE__ */ new Map();
|
|
1196
1230
|
processors;
|
|
1197
1231
|
resource;
|
|
1198
|
-
|
|
1232
|
+
minLevel;
|
|
1233
|
+
constructor(processors, resource, minLevel = "info") {
|
|
1199
1234
|
this.processors = processors;
|
|
1200
1235
|
this.resource = resource;
|
|
1236
|
+
this.minLevel = minLevel;
|
|
1201
1237
|
}
|
|
1202
1238
|
getLogger(name, version, options) {
|
|
1203
1239
|
const key = `${name}@${version || ""}:${options?.schemaUrl || ""}`;
|
|
1204
1240
|
if (!this.loggers.has(key)) {
|
|
1205
|
-
this.loggers.set(key, new WorkerLogger(name, this.processors, this.resource, version));
|
|
1241
|
+
this.loggers.set(key, new WorkerLogger(name, this.processors, this.resource, version, void 0, this.minLevel));
|
|
1206
1242
|
}
|
|
1207
1243
|
return this.loggers.get(key);
|
|
1208
1244
|
}
|
|
@@ -2928,11 +2964,14 @@ const RPC_CONTEXT_MARKER = "__otel_rpc_ctx__";
|
|
|
2928
2964
|
function isRpcContextCarrier(obj) {
|
|
2929
2965
|
return typeof obj === "object" && obj !== null && RPC_CONTEXT_MARKER in obj && obj[RPC_CONTEXT_MARKER] === true;
|
|
2930
2966
|
}
|
|
2931
|
-
function injectRpcContext(ctx = context.active()) {
|
|
2967
|
+
function injectRpcContext(ctx = context.active(), doName) {
|
|
2932
2968
|
const carrier = {
|
|
2933
2969
|
[RPC_CONTEXT_MARKER]: true,
|
|
2934
2970
|
headers: {}
|
|
2935
2971
|
};
|
|
2972
|
+
if (doName) {
|
|
2973
|
+
carrier.doName = doName;
|
|
2974
|
+
}
|
|
2936
2975
|
propagation.inject(ctx, carrier.headers, {
|
|
2937
2976
|
set: (headers, key, value) => {
|
|
2938
2977
|
headers[key] = typeof value === "string" ? value : String(value);
|
|
@@ -2980,7 +3019,7 @@ function instrumentRpcMethod(method, methodName, nsName, stubId) {
|
|
|
2980
3019
|
const spanName = `RPC ${nsName}.${methodName}`;
|
|
2981
3020
|
return tracer.startActiveSpan(spanName, options, async (span) => {
|
|
2982
3021
|
try {
|
|
2983
|
-
const contextCarrier = injectRpcContext(context.active());
|
|
3022
|
+
const contextCarrier = injectRpcContext(context.active(), stubId.name);
|
|
2984
3023
|
const argsWithContext = [contextCarrier, ...argArray];
|
|
2985
3024
|
const result = await Reflect.apply(target, thisArg, argsWithContext);
|
|
2986
3025
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
@@ -3029,12 +3068,24 @@ function instrumentBindingGet(getFn, nsName) {
|
|
|
3029
3068
|
};
|
|
3030
3069
|
return wrap(getFn, getHandler);
|
|
3031
3070
|
}
|
|
3071
|
+
function instrumentBindingGetByName(getByNameFn, nsName) {
|
|
3072
|
+
const getByNameHandler = {
|
|
3073
|
+
apply(target, thisArg, argArray) {
|
|
3074
|
+
const stub = Reflect.apply(target, thisArg, argArray);
|
|
3075
|
+
return instrumentBindingStub(stub, nsName);
|
|
3076
|
+
}
|
|
3077
|
+
};
|
|
3078
|
+
return wrap(getByNameFn, getByNameHandler);
|
|
3079
|
+
}
|
|
3032
3080
|
function instrumentDOBinding(ns, nsName) {
|
|
3033
3081
|
const nsHandler = {
|
|
3034
3082
|
get(target, prop, receiver) {
|
|
3035
3083
|
if (prop === "get") {
|
|
3036
3084
|
const fn = Reflect.get(ns, prop, receiver);
|
|
3037
3085
|
return instrumentBindingGet(fn, nsName);
|
|
3086
|
+
} else if (prop === "getByName") {
|
|
3087
|
+
const fn = Reflect.get(ns, prop, receiver);
|
|
3088
|
+
return instrumentBindingGetByName(fn, nsName);
|
|
3038
3089
|
} else {
|
|
3039
3090
|
return passthroughGet(target, prop, receiver);
|
|
3040
3091
|
}
|
|
@@ -3150,25 +3201,39 @@ function instrumentRpcHandlerMethod(fn, methodName, initialiser, env, id) {
|
|
|
3150
3201
|
thisArg = unwrap(thisArg);
|
|
3151
3202
|
const config = initialiser(env, "do-rpc");
|
|
3152
3203
|
const [extractedContext, cleanedArgs] = extractAndRemoveRpcContext(argArray);
|
|
3204
|
+
const carrierDoName = argArray.length > 0 && extractedContext ? argArray[0].doName : void 0;
|
|
3205
|
+
const doName = carrierDoName || id.name || void 0;
|
|
3206
|
+
const carrier = argArray.length > 0 ? argArray[0] : void 0;
|
|
3207
|
+
console.log("[DO RPC Server]", {
|
|
3208
|
+
methodName,
|
|
3209
|
+
hasExtractedContext: !!extractedContext,
|
|
3210
|
+
carrierDoName,
|
|
3211
|
+
idName: id.name,
|
|
3212
|
+
finalDoName: doName,
|
|
3213
|
+
argArrayLength: argArray.length,
|
|
3214
|
+
cleanedArgsLength: cleanedArgs.length,
|
|
3215
|
+
carrierHeaders: carrier ? carrier.headers : void 0
|
|
3216
|
+
});
|
|
3153
3217
|
let context$1 = extractedContext || context.active();
|
|
3154
3218
|
context$1 = setConfig(config, context$1);
|
|
3155
3219
|
const tracer = trace.getTracer("do_rpc_handler");
|
|
3156
|
-
const doName = id.name || id.toString();
|
|
3157
3220
|
const executeRpc = async () => {
|
|
3158
3221
|
const attributes = {
|
|
3159
3222
|
[ATTR_RPC_SYSTEM]: "cloudflare_rpc",
|
|
3160
3223
|
[ATTR_RPC_METHOD]: methodName,
|
|
3161
3224
|
[ATTR_CLOUDFLARE_JSRPC_METHOD]: methodName,
|
|
3162
3225
|
[SemanticAttributes.FAAS_TRIGGER]: "rpc",
|
|
3163
|
-
"do.id": id.toString()
|
|
3164
|
-
"do.name": id.name
|
|
3226
|
+
"do.id": id.toString()
|
|
3165
3227
|
};
|
|
3228
|
+
if (doName) {
|
|
3229
|
+
attributes["do.name"] = doName;
|
|
3230
|
+
}
|
|
3166
3231
|
const options = {
|
|
3167
3232
|
kind: SpanKind.SERVER,
|
|
3168
3233
|
attributes
|
|
3169
3234
|
};
|
|
3170
|
-
const spanName =
|
|
3171
|
-
return tracer.startActiveSpan(spanName, options, async (span) => {
|
|
3235
|
+
const spanName = doName ? `${doName}.${methodName}` : `${attributes["do.id"]}.${methodName}`;
|
|
3236
|
+
return tracer.startActiveSpan(spanName, options, context.active(), async (span) => {
|
|
3172
3237
|
try {
|
|
3173
3238
|
const bound = target.bind(thisArg);
|
|
3174
3239
|
const result = await bound.apply(thisArg, cleanedArgs);
|
|
@@ -3391,7 +3456,7 @@ function init(config, serviceConfig, propagator) {
|
|
|
3391
3456
|
traceProvider.register();
|
|
3392
3457
|
}
|
|
3393
3458
|
if (config.logs && config.logs.processors.length > 0) {
|
|
3394
|
-
const logsProvider = new WorkerLoggerProvider(config.logs.processors, resource);
|
|
3459
|
+
const logsProvider = new WorkerLoggerProvider(config.logs.processors, resource, config.logs.level);
|
|
3395
3460
|
logsProvider.register();
|
|
3396
3461
|
if (config.logs.instrumentation.instrumentConsole) {
|
|
3397
3462
|
import('./console-Cy5QdByD.js').then(({ instrumentConsole }) => {
|
|
@@ -3699,7 +3764,7 @@ class ConsoleTransport {
|
|
|
3699
3764
|
export(logs, callback) {
|
|
3700
3765
|
try {
|
|
3701
3766
|
for (const log of logs) {
|
|
3702
|
-
this.printLog(log);
|
|
3767
|
+
this.printLog(this.options.transformLog ? this.options.transformLog(log) : log);
|
|
3703
3768
|
}
|
|
3704
3769
|
callback({ code: ExportResultCode.SUCCESS });
|
|
3705
3770
|
} catch (error) {
|