Skip to content

Commit 9cdcbf0

Browse files
committed
[o11y][nfc] Emit jsRpc call attributes in standard test worker, use it for sql-test
1 parent cc1d9c7 commit 9cdcbf0

15 files changed

+42
-82
lines changed

src/workerd/api/tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ wd_test(
124124
src = "sql-test.wd-test",
125125
args = ["--experimental"],
126126
data = [
127+
"instrumentation-tail-worker.js",
127128
"sql-test.js",
128129
"sql-test-tail.js",
129130
],

src/workerd/api/tests/actor-kv-test-tail.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
invocationPromises,
44
spans,
55
testTailHandler,
6-
} from 'test:instumentation-tail';
6+
} from 'test:instrumentation-tail';
77

88
// Use shared instrumentation test tail worker
99
export default testTailHandler;
@@ -27,10 +27,7 @@ export const test = {
2727
];
2828

2929
await Promise.allSettled(invocationPromises);
30-
let received = Array.from(spans.values()).filter(
31-
(span) => span.name !== 'jsRpcSession'
32-
);
30+
let received = Array.from(spans.values());
3331
assert.deepStrictEqual(received, expected);
34-
return new Response('');
3532
},
3633
};

src/workerd/api/tests/actor-kv-test.wd-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const config :Workerd.Config = (
88
],
99
extensions = [ (
1010
modules = [
11-
( name = "test:instumentation-tail", esModule = embed "instrumentation-tail-worker.js" ),
11+
( name = "test:instrumentation-tail", esModule = embed "instrumentation-tail-worker.js" ),
1212
]
1313
) ]
1414
);

src/workerd/api/tests/analytics-engine-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ export default {
2323
});
2424

2525
assert.equal(await isWritten(5000), true);
26-
return new Response('');
2726
},
2827
};

src/workerd/api/tests/cache-instrumentation-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
invocationPromises,
77
spans,
88
testTailHandler,
9-
} from 'test:instumentation-tail';
9+
} from 'test:instrumentation-tail';
1010

1111
// Use shared instrumentation test tail worker
1212
export default testTailHandler;

src/workerd/api/tests/cache-test.wd-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const unitTests :Workerd.Config = (
2323
],
2424
extensions = [ (
2525
modules = [
26-
( name = "test:instumentation-tail", esModule = embed "instrumentation-tail-worker.js" ),
26+
( name = "test:instrumentation-tail", esModule = embed "instrumentation-tail-worker.js" ),
2727
]
2828
) ]
2929
);

src/workerd/api/tests/instrumentation-tail-worker.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@ export const testTailHandler = {
3232
});
3333
break;
3434
case 'attributes': {
35-
// Filter out top-level attributes events (jsRpcSession span)
35+
let span = spans.get(spanKey);
3636
if (event.spanContext.spanId === topLevelSpanId) {
37-
// Ignore attributes for the top-level span
37+
// top-level JsRpc method name attribute – transform into a span with the given name
38+
const rpcMethodName = event.event.info.find(
39+
(item) => item['name'] === 'jsrpc.method'
40+
).value;
41+
span = { name: rpcMethodName };
42+
spans.set(spanKey, span);
3843
break;
3944
}
4045

4146
// attributes references an existing span via spanContext.spanId
42-
let span = spans.get(spanKey);
4347
if (!span) {
4448
throw new Error(`Attributes event for unknown span: ${spanKey}`);
4549
}

src/workerd/api/tests/kv-instrumentation-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
invocationPromises,
77
spans,
88
testTailHandler,
9-
} from 'test:instumentation-tail';
9+
} from 'test:instrumentation-tail';
1010

1111
// Use shared instrumentation test tail worker
1212
export default testTailHandler;
@@ -16,10 +16,10 @@ export const test = {
1616
// Wait for all the tailStream executions to finish
1717
await Promise.allSettled(invocationPromises);
1818

19-
// Recorded streaming tail worker events, in insertion order,
20-
// filtering spans not associated with KV
21-
let received = Array.from(spans.values()).filter(
22-
(span) => span.name !== 'jsRpcSession'
19+
// Recorded streaming tail worker events, in insertion order, filtering spans not associated
20+
// with KV, including jsRpc calls
21+
let received = Array.from(spans.values()).filter((span) =>
22+
span.name.match('kv')
2323
);
2424

2525
// spans emitted by kv-test.js in execution order

src/workerd/api/tests/kv-test.wd-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const unitTests :Workerd.Config = (
1717
],
1818
extensions = [ (
1919
modules = [
20-
( name = "test:instumentation-tail", esModule = embed "instrumentation-tail-worker.js" ),
20+
( name = "test:instrumentation-tail", esModule = embed "instrumentation-tail-worker.js" ),
2121
]
2222
) ]
2323
);

src/workerd/api/tests/r2-instrumentation-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
invocationPromises,
77
spans,
88
testTailHandler,
9-
} from 'test:instumentation-tail';
9+
} from 'test:instrumentation-tail';
1010

1111
// Use shared instrumentation test tail worker
1212
export default testTailHandler;

0 commit comments

Comments
 (0)