@inference-net/otel-cf-workers 2.0.1 → 2.0.2
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 +2 -1
- package/dist/index.js +84 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ export declare interface ConsoleTransportConfig {
|
|
|
84
84
|
pretty?: boolean;
|
|
85
85
|
colors?: boolean;
|
|
86
86
|
includeTimestamp?: boolean;
|
|
87
|
+
transformLog?: (logRecord: ReadableLogRecord) => ReadableLogRecord;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
/**
|
|
@@ -511,7 +512,7 @@ declare class TraceState {
|
|
|
511
512
|
private exportSpans;
|
|
512
513
|
}
|
|
513
514
|
|
|
514
|
-
export declare type Trigger = Request | MessageBatch | ScheduledController | DOConstructorTrigger | 'do-alarm' | ForwardableEmailMessage;
|
|
515
|
+
export declare type Trigger = Request | MessageBatch | ScheduledController | DOConstructorTrigger | 'do-alarm' | 'do-rpc' | ForwardableEmailMessage;
|
|
515
516
|
|
|
516
517
|
export declare function withNextSpan(attrs: Attributes): void;
|
|
517
518
|
|
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.2";
|
|
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";
|
|
@@ -224,6 +224,10 @@ const ATTR_CLOUDFLARE_IMAGES_REQUIRE_SIGNED_URLS = "cloudflare.images.require_si
|
|
|
224
224
|
const ATTR_CLOUDFLARE_RATE_LIMIT_KEY = "cloudflare.rate_limit.key";
|
|
225
225
|
const ATTR_CLOUDFLARE_RATE_LIMIT_ALLOWED = "cloudflare.rate_limit.allowed";
|
|
226
226
|
const ATTR_CLOUDFLARE_RATE_LIMIT_SUCCESS = "cloudflare.rate_limit.success";
|
|
227
|
+
const ATTR_CLOUDFLARE_JSRPC_METHOD = "cloudflare.jsrpc.method";
|
|
228
|
+
const ATTR_RPC_SYSTEM = "rpc.system";
|
|
229
|
+
const ATTR_RPC_SERVICE = "rpc.service";
|
|
230
|
+
const ATTR_RPC_METHOD = "rpc.method";
|
|
227
231
|
const DEFAULT_OTLP_HEADERS = {
|
|
228
232
|
accept: "application/json",
|
|
229
233
|
"content-type": "application/json",
|
|
@@ -2920,6 +2924,41 @@ function instrumentSQLStorage(sql) {
|
|
|
2920
2924
|
return wrap(sql, sqlHandler);
|
|
2921
2925
|
}
|
|
2922
2926
|
|
|
2927
|
+
function instrumentRpcMethod(method, methodName, nsName, stubId) {
|
|
2928
|
+
const tracer = trace.getTracer("do_rpc_client");
|
|
2929
|
+
const rpcHandler = {
|
|
2930
|
+
apply: async (target, thisArg, argArray) => {
|
|
2931
|
+
const attributes = {
|
|
2932
|
+
[ATTR_RPC_SYSTEM]: "cloudflare_rpc",
|
|
2933
|
+
[ATTR_RPC_SERVICE]: nsName,
|
|
2934
|
+
[ATTR_RPC_METHOD]: methodName,
|
|
2935
|
+
[ATTR_CLOUDFLARE_JSRPC_METHOD]: methodName,
|
|
2936
|
+
"do.namespace": nsName,
|
|
2937
|
+
"do.id": stubId.toString(),
|
|
2938
|
+
"do.id.name": stubId.name
|
|
2939
|
+
};
|
|
2940
|
+
const options = {
|
|
2941
|
+
kind: SpanKind.CLIENT,
|
|
2942
|
+
attributes
|
|
2943
|
+
};
|
|
2944
|
+
const spanName = `RPC ${nsName}.${methodName}`;
|
|
2945
|
+
return tracer.startActiveSpan(spanName, options, async (span) => {
|
|
2946
|
+
try {
|
|
2947
|
+
const result = await Reflect.apply(target, thisArg, argArray);
|
|
2948
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
2949
|
+
return result;
|
|
2950
|
+
} catch (error) {
|
|
2951
|
+
span.recordException(error);
|
|
2952
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
2953
|
+
throw error;
|
|
2954
|
+
} finally {
|
|
2955
|
+
span.end();
|
|
2956
|
+
}
|
|
2957
|
+
});
|
|
2958
|
+
}
|
|
2959
|
+
};
|
|
2960
|
+
return wrap(method, rpcHandler);
|
|
2961
|
+
}
|
|
2923
2962
|
function instrumentBindingStub(stub, nsName) {
|
|
2924
2963
|
const stubHandler = {
|
|
2925
2964
|
get(target, prop, receiver) {
|
|
@@ -2933,7 +2972,11 @@ function instrumentBindingStub(stub, nsName) {
|
|
|
2933
2972
|
};
|
|
2934
2973
|
return instrumentClientFetch(fetcher, () => ({ includeTraceContext: true }), attrs);
|
|
2935
2974
|
} else {
|
|
2936
|
-
|
|
2975
|
+
const value = passthroughGet(target, prop, receiver);
|
|
2976
|
+
if (typeof value === "function" && typeof prop === "string") {
|
|
2977
|
+
return instrumentRpcMethod(value, prop, nsName, target.id);
|
|
2978
|
+
}
|
|
2979
|
+
return value;
|
|
2937
2980
|
}
|
|
2938
2981
|
}
|
|
2939
2982
|
};
|
|
@@ -3062,19 +3105,45 @@ function instrumentAlarmFn(alarmFn, initialiser, env, id) {
|
|
|
3062
3105
|
};
|
|
3063
3106
|
return wrap(alarmFn, alarmHandler);
|
|
3064
3107
|
}
|
|
3065
|
-
function
|
|
3066
|
-
if (!fn) return
|
|
3108
|
+
function instrumentRpcHandlerMethod(fn, methodName, initialiser, env, id) {
|
|
3109
|
+
if (!fn) return fn;
|
|
3067
3110
|
const fnHandler = {
|
|
3068
3111
|
async apply(target, thisArg, argArray) {
|
|
3069
3112
|
thisArg = unwrap(thisArg);
|
|
3070
|
-
const config = initialiser(env, "do-
|
|
3113
|
+
const config = initialiser(env, "do-rpc");
|
|
3071
3114
|
const context$1 = setConfig(config);
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3115
|
+
const tracer = trace.getTracer("do_rpc_handler");
|
|
3116
|
+
const doName = id.name || id.toString();
|
|
3117
|
+
const executeRpc = async () => {
|
|
3118
|
+
const attributes = {
|
|
3119
|
+
[ATTR_RPC_SYSTEM]: "cloudflare_rpc",
|
|
3120
|
+
[ATTR_RPC_METHOD]: methodName,
|
|
3121
|
+
[ATTR_CLOUDFLARE_JSRPC_METHOD]: methodName,
|
|
3122
|
+
[SemanticAttributes.FAAS_TRIGGER]: "rpc",
|
|
3123
|
+
"do.id": id.toString(),
|
|
3124
|
+
"do.name": id.name
|
|
3125
|
+
};
|
|
3126
|
+
const options = {
|
|
3127
|
+
kind: SpanKind.SERVER,
|
|
3128
|
+
attributes
|
|
3129
|
+
};
|
|
3130
|
+
const spanName = `Durable Object RPC ${doName}.${methodName}`;
|
|
3131
|
+
return tracer.startActiveSpan(spanName, options, async (span) => {
|
|
3132
|
+
try {
|
|
3133
|
+
const bound = target.bind(thisArg);
|
|
3134
|
+
const result = await bound.apply(thisArg, argArray);
|
|
3135
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
3136
|
+
return result;
|
|
3137
|
+
} catch (error) {
|
|
3138
|
+
span.recordException(error);
|
|
3139
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
3140
|
+
throw error;
|
|
3141
|
+
} finally {
|
|
3142
|
+
span.end();
|
|
3143
|
+
}
|
|
3144
|
+
});
|
|
3145
|
+
};
|
|
3146
|
+
return await context.with(context$1, executeRpc);
|
|
3078
3147
|
}
|
|
3079
3148
|
};
|
|
3080
3149
|
return wrap(fn, fnHandler);
|
|
@@ -3094,9 +3163,9 @@ function instrumentDurableObject(doObj, initialiser, env, state, classStyle) {
|
|
|
3094
3163
|
return instrumentAlarmFn(alarmFn, initialiser, env, state.id);
|
|
3095
3164
|
} else {
|
|
3096
3165
|
const result = Reflect.get(target, prop);
|
|
3097
|
-
if (typeof result === "function") {
|
|
3166
|
+
if (typeof result === "function" && typeof prop === "string") {
|
|
3098
3167
|
result.bind(doObj);
|
|
3099
|
-
return
|
|
3168
|
+
return instrumentRpcHandlerMethod(result, prop, initialiser, env, state.id);
|
|
3100
3169
|
}
|
|
3101
3170
|
return result;
|
|
3102
3171
|
}
|
|
@@ -3583,7 +3652,8 @@ class ConsoleTransport {
|
|
|
3583
3652
|
this.options = {
|
|
3584
3653
|
pretty: options.pretty ?? true,
|
|
3585
3654
|
colors: options.colors ?? false,
|
|
3586
|
-
includeTimestamp: options.includeTimestamp ?? true
|
|
3655
|
+
includeTimestamp: options.includeTimestamp ?? true,
|
|
3656
|
+
transformLog: options.transformLog ?? ((l) => l)
|
|
3587
3657
|
};
|
|
3588
3658
|
}
|
|
3589
3659
|
export(logs, callback) {
|