Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions js/core/src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ export function detachedAction<
...registry.context,
...(opts?.context ?? getContext(registry)),
},
abortSignal: opts?.abortSignal,
telemetryLabels: opts?.telemetryLabels,
})
.then((s) => s.result)
.finally(() => {
Expand Down
7 changes: 6 additions & 1 deletion js/core/src/reflection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ export class ReflectionServer {
const result = await runWithStreamingCallback(
this.registry,
callback,
() => action.run(input, { context, onChunk: callback })
() =>
action.run(input, {
context,
onChunk: callback,
telemetryLabels,
})
);
await flushTracing();
response.write(
Expand Down
34 changes: 32 additions & 2 deletions js/core/tests/flow_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,33 @@ describe('flow', () => {
it('should create a trace', async () => {
const testFlow = createTestFlow(registry);

const result = await testFlow('foo');
const result = await testFlow('foo', {
telemetryLabels: { custom: 'label' },
});

assert.equal(result, 'bar foo');
assert.strictEqual(spanExporter.exportedSpans.length, 1);
assert.strictEqual(spanExporter.exportedSpans[0].displayName, 'testFlow');
assert.deepStrictEqual(spanExporter.exportedSpans[0].attributes, {
'genkit:input': '"foo"',
'genkit:isRoot': true,
'genkit:metadata:subtype': 'flow',
'genkit:name': 'testFlow',
'genkit:output': '"bar foo"',
'genkit:path': '/{testFlow,t:flow}',
'genkit:state': 'success',
'genkit:type': 'action',
custom: 'label',
});
});

it('should create a trace when streaming', async () => {
const testFlow = createTestFlow(registry);

const { output } = testFlow.stream('foo', {
telemetryLabels: { custom: 'label' },
});
const result = await output;

assert.equal(result, 'bar foo');
assert.strictEqual(spanExporter.exportedSpans.length, 1);
Expand All @@ -354,11 +380,13 @@ describe('flow', () => {
'genkit:input': '"foo"',
'genkit:isRoot': true,
'genkit:metadata:subtype': 'flow',
'genkit:metadata:context': '{}',
'genkit:name': 'testFlow',
'genkit:output': '"bar foo"',
'genkit:path': '/{testFlow,t:flow}',
'genkit:state': 'success',
'genkit:type': 'action',
custom: 'label',
});
});

Expand Down Expand Up @@ -392,7 +420,9 @@ describe('flow', () => {
);
}
);
const result = await testFlow('foo', { context: { user: 'pavel' } });
const result = await testFlow('foo', {
context: { user: 'pavel' },
});

assert.equal(result, 'foo bar');
assert.strictEqual(spanExporter.exportedSpans.length, 3);
Expand Down