Skip to content

Commit

Permalink
Prompt Observability (#191)
Browse files Browse the repository at this point in the history
* chore: Attempting to add HoneyHive

* fix: no errors but honeyhive still not working

* Remove Honeyhive

* feat: Langfuse Tracing

* chore: remove honeyhive deps

* chore (langfuse):Add environment and release info

* chore: Fix Build Errors
  • Loading branch information
VVoruganti authored Dec 26, 2024
1 parent e23fcee commit 45a7b76
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 136 deletions.
5 changes: 5 additions & 0 deletions www/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ AI_API_KEY=
MODEL=
HONCHO_URL=
HONCHO_APP_NAME=

# Langfuse
LANGFUSE_SECRET_KEY=
LANGFUSE_PUBLIC_KEY=
LANGFUSE_BASEURL=
13 changes: 13 additions & 0 deletions www/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const dynamic = 'force-dynamic'; // always run dynamically

const OPENROUTER_API_KEY = process.env.AI_API_KEY;
const MODEL = process.env.MODEL || 'gpt-3.5-turbo';
const SENTRY_RELEASE = process.env.SENTRY_RELEASE || 'dev';
const SENTRY_ENVIRONMENT = process.env.SENTRY_ENVIRONMENT || 'local';

const openrouter = createOpenRouter({
// custom settings, e.g.
Expand Down Expand Up @@ -117,6 +119,7 @@ async function saveHistory({

async function fetchOpenRouter(type: string, messages: any[], payload: any) {
try {

const result = streamText({
model: openrouter(MODEL),
messages,
Expand All @@ -127,6 +130,16 @@ async function fetchOpenRouter(type: string, messages: any[], payload: any) {
await saveHistory(finalPayload);
}
},
experimental_telemetry: {
isEnabled: true,
metadata: {
sessionId: payload.sessionId,
userId: payload.userId,
release: SENTRY_RELEASE,
environment: SENTRY_ENVIRONMENT,
tags: [type]
}
}
});
return result.toTextStreamResponse();
} catch (error) {
Expand Down
10 changes: 10 additions & 0 deletions www/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import * as Sentry from "@sentry/nextjs";

import { registerOTel } from '@vercel/otel';
import { LangfuseExporter } from 'langfuse-vercel'

export async function register() {

registerOTel({
serviceName: 'tutor-gpt',
traceExporter: new LangfuseExporter()
})

if (process.env.NEXT_RUNTIME === "nodejs") {
await import("./sentry.server.config");
}

if (process.env.NEXT_RUNTIME === "edge") {
await import("./sentry.edge.config");
}

}

export const onRequestError = Sentry.captureRequestError;
12 changes: 12 additions & 0 deletions www/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { withSentryConfig } from "@sentry/nextjs";
const nextConfig = {
output: "standalone",
experimental: {
instrumentationHook: true,
}
// webpack: (config, { isServer }) => {
// // Add a fallback for the https scheme
// config.resolve.fallback = {
// ...config.resolve.fallback,
// https: false,
// };
//
// return config;
// },
};

const sentryConfig = withSentryConfig(nextConfig, {
Expand Down
5 changes: 5 additions & 0 deletions www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@
},
"dependencies": {
"@openrouter/ai-sdk-provider": "^0.0.6",
"@opentelemetry/api-logs": "^0.56.0",
"@opentelemetry/instrumentation": "^0.56.0",
"@opentelemetry/sdk-logs": "^0.56.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.1",
"@sentry/nextjs": "^8.38.0",
"@stripe/stripe-js": "^4.9.0",
"@supabase/ssr": "^0.5.2",
"@supabase/supabase-js": "^2.45.6",
"@vercel/otel": "^1.10.0",
"@vercel/speed-insights": "^1.1.0",
"ai": "^4.0.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"honcho-ai": "^0.0.11",
"katex": "^0.16.11",
"langfuse-vercel": "^3.32.0",
"next": "^14.2.16",
"next-themes": "^0.3.0",
"openai": "^4.72.0",
Expand Down
Loading

0 comments on commit 45a7b76

Please sign in to comment.