Skip to content

Commit

Permalink
fix(openai): support passing in traceName (#489)
Browse files Browse the repository at this point in the history
Co-authored-by: Selby Kendrick <[email protected]>
  • Loading branch information
hassiebp and selbyk authored Dec 16, 2024
1 parent 21f8676 commit 21ed800
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion langfuse/src/openai/observeOpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const observeOpenAI = <SDKType extends object>(

const defaultGenerationName = `${sdk.constructor?.name}.${propKey.toString()}`;
const generationName = langfuseConfig?.generationName ?? defaultGenerationName;
const config = { ...langfuseConfig, generationName };
const traceName = langfuseConfig && "traceName" in langfuseConfig ? langfuseConfig.traceName : generationName;
const config = { ...langfuseConfig, generationName, traceName };

// Add a flushAsync method to the OpenAI SDK that flushes the Langfuse client
if (propKey === "flushAsync") {
Expand Down
1 change: 1 addition & 0 deletions langfuse/src/openai/traceMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const wrapMethod = async <T extends GenericMethod>(
...config,
...observationData,
id: config?.traceId,
name: config?.traceName,
timestamp: observationData.startTime,
});
}
Expand Down
6 changes: 5 additions & 1 deletion langfuse/src/openai/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ type LangfuseGenerationConfig = Pick<
"metadata" | "version" | "promptName" | "promptVersion"
>;

export type LangfuseNewTraceConfig = LangfuseTraceConfig & { traceId?: string; clientInitParams?: LangfuseInitParams };
export type LangfuseNewTraceConfig = LangfuseTraceConfig & {
traceId?: string;
traceName?: string;
clientInitParams?: LangfuseInitParams;
};
export type LangfuseParent = LangfuseTraceClient | LangfuseSpanClient | LangfuseGenerationClient;
export type LangfuseWithParentConfig = LangfuseGenerationConfig & { parent: LangfuseParent };

Expand Down

0 comments on commit 21ed800

Please sign in to comment.