Skip to content
Merged
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
9 changes: 6 additions & 3 deletions js/core/src/tracing/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ export async function runInNewSpan<T>(
opts.metadata.state = 'error';
otSpan.setStatus({
code: SpanStatusCode.ERROR,
message: formatError(e),
message: getErrorMessage(e),
});
if (e instanceof Error) {
otSpan.recordException(e);
}
throw e;
} finally {
otSpan.setAttributes(metadataToAttributes(opts.metadata));
Expand All @@ -100,9 +103,9 @@ export async function runInNewSpan<T>(
);
}

function formatError(e: any): string {
function getErrorMessage(e: any): string {
if (e instanceof Error) {
return `${e.message}\n${e.stack}`;
return e.message;
}
return `${e}`;
}
Expand Down
24 changes: 10 additions & 14 deletions js/flow/src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@

import {
Action,
action,
FlowError,
FlowState,
FlowStateSchema,
FlowStateStore,
Operation,
StreamingCallback,
action,
getStreamingCallback,
config as globalConfig,
isDevEnv,
Operation,
StreamingCallback,
} from '@genkit-ai/core';
import { logger } from '@genkit-ai/core/logging';
import { registerAction } from '@genkit-ai/core/registry';
import { toJsonSchema } from '@genkit-ai/core/schema';
import {
SPAN_TYPE_ATTR,
newTrace,
setCustomMetadataAttribute,
setCustomMetadataAttributes,
SPAN_TYPE_ATTR,
} from '@genkit-ai/core/tracing';
import { SpanStatusCode } from '@opentelemetry/api';
import * as bodyParser from 'body-parser';
import { default as cors, CorsOptions } from 'cors';
import { CorsOptions, default as cors } from 'cors';
import express from 'express';
import { performance } from 'node:perf_hooks';
import * as z from 'zod';
import { Context } from './context.js';
import {
FlowExecutionError,
FlowStillRunningError,
InterruptError,
getErrorMessage,
getErrorStack,
InterruptError,
} from './errors.js';
import * as telemetry from './telemetry.js';
import {
Expand Down Expand Up @@ -464,8 +464,11 @@ export class Flow<
metadata.state = 'error';
rootSpan.setStatus({
code: SpanStatusCode.ERROR,
message: formatError(e),
message: getErrorMessage(e),
});
if (e instanceof Error) {
rootSpan.recordException(e);
}

setCustomMetadataAttribute(metadataPrefix('state'), 'error');
ctx.state.operation.done = true;
Expand Down Expand Up @@ -856,10 +859,3 @@ export function startFlowsServer(params?: {
console.log(`Flows server listening on port ${port}`);
});
}

function formatError(e: any): string {
if (e instanceof Error) {
return `${e.message}\n${e.stack}`;
}
return `${e}`;
}