Skip to content

Commit 2d8bc3f

Browse files
authored
Merge pull request #25 from comet-ml/vincentkoc-code/opik-created-from
Add created_from metadata to OpenClaw traces
2 parents a85b33c + 94a1d06 commit 2d8bc3f

4 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/service.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ describe("opik service", () => {
291291
threadId: "session-1",
292292
input: expect.objectContaining({ prompt: "Hello", systemPrompt: "You are helpful" }),
293293
metadata: expect.objectContaining({
294+
created_from: "openclaw",
294295
provider: "openai",
295296
model: "gpt-4",
296297
channel: "telegram",
@@ -1571,6 +1572,7 @@ describe("opik service", () => {
15711572

15721573
expect(metadata.model).toBe("gpt-4");
15731574
expect(metadata.provider).toBe("openai");
1575+
expect(metadata.created_from).toBe("openclaw");
15741576
expect(metadata.channel).toBe("discord");
15751577
expect(metadata.channelId).toBe("discord");
15761578
expect(metadata.trigger).toBe("cron");

src/service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
DEFAULT_STALE_SWEEP_INTERVAL_MS,
1818
DEFAULT_STALE_TRACE_TIMEOUT_MS,
1919
MAX_FLUSH_RETRY_DELAY_MS,
20+
OPIK_CREATED_FROM,
2021
OPIK_PLUGIN_ID,
2122
} from "./service/constants.js";
2223
import {
@@ -258,6 +259,7 @@ export function createOpikService(
258259

259260
const agentEnd = active.agentEnd;
260261
const metadata: Record<string, unknown> = {
262+
created_from: OPIK_CREATED_FROM,
261263
...active.costMeta,
262264
success: agentEnd?.success,
263265
durationMs: agentEnd?.durationMs,

src/service/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const DEFAULT_FLUSH_RETRY_COUNT = 2;
44
export const DEFAULT_FLUSH_RETRY_BASE_DELAY_MS = 250;
55
export const MAX_FLUSH_RETRY_DELAY_MS = 5000;
66
export const OPIK_PLUGIN_ID = "opik-openclaw";
7+
export const OPIK_CREATED_FROM = "openclaw";
78

89
export const LOCAL_ATTACHMENT_UPLOAD_MAGIC_ID = "BEMinIO";
910
export const ATTACHMENT_UPLOAD_PART_SIZE_BYTES = 8 * 1024 * 1024;

src/service/hooks/llm.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
22
import type { Opik, Span, Trace } from "opik";
33
import type { ActiveTrace } from "../../types.js";
4+
import { OPIK_CREATED_FROM } from "../constants.js";
45
import {
56
mapUsageToOpikTokens,
67
normalizeProvider,
@@ -63,6 +64,7 @@ export function registerLlmHooks(deps: LlmHooksDeps): void {
6364
threadId: sessionKey,
6465
input: sanitizedTraceInput,
6566
metadata: {
67+
created_from: OPIK_CREATED_FROM,
6668
provider: normalizedProvider,
6769
model: event.model,
6870
sessionId: event.sessionId,

0 commit comments

Comments
 (0)