fix: normalize Cloudflare HTML errors in telemetry (#1210)
Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -210,6 +210,7 @@ import {
|
|||||||
import { setErrorContext } from "./helpers/errorContext";
|
import { setErrorContext } from "./helpers/errorContext";
|
||||||
import {
|
import {
|
||||||
formatErrorDetails,
|
formatErrorDetails,
|
||||||
|
formatTelemetryErrorMessage,
|
||||||
getRetryStatusMessage,
|
getRetryStatusMessage,
|
||||||
isEncryptedContentError,
|
isEncryptedContentError,
|
||||||
} from "./helpers/errorFormatter";
|
} from "./helpers/errorFormatter";
|
||||||
@@ -362,6 +363,7 @@ function deriveReasoningEffort(
|
|||||||
)
|
)
|
||||||
return re;
|
return re;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Anthropic/Bedrock: effort field
|
// Anthropic/Bedrock: effort field
|
||||||
if (
|
if (
|
||||||
modelSettings.provider_type === "anthropic" ||
|
modelSettings.provider_type === "anthropic" ||
|
||||||
@@ -3923,7 +3925,9 @@ export default function App({
|
|||||||
// Log the conversation-busy error
|
// Log the conversation-busy error
|
||||||
telemetry.trackError(
|
telemetry.trackError(
|
||||||
"retry_conversation_busy",
|
"retry_conversation_busy",
|
||||||
errorDetail || "Conversation is busy",
|
formatTelemetryErrorMessage(
|
||||||
|
errorDetail || "Conversation is busy",
|
||||||
|
),
|
||||||
"pre_stream_retry",
|
"pre_stream_retry",
|
||||||
{
|
{
|
||||||
httpStatus:
|
httpStatus:
|
||||||
@@ -3989,7 +3993,9 @@ export default function App({
|
|||||||
// Log the error that triggered the retry
|
// Log the error that triggered the retry
|
||||||
telemetry.trackError(
|
telemetry.trackError(
|
||||||
"retry_pre_stream_transient",
|
"retry_pre_stream_transient",
|
||||||
errorDetail || "Pre-stream transient error",
|
formatTelemetryErrorMessage(
|
||||||
|
errorDetail || "Pre-stream transient error",
|
||||||
|
),
|
||||||
"pre_stream_retry",
|
"pre_stream_retry",
|
||||||
{
|
{
|
||||||
httpStatus:
|
httpStatus:
|
||||||
@@ -5234,9 +5240,11 @@ export default function App({
|
|||||||
// Log the error that triggered the retry
|
// Log the error that triggered the retry
|
||||||
telemetry.trackError(
|
telemetry.trackError(
|
||||||
"retry_post_stream_error",
|
"retry_post_stream_error",
|
||||||
detailFromRun ||
|
formatTelemetryErrorMessage(
|
||||||
fallbackError ||
|
detailFromRun ||
|
||||||
`Stream stopped: ${stopReasonToHandle}`,
|
fallbackError ||
|
||||||
|
`Stream stopped: ${stopReasonToHandle}`,
|
||||||
|
),
|
||||||
"post_stream_retry",
|
"post_stream_retry",
|
||||||
{
|
{
|
||||||
modelId: currentModelId || undefined,
|
modelId: currentModelId || undefined,
|
||||||
@@ -5366,9 +5374,10 @@ export default function App({
|
|||||||
// — skip the generic "Something went wrong?" hint
|
// — skip the generic "Something went wrong?" hint
|
||||||
appendError(errorDetails, {
|
appendError(errorDetails, {
|
||||||
...errorTelemetryBase,
|
...errorTelemetryBase,
|
||||||
errorMessage:
|
errorMessage: formatTelemetryErrorMessage(
|
||||||
serverErrorDetail ||
|
serverErrorDetail ||
|
||||||
`Stream stopped with reason: ${stopReasonToHandle}`,
|
`Stream stopped with reason: ${stopReasonToHandle}`,
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isEncryptedContentError(errorObject)) {
|
if (!isEncryptedContentError(errorObject)) {
|
||||||
|
|||||||
@@ -83,6 +83,18 @@ export function checkCloudflareEdgeError(text: string): string | undefined {
|
|||||||
return `${codeLabel}${statusSegment}${hostSegment}${raySegment}. This is usually a temporary edge/origin outage. Please retry in a moment.`;
|
return `${codeLabel}${statusSegment}${hostSegment}${raySegment}. This is usually a temporary edge/origin outage. Please retry in a moment.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize raw provider error payloads before sending to telemetry.
|
||||||
|
* Keeps telemetry concise by collapsing Cloudflare HTML pages into a
|
||||||
|
* single readable line while preserving non-Cloudflare messages as-is.
|
||||||
|
*/
|
||||||
|
export function formatTelemetryErrorMessage(
|
||||||
|
message: string | null | undefined,
|
||||||
|
): string {
|
||||||
|
if (!message) return "Unknown error";
|
||||||
|
return checkCloudflareEdgeError(message) ?? message;
|
||||||
|
}
|
||||||
|
|
||||||
function getErrorReasons(e: APIError): string[] {
|
function getErrorReasons(e: APIError): string[] {
|
||||||
const reasons = new Set<string>();
|
const reasons = new Set<string>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user