autotel-cloudflare 3.1.0 → 4.0.1

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.
Files changed (76) hide show
  1. package/dist/agents.d.ts.map +1 -1
  2. package/dist/agents.js +7 -0
  3. package/dist/agents.js.map +1 -1
  4. package/package.json +8 -4
  5. package/src/actors/alarms.ts +0 -225
  6. package/src/actors/index.ts +0 -36
  7. package/src/actors/instrument-actor.test.ts +0 -179
  8. package/src/actors/instrument-actor.ts +0 -574
  9. package/src/actors/sockets.ts +0 -217
  10. package/src/actors/storage.ts +0 -263
  11. package/src/actors/traced-handler.ts +0 -300
  12. package/src/actors/types.ts +0 -98
  13. package/src/actors.ts +0 -50
  14. package/src/agents/agent.ts +0 -327
  15. package/src/agents/base.ts +0 -26
  16. package/src/agents/index.ts +0 -46
  17. package/src/agents/mcp.ts +0 -38
  18. package/src/agents/observability.ts +0 -145
  19. package/src/agents/otel-observability.test.ts +0 -269
  20. package/src/agents/otel-observability.ts +0 -557
  21. package/src/agents/types.ts +0 -61
  22. package/src/agents.ts +0 -87
  23. package/src/bindings/ai.test.ts +0 -170
  24. package/src/bindings/ai.ts +0 -73
  25. package/src/bindings/analytics-engine.test.ts +0 -175
  26. package/src/bindings/analytics-engine.ts +0 -78
  27. package/src/bindings/bindings-cache.test.ts +0 -80
  28. package/src/bindings/bindings-detection.test.ts +0 -235
  29. package/src/bindings/bindings-this-binding.test.ts +0 -294
  30. package/src/bindings/bindings.ts +0 -720
  31. package/src/bindings/browser-rendering.test.ts +0 -160
  32. package/src/bindings/browser-rendering.ts +0 -70
  33. package/src/bindings/common.ts +0 -84
  34. package/src/bindings/hyperdrive.test.ts +0 -176
  35. package/src/bindings/hyperdrive.ts +0 -74
  36. package/src/bindings/images.test.ts +0 -262
  37. package/src/bindings/images.ts +0 -182
  38. package/src/bindings/index.ts +0 -20
  39. package/src/bindings/queue-producer.test.ts +0 -224
  40. package/src/bindings/queue-producer.ts +0 -105
  41. package/src/bindings/rate-limiter.test.ts +0 -140
  42. package/src/bindings/rate-limiter.ts +0 -69
  43. package/src/bindings/vectorize.test.ts +0 -362
  44. package/src/bindings/vectorize.ts +0 -86
  45. package/src/bindings.ts +0 -6
  46. package/src/events.ts +0 -6
  47. package/src/execution-logger.test.ts +0 -127
  48. package/src/execution-logger.ts +0 -112
  49. package/src/global/cache.test.ts +0 -292
  50. package/src/global/cache.ts +0 -164
  51. package/src/global/fetch.test.ts +0 -399
  52. package/src/global/fetch.ts +0 -136
  53. package/src/global/index.ts +0 -7
  54. package/src/handlers/durable-objects.test.ts +0 -524
  55. package/src/handlers/durable-objects.ts +0 -250
  56. package/src/handlers/index.ts +0 -6
  57. package/src/handlers/workflows.test.ts +0 -411
  58. package/src/handlers/workflows.ts +0 -345
  59. package/src/handlers.ts +0 -6
  60. package/src/index.ts +0 -91
  61. package/src/logger.ts +0 -15
  62. package/src/native/native-tracing.test.ts +0 -54
  63. package/src/native/native-tracing.ts +0 -83
  64. package/src/native.ts +0 -12
  65. package/src/parse-error.ts +0 -1
  66. package/src/sampling.ts +0 -6
  67. package/src/testing.ts +0 -6
  68. package/src/wrappers/cf-attributes.test.ts +0 -334
  69. package/src/wrappers/define-worker-fetch.test.ts +0 -102
  70. package/src/wrappers/define-worker-fetch.ts +0 -71
  71. package/src/wrappers/index.ts +0 -13
  72. package/src/wrappers/instrument.integration.test.ts +0 -578
  73. package/src/wrappers/instrument.ts +0 -806
  74. package/src/wrappers/native-instrument.test.ts +0 -153
  75. package/src/wrappers/wrap-do.ts +0 -34
  76. package/src/wrappers/wrap-module.ts +0 -37
