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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions apps/sim/app/api/knowledge/[id]/documents/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
`[${requestId}] Starting controlled async processing of ${createdDocuments.length} documents`
)

// Track bulk document upload
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')
trackPlatformEvent('platform.knowledge_base.documents_uploaded', {
'knowledge_base.id': knowledgeBaseId,
'documents.count': createdDocuments.length,
'documents.upload_type': 'bulk',
'processing.chunk_size': validatedData.processingOptions.chunkSize,
'processing.recipe': validatedData.processingOptions.recipe,
})
} catch (_e) {
// Silently fail
}

processDocumentsWithQueue(
createdDocuments,
knowledgeBaseId,
Expand Down Expand Up @@ -231,6 +245,20 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:

const newDocument = await createSingleDocument(validatedData, knowledgeBaseId, requestId)

// Track single document upload
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')
trackPlatformEvent('platform.knowledge_base.documents_uploaded', {
'knowledge_base.id': knowledgeBaseId,
'documents.count': 1,
'documents.upload_type': 'single',
'document.mime_type': validatedData.mimeType,
'document.file_size': validatedData.fileSize,
})
} catch (_e) {
// Silently fail
}

return NextResponse.json({
success: true,
data: newDocument,
Expand Down
12 changes: 0 additions & 12 deletions apps/sim/app/api/knowledge/search/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ describe('Knowledge Search API Route', () => {
const response = await POST(req)
const data = await response.json()

if (response.status !== 200) {
console.log('Test failed with response:', data)
}

expect(response.status).toBe(200)
expect(data.success).toBe(true)
expect(data.data.results).toHaveLength(2)
Expand Down Expand Up @@ -723,10 +719,6 @@ describe('Knowledge Search API Route', () => {
const response = await POST(req)
const data = await response.json()

if (response.status !== 200) {
console.log('Tag-only search test error:', data)
}

expect(response.status).toBe(200)
expect(data.success).toBe(true)
expect(data.data.results).toHaveLength(2)
Expand Down Expand Up @@ -783,10 +775,6 @@ describe('Knowledge Search API Route', () => {
const response = await POST(req)
const data = await response.json()

if (response.status !== 200) {
console.log('Query+tag combination test error:', data)
}

expect(response.status).toBe(200)
expect(data.success).toBe(true)
expect(data.data.results).toHaveLength(2)
Expand Down
14 changes: 14 additions & 0 deletions apps/sim/app/api/mcp/servers/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ export const POST = withMcpAuth('write')(
mcpService.clearCache(workspaceId)

logger.info(`[${requestId}] Successfully registered MCP server: ${body.name}`)

// Track MCP server registration
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')
trackPlatformEvent('platform.mcp.server_added', {
'mcp.server_id': serverId,
'mcp.server_name': body.name,
'mcp.transport': body.transport,
'workspace.id': workspaceId,
})
} catch (_e) {
// Silently fail
}

return createMcpSuccessResponse({ serverId }, 201)
} catch (error) {
logger.error(`[${requestId}] Error registering MCP server:`, error)
Expand Down
14 changes: 14 additions & 0 deletions apps/sim/app/api/mcp/tools/execute/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ export const POST = withMcpAuth('read')(
)
}
logger.info(`[${requestId}] Successfully executed tool ${toolName} on server ${serverId}`)

// Track MCP tool execution
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')
trackPlatformEvent('platform.mcp.tool_executed', {
'mcp.server_id': serverId,
'mcp.tool_name': toolName,
'mcp.execution_status': 'success',
'workspace.id': workspaceId,
})
} catch (_e) {
// Silently fail
}

return createMcpSuccessResponse(transformedResult)
} catch (error) {
logger.error(`[${requestId}] Error executing MCP tool:`, error)
Expand Down
13 changes: 13 additions & 0 deletions apps/sim/app/api/schedules/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ export async function POST(req: NextRequest) {
cronExpression,
})

// Track schedule creation/update
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')
trackPlatformEvent('platform.schedule.created', {
'workflow.id': workflowId,
'schedule.type': scheduleType || 'daily',
'schedule.timezone': timezone,
'schedule.is_custom': scheduleType === 'custom',
})
} catch (_e) {
// Silently fail
}

return NextResponse.json({
message: 'Schedule updated',
nextRunAt,
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/app/api/telemetry/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ALLOWED_CATEGORIES = [
'error',
'workflow',
'consent',
'batch',
]

const DEFAULT_TIMEOUT = 5000 // 5 seconds timeout
Expand Down Expand Up @@ -132,7 +133,6 @@ async function forwardToCollector(data: any): Promise<boolean> {
],
}

// Create explicit AbortController for timeout
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), timeout)

Expand Down
17 changes: 17 additions & 0 deletions apps/sim/app/api/templates/[id]/use/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
`[${requestId}] Successfully used template: ${id}, created workflow: ${newWorkflowId}, database returned: ${result.id}`
)

// Track template usage
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')
const templateState = templateData.state as any
trackPlatformEvent('platform.template.used', {
'template.id': id,
'template.name': templateData.name,
'workflow.created_id': newWorkflowId,
'workflow.blocks_count': templateState?.blocks
? Object.keys(templateState.blocks).length
: 0,
'workspace.id': workspaceId,
})
} catch (_e) {
// Silently fail
}

// Verify the workflow was actually created
const verifyWorkflow = await db
.select({ id: workflow.id })
Expand Down
36 changes: 36 additions & 0 deletions apps/sim/app/api/workflows/[id]/deploy/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,31 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{

logger.info(`[${requestId}] Workflow deployed successfully: ${id}`)

// Track workflow deployment
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')

// Aggregate block types to understand which blocks are being used
const blockTypeCounts: Record<string, number> = {}
for (const block of Object.values(currentState.blocks)) {
const blockType = (block as any).type || 'unknown'
blockTypeCounts[blockType] = (blockTypeCounts[blockType] || 0) + 1
}

trackPlatformEvent('platform.workflow.deployed', {
'workflow.id': id,
'workflow.name': workflowData!.name,
'workflow.blocks_count': Object.keys(currentState.blocks).length,
'workflow.edges_count': currentState.edges.length,
'workflow.has_loops': Object.keys(currentState.loops).length > 0,
'workflow.has_parallels': Object.keys(currentState.parallels).length > 0,
'workflow.api_key_type': keyInfo?.type || 'default',
'workflow.block_types': JSON.stringify(blockTypeCounts),
})
} catch (_e) {
// Silently fail
}

const responseApiKeyInfo = keyInfo ? `${keyInfo.name} (${keyInfo.type})` : 'Default key'

return createSuccessResponse({
Expand Down Expand Up @@ -400,6 +425,17 @@ export async function DELETE(
})

logger.info(`[${requestId}] Workflow undeployed successfully: ${id}`)

// Track workflow undeployment
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')
trackPlatformEvent('platform.workflow.undeployed', {
'workflow.id': id,
})
} catch (_e) {
// Silently fail
}

return createSuccessResponse({
isDeployed: false,
deployedAt: null,
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/app/api/workflows/[id]/log/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
variables: {},
})

const { traceSpans } = buildTraceSpans(result)
const { traceSpans, totalDuration } = buildTraceSpans(result)

if (result.success === false) {
const message = result.error || 'Workflow execution failed'
await loggingSession.safeCompleteWithError({
endedAt: new Date().toISOString(),
totalDurationMs: result.metadata?.duration || 0,
totalDurationMs: totalDuration || result.metadata?.duration || 0,
error: { message },
traceSpans,
})
} else {
await loggingSession.safeComplete({
endedAt: new Date().toISOString(),
totalDurationMs: result.metadata?.duration || 0,
totalDurationMs: totalDuration || result.metadata?.duration || 0,
finalOutput: result.output || {},
traceSpans,
})
Expand Down
13 changes: 13 additions & 0 deletions apps/sim/app/api/workflows/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ export async function POST(req: NextRequest) {

logger.info(`[${requestId}] Creating workflow ${workflowId} for user ${session.user.id}`)

// Track workflow creation
try {
const { trackPlatformEvent } = await import('@/lib/telemetry/tracer')
trackPlatformEvent('platform.workflow.created', {
'workflow.id': workflowId,
'workflow.name': name,
'workflow.has_workspace': !!workspaceId,
'workflow.has_folder': !!folderId,
})
} catch (_e) {
// Silently fail
}

await db.insert(workflow).values({
id: workflowId,
userId: session.user.id,
Expand Down
Loading