Skip to content

Commit 5ff1f28

Browse files
committed
Tracing v1
1 parent 377712c commit 5ff1f28

40 files changed

+6204
-3759
lines changed

apps/sim/app/api/copilot/api-keys/generate/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type NextRequest, NextResponse } from 'next/server'
22
import { z } from 'zod'
33
import { getSession } from '@/lib/auth'
44
import { SIM_AGENT_API_URL } from '@/lib/copilot/constants'
5+
import { fetchGo } from '@/lib/copilot/request/go/fetch'
56
import { env } from '@/lib/core/config/env'
67

78
const GenerateApiKeySchema = z.object({
@@ -32,13 +33,16 @@ export async function POST(req: NextRequest) {
3233

3334
const { name } = validationResult.data
3435

35-
const res = await fetch(`${SIM_AGENT_API_URL}/api/validate-key/generate`, {
36+
const res = await fetchGo(`${SIM_AGENT_API_URL}/api/validate-key/generate`, {
3637
method: 'POST',
3738
headers: {
3839
'Content-Type': 'application/json',
3940
...(env.COPILOT_API_KEY ? { 'x-api-key': env.COPILOT_API_KEY } : {}),
4041
},
4142
body: JSON.stringify({ userId, name }),
43+
spanName: 'sim → go /api/validate-key/generate',
44+
operation: 'generate_api_key',
45+
attributes: { 'user.id': userId },
4246
})
4347

4448
if (!res.ok) {

apps/sim/app/api/copilot/api-keys/route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type NextRequest, NextResponse } from 'next/server'
22
import { getSession } from '@/lib/auth'
33
import { SIM_AGENT_API_URL } from '@/lib/copilot/constants'
4+
import { fetchGo } from '@/lib/copilot/request/go/fetch'
45
import { env } from '@/lib/core/config/env'
56

67
export async function GET(request: NextRequest) {
@@ -12,13 +13,16 @@ export async function GET(request: NextRequest) {
1213

1314
const userId = session.user.id
1415

15-
const res = await fetch(`${SIM_AGENT_API_URL}/api/validate-key/get-api-keys`, {
16+
const res = await fetchGo(`${SIM_AGENT_API_URL}/api/validate-key/get-api-keys`, {
1617
method: 'POST',
1718
headers: {
1819
'Content-Type': 'application/json',
1920
...(env.COPILOT_API_KEY ? { 'x-api-key': env.COPILOT_API_KEY } : {}),
2021
},
2122
body: JSON.stringify({ userId }),
23+
spanName: 'sim → go /api/validate-key/get-api-keys',
24+
operation: 'get_api_keys',
25+
attributes: { 'user.id': userId },
2226
})
2327

2428
if (!res.ok) {
@@ -66,13 +70,16 @@ export async function DELETE(request: NextRequest) {
6670
return NextResponse.json({ error: 'id is required' }, { status: 400 })
6771
}
6872

69-
const res = await fetch(`${SIM_AGENT_API_URL}/api/validate-key/delete`, {
73+
const res = await fetchGo(`${SIM_AGENT_API_URL}/api/validate-key/delete`, {
7074
method: 'POST',
7175
headers: {
7276
'Content-Type': 'application/json',
7377
...(env.COPILOT_API_KEY ? { 'x-api-key': env.COPILOT_API_KEY } : {}),
7478
},
7579
body: JSON.stringify({ userId, apiKeyId: id }),
80+
spanName: 'sim → go /api/validate-key/delete',
81+
operation: 'delete_api_key',
82+
attributes: { 'user.id': userId, 'api_key.id': id },
7683
})
7784

7885
if (!res.ok) {

apps/sim/app/api/copilot/auto-allowed-tools/route.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { getSession } from '@/lib/auth'
44
import { SIM_AGENT_API_URL } from '@/lib/copilot/constants'
5+
import { fetchGo } from '@/lib/copilot/request/go/fetch'
56
import { env } from '@/lib/core/config/env'
67

78
const logger = createLogger('CopilotAutoAllowedToolsAPI')
@@ -30,9 +31,15 @@ export async function GET() {
3031

3132
const userId = session.user.id
3233

33-
const res = await fetch(
34+
const res = await fetchGo(
3435
`${SIM_AGENT_API_URL}/api/tool-preferences/auto-allowed?userId=${encodeURIComponent(userId)}`,
35-
{ method: 'GET', headers: copilotHeaders() }
36+
{
37+
method: 'GET',
38+
headers: copilotHeaders(),
39+
spanName: 'sim → go /api/tool-preferences/auto-allowed',
40+
operation: 'list_auto_allowed_tools',
41+
attributes: { 'user.id': userId },
42+
}
3643
)
3744

3845
if (!res.ok) {
@@ -66,10 +73,13 @@ export async function POST(request: NextRequest) {
6673
return NextResponse.json({ error: 'toolId must be a string' }, { status: 400 })
6774
}
6875

69-
const res = await fetch(`${SIM_AGENT_API_URL}/api/tool-preferences/auto-allowed`, {
76+
const res = await fetchGo(`${SIM_AGENT_API_URL}/api/tool-preferences/auto-allowed`, {
7077
method: 'POST',
7178
headers: copilotHeaders(),
7279
body: JSON.stringify({ userId, toolId: body.toolId }),
80+
spanName: 'sim → go /api/tool-preferences/auto-allowed',
81+
operation: 'add_auto_allowed_tool',
82+
attributes: { 'user.id': userId, 'tool.id': body.toolId },
7383
})
7484

7585
if (!res.ok) {
@@ -107,9 +117,15 @@ export async function DELETE(request: NextRequest) {
107117
return NextResponse.json({ error: 'toolId query parameter is required' }, { status: 400 })
108118
}
109119

110-
const res = await fetch(
120+
const res = await fetchGo(
111121
`${SIM_AGENT_API_URL}/api/tool-preferences/auto-allowed?userId=${encodeURIComponent(userId)}&toolId=${encodeURIComponent(toolId)}`,
112-
{ method: 'DELETE', headers: copilotHeaders() }
122+
{
123+
method: 'DELETE',
124+
headers: copilotHeaders(),
125+
spanName: 'sim → go /api/tool-preferences/auto-allowed',
126+
operation: 'remove_auto_allowed_tool',
127+
attributes: { 'user.id': userId, 'tool.id': toolId },
128+
}
113129
)
114130

115131
if (!res.ok) {

apps/sim/app/api/copilot/chat/abort/route.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { NextResponse } from 'next/server'
33
import { getLatestRunForStream } from '@/lib/copilot/async-runs/repository'
44
import { SIM_AGENT_API_URL } from '@/lib/copilot/constants'
5+
import { fetchGo } from '@/lib/copilot/request/go/fetch'
56
import { authenticateCopilotRequestSessionOnly } from '@/lib/copilot/request/http'
67
import { abortActiveStream, waitForPendingChatStream } from '@/lib/copilot/request/session'
78
import { env } from '@/lib/core/config/env'
@@ -54,7 +55,7 @@ export async function POST(request: Request) {
5455
() => controller.abort('timeout:go_explicit_abort_fetch'),
5556
GO_EXPLICIT_ABORT_TIMEOUT_MS
5657
)
57-
const response = await fetch(`${SIM_AGENT_API_URL}/api/streams/explicit-abort`, {
58+
const response = await fetchGo(`${SIM_AGENT_API_URL}/api/streams/explicit-abort`, {
5859
method: 'POST',
5960
headers,
6061
signal: controller.signal,
@@ -63,6 +64,12 @@ export async function POST(request: Request) {
6364
userId: authenticatedUserId,
6465
...(chatId ? { chatId } : {}),
6566
}),
67+
spanName: 'sim → go /api/streams/explicit-abort',
68+
operation: 'explicit_abort',
69+
attributes: {
70+
'copilot.stream.id': streamId,
71+
...(chatId ? { 'chat.id': chatId } : {}),
72+
},
6673
}).finally(() => clearTimeout(timeout))
6774
if (!response.ok) {
6875
throw new Error(`Explicit abort marker request failed: ${response.status}`)

0 commit comments

Comments
 (0)