@@ -1,153 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { instrument } from './instrument';
3
- import { span } from 'autotel-edge';
4
- import { isWrapped } from '../bindings/common';
5
-
6
- /**
7
- * A KV-shaped binding so instrumentBindings() would proxy it in the OTLP path.
8
- * In native mode we must NOT proxy it (Cloudflare traces KV natively) — these
9
- * tests assert that the handler receives the original, unwrapped binding and
10
- * that user spans route to ctx.tracing.enterSpan instead of the OTel pipeline.
11
- */
12
- function fakeKv() {
13
- return {
14
- get: vi.fn(async () => 'value'),
15
- put: vi.fn(async () => {}),
16
- delete: vi.fn(async () => {}),
17
- list: vi.fn(async () => ({ keys: [] })),
18
- };
19
- }
20
-
21
- function nativeCtx() {
22
- const enteredSpans: string[] = [];
23
- const waitUntil = vi.fn();
24
- const ctx = {
25
- waitUntil,
26
- passThroughOnException() {},
27
- tracing: {
28
- enterSpan: vi.fn((name: string, cb: (s: any) => unknown) => {
29
- enteredSpans.push(name);
30
- return cb({ isTraced: true, setAttribute: vi.fn() });
31
- }),
32
- },
33
- };
34
- return { ctx, enteredSpans, waitUntil };
35
- }
36
-
37
- const baseConfig = {
38
- service: { name: 'native-test' },
39
- exporter: { url: 'http://localhost:4318/v1/traces' },
40
- } as const;
41
-
42
- describe('instrument() with Cloudflare native tracing (auto)', () => {
43
- it('defers binding instrumentation to the platform (no proxy wrapping)', async () => {
44
- const { ctx } = nativeCtx();
45
- const kv = fakeKv();
46
- let seenBinding: unknown;
47
-
48
- const handler = instrument(
49
- {
50
- async fetch(_req, env: { MY_KV: ReturnType<typeof fakeKv> }) {
51
- seenBinding = env.MY_KV;
52
- await env.MY_KV.get('k');
53
- return new Response('ok');
54
- },
55
- },
56
- baseConfig,
57
- );
58
-
59
- await handler.fetch!(new Request('https://x/'), { MY_KV: kv }, ctx as never);
60
-
61
- // Handler received the ORIGINAL binding, not an autotel proxy.
62
- expect(seenBinding).toBe(kv);
63
- expect(isWrapped(seenBinding)).toBe(false);
64
- // No "KV ...: get" span was created via the native tracer.
65
- expect(
66
- ctx.tracing.enterSpan.mock.calls.some(([name]) =>
67
- String(name).startsWith('KV '),
68
- ),
69
- ).toBe(false);
70
- });
71
-
72
- it('surfaces the cf-ray header as a correlation.id span attribute', async () => {
73
- const attrs: Record<string, unknown> = {};
74
- const ctx = {
75
- waitUntil() {},
76
- passThroughOnException() {},
77
- tracing: {
78
- enterSpan: vi.fn((_name: string, cb: (s: any) => unknown) =>
79
- cb({
80
- isTraced: true,
81
- setAttribute(k: string, v: unknown) {
82
- attrs[k] = v;
83
- },
84
- }),
85
- ),
86
- },
87
- };
88
-
89
- const handler = instrument(
90
- { async fetch() { return span('work', () => new Response('ok')); } },
91
- baseConfig,
92
- );
93
-
94
- const req = new Request('https://x/', { headers: { 'cf-ray': 'ray-7f' } });
95
- await handler.fetch!(req, {}, ctx as never);
96
- expect(attrs['correlation.id']).toBe('ray-7f');
97
- });
98
-
99
- it('routes user span() calls to ctx.tracing.enterSpan', async () => {
100
- const { ctx, enteredSpans } = nativeCtx();
101
-
102
- const handler = instrument(
103
- {
104
- async fetch() {
105
- return span('user.work', (s) => {
106
- s.setAttribute('ok', true);
107
- return new Response('done');
108
- });
109
- },
110
- },
111
- baseConfig,
112
- );
113
-
114
- const res = await handler.fetch!(new Request('https://x/'), {}, ctx as never);
115
- expect(await res.text()).toBe('done');
116
- expect(enteredSpans).toContain('user.work');
117
- });
118
-
119
- it('does not run the OTLP export flow (no waitUntil) in native mode', async () => {
120
- const { ctx, waitUntil } = nativeCtx();
121
- const handler = instrument(
122
- { async fetch() { return new Response('ok'); } },
123
- baseConfig,
124
- );
125
- await handler.fetch!(new Request('https://x/'), {}, ctx as never);
126
- expect(waitUntil).not.toHaveBeenCalled();
127
- });
128
- });
129
-
130
- describe('instrument() with nativeTracing: "off"', () => {
131
- it('ignores ctx.tracing and uses the autotel pipeline (proxies bindings)', async () => {
132
- const { ctx } = nativeCtx();
133
- const kv = fakeKv();
134
- let seenBinding: unknown;
135
-
136
- const handler = instrument(
137
- {
138
- async fetch(_req, env: { MY_KV: ReturnType<typeof fakeKv> }) {
139
- seenBinding = env.MY_KV;
140
- return new Response('ok');
141
- },
142
- },
143
- { ...baseConfig, nativeTracing: 'off' },
144
- );
145
-
146
- await handler.fetch!(new Request('https://x/'), { MY_KV: kv }, ctx as never);
147
-
148
- // OTLP path proxies the binding, so the handler sees a wrapped object.
149
- expect(isWrapped(seenBinding)).toBe(true);
150
- // Native tracer was never used.
151
- expect(ctx.tracing.enterSpan).not.toHaveBeenCalled();
152
- });
153
- });
@@ -1,34 +0,0 @@
1
- /**
2
- * Durable Object wrapper
3
- *
4
- * @example
5
- * ```typescript
6
- * import { wrapDurableObject } from 'autotel-cloudflare'
7
- *
8
- * class Counter implements DurableObject {
9
- * async fetch(request: Request) {
10
- * return new Response('count')
11
- * }
12
- * }
13
- *
14
- * export default wrapDurableObject({ service: { name: 'counter-do' } }, Counter)
15
- * ```
16
- */
17
-
18
- import { instrumentDO } from '../handlers/durable-objects';
19
- import type { ConfigurationOption } from 'autotel-edge';
20
-
21
- /**
22
- * Wrap a Durable Object class with instrumentation
23
- * Alternative API style inspired by workers-honeycomb-logger
24
- *
25
- * @param config Configuration (can be static object or function)
26
- * @param doClass The Durable Object class to wrap
27
- * @returns Instrumented Durable Object class
28
- */
29
- export function wrapDurableObject<T extends DurableObject>(
30
- config: ConfigurationOption,
31
- doClass: new (state: DurableObjectState, env: any) => T,
32
- ): new (state: DurableObjectState, env: any) => T {
33
- return instrumentDO(doClass, config);
34
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * workers-honeycomb-logger style wrapper API
3
- *
4
- * @example
5
- * ```typescript
6
- * import { wrapModule } from 'autotel-cloudflare'
7
- *
8
- * const handler = {
9
- * async fetch(req, env, ctx) {
10
- * return new Response('Hello')
11
- * }
12
- * }
13
- *
14
- * export default wrapModule(
15
- * { service: { name: 'my-worker' } },
16
- * handler
17
- * )
18
- * ```
19
- */
20
-
21
- import { instrument } from './instrument';
22
- import type { ConfigurationOption } from 'autotel-edge';
23
-
24
- /**
25
- * Wrap a Cloudflare Workers module-style handler
26
- * Alternative API style inspired by workers-honeycomb-logger
27
- *
28
- * @param config Configuration (can be static object or function)
29
- * @param handler The worker handler to wrap
30
- * @returns Instrumented handler
31
- */
32
- export function wrapModule<E, Q = any, C = any>(
33
- config: ConfigurationOption,
34
- handler: ExportedHandler<E, Q, C>,
35
- ): ExportedHandler<E, Q, C> {
36
- return instrument(handler, config);
37
- }