Skip to content

Commit 116a3c5

Browse files
committed
improvement(posthog): tighten trace ID parse and verbose comments
1 parent 7de6520 commit 116a3c5

2 files changed

Lines changed: 4 additions & 16 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,12 +1279,7 @@ export interface UseChatOptions {
12791279
onTitleUpdate?: () => void
12801280
onStreamEnd?: (chatId: string, messages: ChatMessage[]) => void
12811281
initialActiveResourceId?: string | null
1282-
/**
1283-
* Fired once per chat send as soon as the server's `traceparent`
1284-
* response header arrives (i.e. before any stream content). Used by
1285-
* callers to emit a follow-up PostHog event carrying the request ID
1286-
* for correlation with Go-side logs.
1287-
*/
1282+
/** Fired when the server's `traceparent` response header arrives, before any stream content. */
12881283
onRequestStarted?: (info: { requestId: string; userMessageId: string }) => void
12891284
}
12901285

@@ -4224,9 +4219,8 @@ export function useChat(
42244219
if (traceparent) {
42254220
streamTraceparentRef.current = traceparent
42264221
setCurrentChatTraceparent(traceparent)
4227-
const parts = traceparent.split('-')
4228-
const traceId = parts.length === 4 ? parts[1] : ''
4229-
if (/^[0-9a-f]{32}$/.test(traceId) && traceId !== '0'.repeat(32)) {
4222+
const traceId = traceparent.split('-')[1] ?? ''
4223+
if (/^[0-9a-f]{32}$/.test(traceId)) {
42304224
try {
42314225
onRequestStartedRef.current?.({ requestId: traceId, userMessageId })
42324226
} catch (callbackError) {

apps/sim/lib/posthog/events.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,7 @@ export interface PostHogEventMap {
428428
is_new_task: boolean
429429
}
430430

431-
/**
432-
* Fired when the server has assigned a request ID for a chat send (i.e.
433-
* the SSE response headers have arrived with a `traceparent`). Pairs
434-
* one-to-one with `task_message_sent` (or with a queued/replay dispatch)
435-
* via timestamp proximity, and carries the `request_id` used by Go for
436-
* log correlation.
437-
*/
431+
/** Pairs with `task_message_sent` via `request_id` for correlation with server-side logs. */
438432
task_request_started: {
439433
workspace_id: string
440434
view: 'mothership' | 'copilot'

0 commit comments

Comments
 (0)