Skip to content

Commit d7c333c

Browse files
committed
fix(chat): disable staging ai telemetry
1 parent 7dc2e10 commit d7c333c

6 files changed

Lines changed: 41 additions & 9 deletions

File tree

apps/chat/src/app/api/chatbots/[chatbotId]/chat/route.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ if (!process.env.OPENAI_API_KEY) {
5959
}
6060
const CHAT_LOG_PREFIX = '[chat:dev]'
6161
const isDevLogging = process.env.NODE_ENV === 'development'
62+
const isAiTelemetryEnabled = process.env.CHAT_ENABLE_AI_TELEMETRY !== 'false'
6263
const MAX_LOG_STRING_LENGTH = 500
6364
const HASH_DIGEST_LENGTH = 12
6465

@@ -1268,7 +1269,7 @@ export async function POST(
12681269
const result = streamText({
12691270
model,
12701271
maxOutputTokens,
1271-
experimental_telemetry: { isEnabled: true },
1272+
experimental_telemetry: { isEnabled: isAiTelemetryEnabled },
12721273
providerOptions: {
12731274
openai: {
12741275
...(selectedModelConfig.supportsReasoning && {
@@ -1691,6 +1692,20 @@ export async function POST(
16911692

16921693
return result.toUIMessageStreamResponse({
16931694
sendReasoning: true,
1695+
onError: (error) => {
1696+
const serializedError = serializeStreamError(error)
1697+
const classification = classifyStreamError(serializedError)
1698+
1699+
console.error('Error while streaming UI message response:', {
1700+
requestId,
1701+
error: serializedError,
1702+
classification: classification.classification,
1703+
retryable: classification.retryable,
1704+
suggestedAction: classification.suggestedAction,
1705+
})
1706+
1707+
return 'An error occurred while processing the request.'
1708+
},
16941709
messageMetadata: ({ part }) => {
16951710
if (part.type !== 'finish') {
16961711
return undefined

apps/chat/src/instrumentation.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
const isAiTelemetryEnabled = () =>
2+
process.env.CHAT_ENABLE_AI_TELEMETRY !== 'false'
3+
14
export async function register() {
2-
if (process.env.NEXT_RUNTIME === 'nodejs') {
3-
const { LangfuseSpanProcessor } = await import('@langfuse/otel')
4-
const { NodeTracerProvider } = await import('@opentelemetry/sdk-trace-node')
5+
if (process.env.NEXT_RUNTIME !== 'nodejs' || !isAiTelemetryEnabled()) {
6+
return
7+
}
58

6-
const langfuseSpanProcessor = new LangfuseSpanProcessor()
9+
const { LangfuseSpanProcessor } = await import('@langfuse/otel')
10+
const { NodeTracerProvider } = await import('@opentelemetry/sdk-trace-node')
711

8-
const tracerProvider = new NodeTracerProvider()
9-
tracerProvider.addSpanProcessor(langfuseSpanProcessor)
10-
tracerProvider.register()
11-
}
12+
const langfuseSpanProcessor = new LangfuseSpanProcessor()
13+
14+
const tracerProvider = new NodeTracerProvider()
15+
tracerProvider.addSpanProcessor(langfuseSpanProcessor)
16+
tracerProvider.register()
1217
}

deploy/charts/klicker-uzh-v3/templates/cm-chat.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{{- $fullName := include "chart.fullname" . -}}
2+
{{- $chatTelemetryEnabled := true -}}
3+
{{- if and .Values.chat.telemetry (hasKey .Values.chat.telemetry "enabled") -}}
4+
{{- $chatTelemetryEnabled = .Values.chat.telemetry.enabled -}}
5+
{{- end -}}
26
apiVersion: v1
37
kind: ConfigMap
48
metadata:
@@ -8,6 +12,7 @@ metadata:
812
data:
913
OPENAI_BASE_URL: {{ .Values.chat.openai.baseUrl | quote }}
1014
CHAT_OPENAI_STORE_RESPONSES: {{ .Values.chat.openai.storeResponses | default false | quote }}
15+
CHAT_ENABLE_AI_TELEMETRY: {{ $chatTelemetryEnabled | quote }}
1116
{{- if .Values.chat.modelRegistry }}
1217
CHAT_MODEL_REGISTRY_JSON: {{ .Values.chat.modelRegistry | toJson | quote }}
1318
{{- end }}

deploy/charts/klicker-uzh-v3/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ chat:
170170
baseUrl: ''
171171
storeResponses: false
172172

173+
telemetry:
174+
enabled: true
175+
173176
mcp:
174177
key: ''
175178

deploy/env-uzh-stg/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ chat:
165165
baseUrl: 'http://litellm.stg-litellm.svc.cluster.local:4000/v1'
166166
storeResponses: true
167167

168+
telemetry:
169+
enabled: false
170+
168171
automaticModels:
169172
primaryId: gpt-5.1
170173
fallbackId: gpt-4.1-mini

turbo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"OPENAI_API_KEY",
8181
"OPENAI_BASE_URL",
8282
"CHAT_OPENAI_STORE_RESPONSES",
83+
"CHAT_ENABLE_AI_TELEMETRY",
8384
"UPSTREAM_OPENAI_API_KEY",
8485
"UPSTREAM_OPENAI_BASE_URL",
8586
"LANGFUSE_PUBLIC_KEY",

0 commit comments

Comments
 (0)