Skip to content
Open
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
4 changes: 4 additions & 0 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ OPENAI_API_KEY=
ANTHROPIC_API_KEY=
GROQ_API_KEY=

# Inference.net Catalyst tracing (optional — no-op if CATALYST_OTLP_TOKEN is unset)
CATALYST_OTLP_TOKEN=
CATALYST_OTLP_ENDPOINT=https://telemetry.inference.net

# Resend (for sending emails)
RESEND_API_KEY=
RESEND_FROM_SYSTEM= # e.g., noreply@mail.trycomp.ai
Expand Down
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@aws-sdk/s3-request-presigner": "3.1013.0",
"@browserbasehq/sdk": "2.6.0",
"@browserbasehq/stagehand": "^3.2.1",
"@inference/tracing": "^0.0.21",
"@maced/api-client": "^0.9.2",
"@mendable/firecrawl-js": "^4.9.3",
"@nestjs/common": "^11.0.1",
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/assistant-chat/assistant-chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { buildTools } from './assistant-chat-tools';
import type { AssistantChatMessage } from './assistant-chat.types';
import { RolesService } from '../roles/roles.service';
import { ASSISTANT_OPENAI_PROVIDER_OPTIONS } from './openai-options';
import { getAITelemetry } from '../inference-tracing';

@ApiTags('Assistant Chat')
@Controller({ path: 'assistant-chat', version: '1' })
Expand Down Expand Up @@ -132,6 +133,7 @@ Important:
tools,
providerOptions: ASSISTANT_OPENAI_PROVIDER_OPTIONS,
stopWhen: stepCountIs(5),
experimental_telemetry: getAITelemetry('grc-assistant'),
});

const webResponse = result.toUIMessageStreamResponse({
Expand Down
28 changes: 28 additions & 0 deletions apps/api/src/inference-tracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as ai from 'ai';
import { setup, type CatalystTracing } from '@inference/tracing';
import { createAISdkTelemetrySettings } from '@inference/tracing/ai-sdk';

let tracing: CatalystTracing | null = null;

export async function initTracing(): Promise<void> {
if (!process.env.CATALYST_OTLP_TOKEN) return;

tracing = await setup({
serviceName: 'compai-api',
modules: { aiSdk: ai },
});

console.log(
`Catalyst tracing enabled → ${tracing.endpoint} as ${tracing.serviceName}`,
);
}

export async function shutdownTracing(): Promise<void> {
if (!tracing) return;
await tracing.shutdown();
}

export function getAITelemetry(functionId: string) {
if (!tracing) return undefined;
return createAISdkTelemetrySettings(tracing.tracer, { functionId });
}
4 changes: 4 additions & 0 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as express from 'express';
import helmet from 'helmet';
import path from 'path';
import { AppModule } from './app.module';
import { initTracing, shutdownTracing } from './inference-tracing';
import {
applyPublicOpenApiMetadata,
PUBLIC_OPENAPI_DESCRIPTION,
Expand All @@ -34,6 +35,8 @@ function describeServer(baseUrl: string): string {
}

async function bootstrap(): Promise<void> {
await initTracing();

// Disable body parser - required for better-auth NestJS integration
// The library will re-add body parsers after handling auth routes
app = await NestFactory.create(AppModule, {
Expand Down Expand Up @@ -216,6 +219,7 @@ async function shutdown(signal: string): Promise<void> {
await app.close();
console.log('Application closed');
}
await shutdownTracing();
process.exit(0);
}

Expand Down
Loading
Loading