Skip to content

Commit b9f1c7f

Browse files
committed
refactor(stream): add span
1 parent 5e5844c commit b9f1c7f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/wizard/stream.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import {
2020
ResourceType,
2121
} from 'omniboxd/resources/entities/resource.entity';
2222
import { ChatResponse } from 'omniboxd/wizard/dto/chat-response.dto';
23-
import { context, propagation } from '@opentelemetry/api';
23+
import { context, propagation, trace } from '@opentelemetry/api';
2424
import { Share } from 'omniboxd/shares/entities/share.entity';
2525
import { SharedResourcesService } from 'omniboxd/shared-resources/shared-resources.service';
2626
import { ResourcesService } from 'omniboxd/resources/resources.service';
27+
import { Span } from 'nestjs-otel';
2728

2829
interface HandlerContext {
2930
parentId?: string;
@@ -42,12 +43,18 @@ export class StreamService {
4243
private readonly resourcesService: ResourcesService,
4344
) {}
4445

46+
@Span('stream')
4547
async stream(
4648
url: string,
4749
body: Record<string, any>,
4850
requestId: string,
4951
callback: (data: string) => Promise<void>,
5052
): Promise<void> {
53+
const span = trace.getSpan(context.active());
54+
if (span) {
55+
span.setAttribute('agent_request', JSON.stringify(body));
56+
}
57+
5158
const traceHeaders: Record<string, string> = {};
5259
propagation.inject(context.active(), traceHeaders);
5360
const response = await fetch(`${this.wizardBaseUrl}${url}`, {

0 commit comments

Comments
 (0)