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 — see apps/api/src/inference-tracing.ts
CATALYST_OTLP_TOKEN= # Inference API key (https://inference.net)
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.19",
"@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
24 changes: 24 additions & 0 deletions apps/api/src/inference-tracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as ai from 'ai';
import { setup } from '@inference/tracing';
import { createAISdkTelemetrySettings } from '@inference/tracing/ai-sdk';

type Tracing = Awaited<ReturnType<typeof setup>>;

let tracing: Tracing | null = null;

export async function initTracing(): Promise<void> {
tracing = await setup({
serviceName: 'compai-grc-assistant',
modules: { aiSdk: ai },
});
}

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 });
}
6 changes: 6 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,10 @@ function describeServer(baseUrl: string): string {
}

async function bootstrap(): Promise<void> {
// Catalyst tracing must initialize before the AI SDK is first used
// (assistant-chat controller passes experimental_telemetry on streamText).
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 +221,7 @@ async function shutdown(signal: string): Promise<void> {
await app.close();
console.log('Application closed');
}
await shutdownTracing();
process.exit(0);
}

Expand Down
4 changes: 4 additions & 0 deletions apps/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ NEXT_PUBLIC_PORTAL_URL="http://localhost:3002"
ANTHROPIC_API_KEY="" # Optional, For more options with models
BETTER_AUTH_URL=http://localhost:3000 # For auth

# Inference.net Catalyst tracing — see apps/app/src/lib/inference-tracing.ts
CATALYST_OTLP_TOKEN="" # Inference API key (https://inference.net)
CATALYST_OTLP_ENDPOINT=https://telemetry.inference.net

NEXT_OUTPUT_STANDALONE=false # For deploying on AWS instead of Vercel

FLEET_URL="" # If you want to enable MDM, your hosted url
Expand Down
1 change: 1 addition & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@dub/better-auth": "^0.0.6",
"@dub/embed-react": "^0.0.16",
"@hookform/resolvers": "^5.1.1",
"@inference/tracing": "^0.0.19",
"@mendable/firecrawl-js": "^1.24.0",
"@monaco-editor/react": "^4.7.0",
"@nangohq/frontend": "^0.53.2",
Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/app/api/policies/[policyId]/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { auth } from '@/utils/auth';
import { getAITelemetry } from '@/lib/inference-tracing';
import { anthropic } from '@ai-sdk/anthropic';
import { db } from '@db/server';
import { convertToModelMessages, streamText, stepCountIs, type UIMessage } from 'ai';
Expand Down Expand Up @@ -194,6 +195,7 @@ You MUST produce the policy by starting from the <current_policy> text above and
toolChoice: 'auto',
stopWhen: stepCountIs(5),
tools: getPolicyTools({ currentPolicyId: policyId, cookieHeader: cookieStr }),
experimental_telemetry: getAITelemetry('policy-editor'),
});

return result.toUIMessageStreamResponse();
Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as Sentry from "@sentry/nextjs";
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
await import("../sentry.server.config");
const { initTracing } = await import("./lib/inference-tracing");
await initTracing();
}

if (process.env.NEXT_RUNTIME === "edge") {
Expand Down
24 changes: 24 additions & 0 deletions apps/app/src/lib/inference-tracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { setup } from '@inference/tracing';
import { createAISdkTelemetrySettings } from '@inference/tracing/ai-sdk';
import * as ai from 'ai';

type Tracing = Awaited<ReturnType<typeof setup>>;

let tracing: Tracing | null = null;

export async function initTracing(): Promise<void> {
tracing = await setup({
serviceName: 'compai-policy-editor',
modules: { aiSdk: ai },
});
}

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 });
}
Loading