autotel-cloudflare 2.15.0 → 2.16.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/README.md +3 -3
- package/dist/bindings.d.ts +0 -19
- package/dist/bindings.js +1 -1
- package/dist/{chunk-4UG2QCPQ.js → chunk-NUNTBJWB.js} +80 -58
- package/dist/chunk-NUNTBJWB.js.map +1 -0
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/bindings/ai.test.ts +14 -0
- package/src/bindings/ai.ts +2 -2
- package/src/bindings/analytics-engine.test.ts +15 -0
- package/src/bindings/analytics-engine.ts +2 -2
- package/src/bindings/bindings-cache.test.ts +80 -0
- package/src/bindings/bindings-this-binding.test.ts +258 -0
- package/src/bindings/bindings.ts +80 -48
- package/src/bindings/browser-rendering.test.ts +16 -0
- package/src/bindings/browser-rendering.ts +2 -2
- package/src/bindings/hyperdrive.test.ts +22 -0
- package/src/bindings/hyperdrive.ts +2 -2
- package/src/bindings/images.test.ts +33 -0
- package/src/bindings/images.ts +4 -4
- package/src/bindings/queue-producer.test.ts +32 -0
- package/src/bindings/queue-producer.ts +4 -4
- package/src/bindings/rate-limiter.test.ts +16 -0
- package/src/bindings/rate-limiter.ts +2 -2
- package/src/bindings/vectorize.test.ts +22 -0
- package/src/bindings/vectorize.ts +2 -2
- package/src/global/fetch.test.ts +55 -0
- package/src/global/fetch.ts +4 -2
- package/src/wrappers/instrument.integration.test.ts +103 -0
- package/src/wrappers/instrument.ts +16 -3
- package/dist/chunk-4UG2QCPQ.js.map +0 -1
package/README.md
CHANGED
|
@@ -44,8 +44,8 @@ head_sampling_rate = 1.0 # Let autotel handle sampling
|
|
|
44
44
|
import { wrapModule, trace } from 'autotel-cloudflare'
|
|
45
45
|
|
|
46
46
|
// Zero-boilerplate function tracing
|
|
47
|
-
const processOrder = trace(async (orderId: string) => {
|
|
48
|
-
const order = await
|
|
47
|
+
const processOrder = trace(async (orderId: string, kv: KVNamespace) => {
|
|
48
|
+
const order = await kv.get(orderId) // Auto-instrumented!
|
|
49
49
|
return order
|
|
50
50
|
})
|
|
51
51
|
|
|
@@ -57,7 +57,7 @@ export default wrapModule(
|
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
async fetch(req, env, ctx) {
|
|
60
|
-
return Response.json(await processOrder('123'))
|
|
60
|
+
return Response.json(await processOrder('123', env.ORDERS_KV))
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
)
|
package/dist/bindings.d.ts
CHANGED
|
@@ -32,25 +32,6 @@ declare function instrumentD1<D extends D1Database>(d1: D, databaseName?: string
|
|
|
32
32
|
* Instrument service binding (Fetcher)
|
|
33
33
|
*/
|
|
34
34
|
declare function instrumentServiceBinding<F extends Fetcher>(fetcher: F, serviceName?: string): F;
|
|
35
|
-
/**
|
|
36
|
-
* Auto-instrument all Cloudflare bindings in the environment
|
|
37
|
-
*
|
|
38
|
-
* Detection order (most specific first):
|
|
39
|
-
* 1. R2 — get, put, delete, list, head
|
|
40
|
-
* 2. KV — get, put, delete, list (not head)
|
|
41
|
-
* 3. D1 — prepare, exec
|
|
42
|
-
* 4. Vectorize — query, insert, upsert, describe
|
|
43
|
-
* 5. AI — run + (gateway or models discriminator)
|
|
44
|
-
* 6. Hyperdrive — connect + connectionString + host
|
|
45
|
-
* 7. Queue Producer — send, sendBatch (not get)
|
|
46
|
-
* 8. Analytics Engine — writeDataPoint
|
|
47
|
-
* 9. Images — info, input
|
|
48
|
-
* 10. Service Binding — fetch (broadest, must be last)
|
|
49
|
-
*
|
|
50
|
-
* Not auto-detected (manual only):
|
|
51
|
-
* - Rate Limiter — limit() alone too generic
|
|
52
|
-
* - Browser Rendering — indistinguishable from Service Binding
|
|
53
|
-
*/
|
|
54
35
|
declare function instrumentBindings(env: Record<string, any>): Record<string, any>;
|
|
55
36
|
|
|
56
37
|
/**
|
package/dist/bindings.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { instrumentAI, instrumentAnalyticsEngine, instrumentBindings, instrumentBrowserRendering, instrumentD1, instrumentHyperdrive, instrumentImages, instrumentKV, instrumentQueueProducer, instrumentR2, instrumentRateLimiter, instrumentServiceBinding, instrumentVectorize } from './chunk-
|
|
1
|
+
export { instrumentAI, instrumentAnalyticsEngine, instrumentBindings, instrumentBrowserRendering, instrumentD1, instrumentHyperdrive, instrumentImages, instrumentKV, instrumentQueueProducer, instrumentR2, instrumentRateLimiter, instrumentServiceBinding, instrumentVectorize } from './chunk-NUNTBJWB.js';
|
|
2
2
|
import './chunk-O4IYKWPJ.js';
|
|
3
3
|
//# sourceMappingURL=bindings.js.map
|
|
4
4
|
//# sourceMappingURL=bindings.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { wrap, isWrapped, setAttr } from './chunk-O4IYKWPJ.js';
|
|
2
2
|
import { trace, SpanKind, SpanStatusCode } from '@opentelemetry/api';
|
|
3
|
+
import { getActiveConfig } from 'autotel-edge';
|
|
3
4
|
|
|
4
5
|
function instrumentAI(ai, bindingName) {
|
|
5
6
|
const name = bindingName || "ai";
|
|
@@ -8,7 +9,7 @@ function instrumentAI(ai, bindingName) {
|
|
|
8
9
|
const value = Reflect.get(target, prop);
|
|
9
10
|
if (prop === "run" && typeof value === "function") {
|
|
10
11
|
return new Proxy(value, {
|
|
11
|
-
apply: (fnTarget,
|
|
12
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
12
13
|
const [model] = args;
|
|
13
14
|
const tracer = trace.getTracer("autotel-edge");
|
|
14
15
|
return tracer.startActiveSpan(
|
|
@@ -23,7 +24,7 @@ function instrumentAI(ai, bindingName) {
|
|
|
23
24
|
},
|
|
24
25
|
async (span) => {
|
|
25
26
|
try {
|
|
26
|
-
const result = await Reflect.apply(fnTarget,
|
|
27
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
27
28
|
if (result?.usage?.prompt_tokens !== void 0) {
|
|
28
29
|
setAttr(span, "gen_ai.usage.input_tokens", Number(result.usage.prompt_tokens));
|
|
29
30
|
}
|
|
@@ -60,7 +61,7 @@ function instrumentVectorize(vectorize, indexName) {
|
|
|
60
61
|
const value = Reflect.get(target, prop);
|
|
61
62
|
if (typeof prop === "string" && TRACED_METHODS.includes(prop) && typeof value === "function") {
|
|
62
63
|
return new Proxy(value, {
|
|
63
|
-
apply: (fnTarget,
|
|
64
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
64
65
|
const operation = prop;
|
|
65
66
|
const tracer = trace.getTracer("autotel-edge");
|
|
66
67
|
const attributes = {
|
|
@@ -85,7 +86,7 @@ function instrumentVectorize(vectorize, indexName) {
|
|
|
85
86
|
},
|
|
86
87
|
async (span) => {
|
|
87
88
|
try {
|
|
88
|
-
const result = await Reflect.apply(fnTarget,
|
|
89
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
89
90
|
if (operation === "query" && result?.matches) {
|
|
90
91
|
setAttr(span, "db.vectorize.matches_count", result.matches.length);
|
|
91
92
|
}
|
|
@@ -118,7 +119,7 @@ function instrumentHyperdrive(hyperdrive, bindingName) {
|
|
|
118
119
|
const value = Reflect.get(target, prop);
|
|
119
120
|
if (prop === "connect" && typeof value === "function") {
|
|
120
121
|
return new Proxy(value, {
|
|
121
|
-
apply: (fnTarget,
|
|
122
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
122
123
|
const tracer = trace.getTracer("autotel-edge");
|
|
123
124
|
const attributes = {
|
|
124
125
|
"db.system": "cloudflare-hyperdrive",
|
|
@@ -144,7 +145,7 @@ function instrumentHyperdrive(hyperdrive, bindingName) {
|
|
|
144
145
|
},
|
|
145
146
|
async (span) => {
|
|
146
147
|
try {
|
|
147
|
-
const result = await Reflect.apply(fnTarget,
|
|
148
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
148
149
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
149
150
|
return result;
|
|
150
151
|
} catch (error) {
|
|
@@ -174,7 +175,7 @@ function instrumentQueueProducer(queue, queueName) {
|
|
|
174
175
|
const value = Reflect.get(target, prop);
|
|
175
176
|
if (prop === "send" && typeof value === "function") {
|
|
176
177
|
return new Proxy(value, {
|
|
177
|
-
apply: (fnTarget,
|
|
178
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
178
179
|
const tracer = trace.getTracer("autotel-edge");
|
|
179
180
|
return tracer.startActiveSpan(
|
|
180
181
|
`Queue ${name}: send`,
|
|
@@ -189,7 +190,7 @@ function instrumentQueueProducer(queue, queueName) {
|
|
|
189
190
|
},
|
|
190
191
|
async (span) => {
|
|
191
192
|
try {
|
|
192
|
-
const result = await Reflect.apply(fnTarget,
|
|
193
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
193
194
|
setAttr(span, "messaging.message.id", result?.messageId);
|
|
194
195
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
195
196
|
return result;
|
|
@@ -210,7 +211,7 @@ function instrumentQueueProducer(queue, queueName) {
|
|
|
210
211
|
}
|
|
211
212
|
if (prop === "sendBatch" && typeof value === "function") {
|
|
212
213
|
return new Proxy(value, {
|
|
213
|
-
apply: (fnTarget,
|
|
214
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
214
215
|
const [messages] = args;
|
|
215
216
|
const tracer = trace.getTracer("autotel-edge");
|
|
216
217
|
return tracer.startActiveSpan(
|
|
@@ -227,7 +228,7 @@ function instrumentQueueProducer(queue, queueName) {
|
|
|
227
228
|
},
|
|
228
229
|
async (span) => {
|
|
229
230
|
try {
|
|
230
|
-
const result = await Reflect.apply(fnTarget,
|
|
231
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
231
232
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
232
233
|
return result;
|
|
233
234
|
} catch (error) {
|
|
@@ -257,7 +258,7 @@ function instrumentAnalyticsEngine(ae, datasetName) {
|
|
|
257
258
|
const value = Reflect.get(target, prop);
|
|
258
259
|
if (prop === "writeDataPoint" && typeof value === "function") {
|
|
259
260
|
return new Proxy(value, {
|
|
260
|
-
apply: (fnTarget,
|
|
261
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
261
262
|
const [dataPoint] = args;
|
|
262
263
|
const tracer = trace.getTracer("autotel-edge");
|
|
263
264
|
const attributes = {
|
|
@@ -283,7 +284,7 @@ function instrumentAnalyticsEngine(ae, datasetName) {
|
|
|
283
284
|
},
|
|
284
285
|
(span) => {
|
|
285
286
|
try {
|
|
286
|
-
Reflect.apply(fnTarget,
|
|
287
|
+
Reflect.apply(fnTarget, target, args);
|
|
287
288
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
288
289
|
} catch (error) {
|
|
289
290
|
span.recordException(error);
|
|
@@ -382,7 +383,7 @@ function instrumentImages(images, bindingName) {
|
|
|
382
383
|
const value = Reflect.get(target, prop);
|
|
383
384
|
if (prop === "info" && typeof value === "function") {
|
|
384
385
|
return new Proxy(value, {
|
|
385
|
-
apply: (fnTarget,
|
|
386
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
386
387
|
const tracer = trace.getTracer("autotel-edge");
|
|
387
388
|
return tracer.startActiveSpan(
|
|
388
389
|
`Images ${name}: info`,
|
|
@@ -395,7 +396,7 @@ function instrumentImages(images, bindingName) {
|
|
|
395
396
|
},
|
|
396
397
|
async (span) => {
|
|
397
398
|
try {
|
|
398
|
-
const result = await Reflect.apply(fnTarget,
|
|
399
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
399
400
|
setAttr(span, "images.width", result?.width);
|
|
400
401
|
setAttr(span, "images.height", result?.height);
|
|
401
402
|
setAttr(span, "images.format", result?.format);
|
|
@@ -418,8 +419,8 @@ function instrumentImages(images, bindingName) {
|
|
|
418
419
|
}
|
|
419
420
|
if (prop === "input" && typeof value === "function") {
|
|
420
421
|
return new Proxy(value, {
|
|
421
|
-
apply: (fnTarget,
|
|
422
|
-
const transformer = Reflect.apply(fnTarget,
|
|
422
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
423
|
+
const transformer = Reflect.apply(fnTarget, target, args);
|
|
423
424
|
const meta = { operationCount: 0 };
|
|
424
425
|
return proxyTransformer(transformer, meta, name);
|
|
425
426
|
}
|
|
@@ -432,6 +433,11 @@ function instrumentImages(images, bindingName) {
|
|
|
432
433
|
}
|
|
433
434
|
|
|
434
435
|
// src/bindings/bindings.ts
|
|
436
|
+
function sanitizeStatement(query, mode) {
|
|
437
|
+
if (mode === "off") return void 0;
|
|
438
|
+
if (mode === "obfuscated") return query.replaceAll(/'[^']*'/g, "'?'").replaceAll(/\b\d+\b/g, "?");
|
|
439
|
+
return query;
|
|
440
|
+
}
|
|
435
441
|
function instrumentKV(kv, namespaceName) {
|
|
436
442
|
const name = namespaceName || "kv";
|
|
437
443
|
const kvHandler = {
|
|
@@ -439,7 +445,7 @@ function instrumentKV(kv, namespaceName) {
|
|
|
439
445
|
const value = Reflect.get(target, prop);
|
|
440
446
|
if (prop === "get" && typeof value === "function") {
|
|
441
447
|
return new Proxy(value, {
|
|
442
|
-
apply: (fnTarget,
|
|
448
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
443
449
|
const [key, options] = args;
|
|
444
450
|
const tracer = trace.getTracer("autotel-edge");
|
|
445
451
|
return tracer.startActiveSpan(
|
|
@@ -456,7 +462,7 @@ function instrumentKV(kv, namespaceName) {
|
|
|
456
462
|
},
|
|
457
463
|
async (span) => {
|
|
458
464
|
try {
|
|
459
|
-
const result = await Reflect.apply(fnTarget,
|
|
465
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
460
466
|
span.setAttribute("db.result.type", result === null ? "null" : typeof result);
|
|
461
467
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
462
468
|
return result;
|
|
@@ -477,7 +483,7 @@ function instrumentKV(kv, namespaceName) {
|
|
|
477
483
|
}
|
|
478
484
|
if (prop === "put" && typeof value === "function") {
|
|
479
485
|
return new Proxy(value, {
|
|
480
|
-
apply: (fnTarget,
|
|
486
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
481
487
|
const [key] = args;
|
|
482
488
|
const tracer = trace.getTracer("autotel-edge");
|
|
483
489
|
return tracer.startActiveSpan(
|
|
@@ -493,7 +499,7 @@ function instrumentKV(kv, namespaceName) {
|
|
|
493
499
|
},
|
|
494
500
|
async (span) => {
|
|
495
501
|
try {
|
|
496
|
-
const result = await Reflect.apply(fnTarget,
|
|
502
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
497
503
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
498
504
|
return result;
|
|
499
505
|
} catch (error) {
|
|
@@ -513,7 +519,7 @@ function instrumentKV(kv, namespaceName) {
|
|
|
513
519
|
}
|
|
514
520
|
if (prop === "delete" && typeof value === "function") {
|
|
515
521
|
return new Proxy(value, {
|
|
516
|
-
apply: (fnTarget,
|
|
522
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
517
523
|
const [key] = args;
|
|
518
524
|
const tracer = trace.getTracer("autotel-edge");
|
|
519
525
|
return tracer.startActiveSpan(
|
|
@@ -529,7 +535,7 @@ function instrumentKV(kv, namespaceName) {
|
|
|
529
535
|
},
|
|
530
536
|
async (span) => {
|
|
531
537
|
try {
|
|
532
|
-
const result = await Reflect.apply(fnTarget,
|
|
538
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
533
539
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
534
540
|
return result;
|
|
535
541
|
} catch (error) {
|
|
@@ -549,7 +555,7 @@ function instrumentKV(kv, namespaceName) {
|
|
|
549
555
|
}
|
|
550
556
|
if (prop === "list" && typeof value === "function") {
|
|
551
557
|
return new Proxy(value, {
|
|
552
|
-
apply: (fnTarget,
|
|
558
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
553
559
|
const [options] = args;
|
|
554
560
|
const tracer = trace.getTracer("autotel-edge");
|
|
555
561
|
return tracer.startActiveSpan(
|
|
@@ -566,7 +572,7 @@ function instrumentKV(kv, namespaceName) {
|
|
|
566
572
|
},
|
|
567
573
|
async (span) => {
|
|
568
574
|
try {
|
|
569
|
-
const result = await Reflect.apply(fnTarget,
|
|
575
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
570
576
|
span.setAttribute("db.result.keys_count", result.keys.length);
|
|
571
577
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
572
578
|
return result;
|
|
@@ -597,7 +603,7 @@ function instrumentR2(r2, bucketName) {
|
|
|
597
603
|
const value = Reflect.get(target, prop);
|
|
598
604
|
if (prop === "get" && typeof value === "function") {
|
|
599
605
|
return new Proxy(value, {
|
|
600
|
-
apply: (fnTarget,
|
|
606
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
601
607
|
const [key] = args;
|
|
602
608
|
const tracer = trace.getTracer("autotel-edge");
|
|
603
609
|
return tracer.startActiveSpan(
|
|
@@ -613,7 +619,7 @@ function instrumentR2(r2, bucketName) {
|
|
|
613
619
|
},
|
|
614
620
|
async (span) => {
|
|
615
621
|
try {
|
|
616
|
-
const result = await Reflect.apply(fnTarget,
|
|
622
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
617
623
|
if (result) {
|
|
618
624
|
span.setAttribute("db.result.size", result.size);
|
|
619
625
|
span.setAttribute("db.result.etag", result.etag);
|
|
@@ -640,7 +646,7 @@ function instrumentR2(r2, bucketName) {
|
|
|
640
646
|
}
|
|
641
647
|
if (prop === "put" && typeof value === "function") {
|
|
642
648
|
return new Proxy(value, {
|
|
643
|
-
apply: (fnTarget,
|
|
649
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
644
650
|
const [key] = args;
|
|
645
651
|
const tracer = trace.getTracer("autotel-edge");
|
|
646
652
|
return tracer.startActiveSpan(
|
|
@@ -656,7 +662,7 @@ function instrumentR2(r2, bucketName) {
|
|
|
656
662
|
},
|
|
657
663
|
async (span) => {
|
|
658
664
|
try {
|
|
659
|
-
const result = await Reflect.apply(fnTarget,
|
|
665
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
660
666
|
span.setAttribute("db.result.etag", result.etag);
|
|
661
667
|
span.setAttribute("db.result.uploaded", result.uploaded);
|
|
662
668
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
@@ -678,7 +684,7 @@ function instrumentR2(r2, bucketName) {
|
|
|
678
684
|
}
|
|
679
685
|
if (prop === "delete" && typeof value === "function") {
|
|
680
686
|
return new Proxy(value, {
|
|
681
|
-
apply: (fnTarget,
|
|
687
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
682
688
|
const keys = args;
|
|
683
689
|
const tracer = trace.getTracer("autotel-edge");
|
|
684
690
|
return tracer.startActiveSpan(
|
|
@@ -694,7 +700,7 @@ function instrumentR2(r2, bucketName) {
|
|
|
694
700
|
},
|
|
695
701
|
async (span) => {
|
|
696
702
|
try {
|
|
697
|
-
const result = await Reflect.apply(fnTarget,
|
|
703
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
698
704
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
699
705
|
return result;
|
|
700
706
|
} catch (error) {
|
|
@@ -714,7 +720,7 @@ function instrumentR2(r2, bucketName) {
|
|
|
714
720
|
}
|
|
715
721
|
if (prop === "list" && typeof value === "function") {
|
|
716
722
|
return new Proxy(value, {
|
|
717
|
-
apply: (fnTarget,
|
|
723
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
718
724
|
const [options] = args;
|
|
719
725
|
const tracer = trace.getTracer("autotel-edge");
|
|
720
726
|
return tracer.startActiveSpan(
|
|
@@ -731,7 +737,7 @@ function instrumentR2(r2, bucketName) {
|
|
|
731
737
|
},
|
|
732
738
|
async (span) => {
|
|
733
739
|
try {
|
|
734
|
-
const result = await Reflect.apply(fnTarget,
|
|
740
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
735
741
|
span.setAttribute("db.result.objects_count", result.objects.length);
|
|
736
742
|
span.setAttribute("db.result.truncated", result.truncated);
|
|
737
743
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
@@ -763,30 +769,36 @@ function instrumentD1(d1, databaseName) {
|
|
|
763
769
|
const value = Reflect.get(target, prop);
|
|
764
770
|
if (prop === "prepare" && typeof value === "function") {
|
|
765
771
|
return new Proxy(value, {
|
|
766
|
-
apply: (fnTarget,
|
|
772
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
767
773
|
const [query] = args;
|
|
768
774
|
const tracer = trace.getTracer("autotel-edge");
|
|
769
|
-
const prepared = Reflect.apply(fnTarget,
|
|
775
|
+
const prepared = Reflect.apply(fnTarget, target, args);
|
|
770
776
|
const preparedHandler = {
|
|
771
777
|
get(target2, prop2) {
|
|
772
778
|
const value2 = Reflect.get(target2, prop2);
|
|
773
779
|
if (prop2 === "first" || prop2 === "run" || prop2 === "all" || prop2 === "raw") {
|
|
774
780
|
return new Proxy(value2, {
|
|
775
|
-
apply: (fnTarget2,
|
|
781
|
+
apply: (fnTarget2, _thisArg2, args2) => {
|
|
782
|
+
const activeConfig = getActiveConfig();
|
|
783
|
+
const captureMode = activeConfig?.dataSafety?.captureDbStatement ?? "full";
|
|
784
|
+
const statement = sanitizeStatement(query, captureMode);
|
|
785
|
+
const attributes = {
|
|
786
|
+
"db.system": "cloudflare-d1",
|
|
787
|
+
"db.operation": prop2,
|
|
788
|
+
"db.name": name
|
|
789
|
+
};
|
|
790
|
+
if (statement !== void 0) {
|
|
791
|
+
attributes["db.statement"] = statement;
|
|
792
|
+
}
|
|
776
793
|
return tracer.startActiveSpan(
|
|
777
794
|
`D1 ${name}: ${prop2}`,
|
|
778
795
|
{
|
|
779
796
|
kind: SpanKind.CLIENT,
|
|
780
|
-
attributes
|
|
781
|
-
"db.system": "cloudflare-d1",
|
|
782
|
-
"db.operation": prop2,
|
|
783
|
-
"db.name": name,
|
|
784
|
-
"db.statement": query
|
|
785
|
-
}
|
|
797
|
+
attributes
|
|
786
798
|
},
|
|
787
799
|
async (span) => {
|
|
788
800
|
try {
|
|
789
|
-
const result = await Reflect.apply(fnTarget2,
|
|
801
|
+
const result = await Reflect.apply(fnTarget2, target2, args2);
|
|
790
802
|
if (prop2 === "all" && Array.isArray(result)) {
|
|
791
803
|
span.setAttribute("db.result.rows_count", result.length);
|
|
792
804
|
} else if (prop2 === "first" && result) {
|
|
@@ -818,23 +830,29 @@ function instrumentD1(d1, databaseName) {
|
|
|
818
830
|
}
|
|
819
831
|
if (prop === "exec" && typeof value === "function") {
|
|
820
832
|
return new Proxy(value, {
|
|
821
|
-
apply: (fnTarget,
|
|
833
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
822
834
|
const [query] = args;
|
|
823
835
|
const tracer = trace.getTracer("autotel-edge");
|
|
836
|
+
const activeConfig = getActiveConfig();
|
|
837
|
+
const captureMode = activeConfig?.dataSafety?.captureDbStatement ?? "full";
|
|
838
|
+
const statement = sanitizeStatement(query, captureMode);
|
|
839
|
+
const attributes = {
|
|
840
|
+
"db.system": "cloudflare-d1",
|
|
841
|
+
"db.operation": "exec",
|
|
842
|
+
"db.name": name
|
|
843
|
+
};
|
|
844
|
+
if (statement !== void 0) {
|
|
845
|
+
attributes["db.statement"] = statement;
|
|
846
|
+
}
|
|
824
847
|
return tracer.startActiveSpan(
|
|
825
848
|
`D1 ${name}: exec`,
|
|
826
849
|
{
|
|
827
850
|
kind: SpanKind.CLIENT,
|
|
828
|
-
attributes
|
|
829
|
-
"db.system": "cloudflare-d1",
|
|
830
|
-
"db.operation": "exec",
|
|
831
|
-
"db.name": name,
|
|
832
|
-
"db.statement": query
|
|
833
|
-
}
|
|
851
|
+
attributes
|
|
834
852
|
},
|
|
835
853
|
async (span) => {
|
|
836
854
|
try {
|
|
837
|
-
const result = await Reflect.apply(fnTarget,
|
|
855
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
838
856
|
span.setAttribute("db.result.count", result.count);
|
|
839
857
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
840
858
|
return result;
|
|
@@ -865,7 +883,7 @@ function instrumentServiceBinding(fetcher, serviceName) {
|
|
|
865
883
|
const value = Reflect.get(target, prop);
|
|
866
884
|
if (prop === "fetch" && typeof value === "function") {
|
|
867
885
|
return new Proxy(value, {
|
|
868
|
-
apply: (fnTarget,
|
|
886
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
869
887
|
const [input, init] = args;
|
|
870
888
|
const request = new Request(input, init);
|
|
871
889
|
const tracer = trace.getTracer("autotel-edge");
|
|
@@ -882,7 +900,7 @@ function instrumentServiceBinding(fetcher, serviceName) {
|
|
|
882
900
|
},
|
|
883
901
|
async (span) => {
|
|
884
902
|
try {
|
|
885
|
-
const response = await Reflect.apply(fnTarget,
|
|
903
|
+
const response = await Reflect.apply(fnTarget, target, args);
|
|
886
904
|
span.setAttribute("http.response.status_code", response.status);
|
|
887
905
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
888
906
|
return response;
|
|
@@ -908,7 +926,10 @@ function instrumentServiceBinding(fetcher, serviceName) {
|
|
|
908
926
|
}
|
|
909
927
|
var hasMethod = (obj, m) => typeof obj?.[m] === "function";
|
|
910
928
|
var hasExactMethods = (obj, methods) => methods.every((m) => hasMethod(obj, m));
|
|
929
|
+
var envCache = /* @__PURE__ */ new WeakMap();
|
|
911
930
|
function instrumentBindings(env) {
|
|
931
|
+
const cached = envCache.get(env);
|
|
932
|
+
if (cached) return cached;
|
|
912
933
|
const instrumented = {};
|
|
913
934
|
for (const [key, value] of Object.entries(env)) {
|
|
914
935
|
if (!value || typeof value !== "object") {
|
|
@@ -961,6 +982,7 @@ function instrumentBindings(env) {
|
|
|
961
982
|
}
|
|
962
983
|
instrumented[key] = value;
|
|
963
984
|
}
|
|
985
|
+
envCache.set(env, instrumented);
|
|
964
986
|
return instrumented;
|
|
965
987
|
}
|
|
966
988
|
function instrumentRateLimiter(limiter, bindingName) {
|
|
@@ -970,7 +992,7 @@ function instrumentRateLimiter(limiter, bindingName) {
|
|
|
970
992
|
const value = Reflect.get(target, prop);
|
|
971
993
|
if (prop === "limit" && typeof value === "function") {
|
|
972
994
|
return new Proxy(value, {
|
|
973
|
-
apply: (fnTarget,
|
|
995
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
974
996
|
const [options] = args;
|
|
975
997
|
const tracer = trace.getTracer("autotel-edge");
|
|
976
998
|
return tracer.startActiveSpan(
|
|
@@ -984,7 +1006,7 @@ function instrumentRateLimiter(limiter, bindingName) {
|
|
|
984
1006
|
},
|
|
985
1007
|
async (span) => {
|
|
986
1008
|
try {
|
|
987
|
-
const result = await Reflect.apply(fnTarget,
|
|
1009
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
988
1010
|
setAttr(span, "rate_limiter.success", result?.success);
|
|
989
1011
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
990
1012
|
return result;
|
|
@@ -1015,7 +1037,7 @@ function instrumentBrowserRendering(browser, bindingName) {
|
|
|
1015
1037
|
const value = Reflect.get(target, prop);
|
|
1016
1038
|
if (prop === "fetch" && typeof value === "function") {
|
|
1017
1039
|
return new Proxy(value, {
|
|
1018
|
-
apply: (fnTarget,
|
|
1040
|
+
apply: (fnTarget, _thisArg, args) => {
|
|
1019
1041
|
const [input] = args;
|
|
1020
1042
|
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
1021
1043
|
const tracer = trace.getTracer("autotel-edge");
|
|
@@ -1030,7 +1052,7 @@ function instrumentBrowserRendering(browser, bindingName) {
|
|
|
1030
1052
|
},
|
|
1031
1053
|
async (span) => {
|
|
1032
1054
|
try {
|
|
1033
|
-
const result = await Reflect.apply(fnTarget,
|
|
1055
|
+
const result = await Reflect.apply(fnTarget, target, args);
|
|
1034
1056
|
setAttr(span, "http.response.status_code", result?.status);
|
|
1035
1057
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
1036
1058
|
return result;
|
|
@@ -1056,5 +1078,5 @@ function instrumentBrowserRendering(browser, bindingName) {
|
|
|
1056
1078
|
}
|
|
1057
1079
|
|
|
1058
1080
|
export { instrumentAI, instrumentAnalyticsEngine, instrumentBindings, instrumentBrowserRendering, instrumentD1, instrumentHyperdrive, instrumentImages, instrumentKV, instrumentQueueProducer, instrumentR2, instrumentRateLimiter, instrumentServiceBinding, instrumentVectorize };
|
|
1059
|
-
//# sourceMappingURL=chunk-
|
|
1060
|
-
//# sourceMappingURL=chunk-
|
|
1081
|
+
//# sourceMappingURL=chunk-NUNTBJWB.js.map
|
|
1082
|
+
//# sourceMappingURL=chunk-NUNTBJWB.js.map
|