mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
add experimental.open_telemetry config option to enable OTEL spans (#4978)
Co-authored-by: noamzbr <noamzbr@users.noreply.github.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
parent
cfbaf81ef8
commit
864c098701
5 changed files with 18 additions and 0 deletions
|
|
@ -222,6 +222,7 @@ export namespace Agent {
|
|||
}
|
||||
|
||||
export async function generate(input: { description: string }) {
|
||||
const cfg = await Config.get()
|
||||
const defaultModel = await Provider.defaultModel()
|
||||
const model = await Provider.getModel(defaultModel.providerID, defaultModel.modelID)
|
||||
const language = await Provider.getLanguage(model)
|
||||
|
|
@ -229,6 +230,7 @@ export namespace Agent {
|
|||
system.push(PROMPT_GENERATE)
|
||||
const existing = await list()
|
||||
const result = await generateObject({
|
||||
experimental_telemetry: { isEnabled: cfg.experimental?.openTelemetry },
|
||||
temperature: 0.3,
|
||||
prompt: [
|
||||
...system.map(
|
||||
|
|
|
|||
|
|
@ -670,6 +670,10 @@ export namespace Config {
|
|||
chatMaxRetries: z.number().optional().describe("Number of retries for chat completions on failure"),
|
||||
disable_paste_summary: z.boolean().optional(),
|
||||
batch_tool: z.boolean().optional().describe("Enable the batch tool"),
|
||||
openTelemetry: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe("Enable OpenTelemetry spans for AI SDK calls (using the 'experimental_telemetry' flag)"),
|
||||
primary_tools: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import z from "zod"
|
|||
import { SessionPrompt } from "./prompt"
|
||||
import { Flag } from "../flag/flag"
|
||||
import { Token } from "../util/token"
|
||||
import { Config } from "../config/config"
|
||||
import { Log } from "../util/log"
|
||||
import { ProviderTransform } from "@/provider/transform"
|
||||
import { SessionProcessor } from "./processor"
|
||||
|
|
@ -96,6 +97,7 @@ export namespace SessionCompaction {
|
|||
abort: AbortSignal
|
||||
auto: boolean
|
||||
}) {
|
||||
const cfg = await Config.get()
|
||||
const model = await Provider.getModel(input.model.providerID, input.model.modelID)
|
||||
const language = await Provider.getLanguage(model)
|
||||
const system = [...SystemPrompt.compaction(model.providerID)]
|
||||
|
|
@ -191,6 +193,7 @@ export namespace SessionCompaction {
|
|||
},
|
||||
],
|
||||
}),
|
||||
experimental_telemetry: { isEnabled: cfg.experimental?.openTelemetry },
|
||||
})
|
||||
if (result === "continue" && input.auto) {
|
||||
const continueMsg = await Session.updateMessage({
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import { Command } from "../command"
|
|||
import { $, fileURLToPath } from "bun"
|
||||
import { ConfigMarkdown } from "../config/markdown"
|
||||
import { SessionSummary } from "./summary"
|
||||
import { Config } from "../config/config"
|
||||
import { NamedError } from "@opencode-ai/util/error"
|
||||
import { fn } from "@/util/fn"
|
||||
import { SessionProcessor } from "./processor"
|
||||
|
|
@ -433,6 +434,7 @@ export namespace SessionPrompt {
|
|||
}
|
||||
|
||||
// normal processing
|
||||
const cfg = await Config.get()
|
||||
const agent = await Agent.get(lastUser.agent)
|
||||
msgs = insertReminders({
|
||||
messages: msgs,
|
||||
|
|
@ -613,6 +615,7 @@ export namespace SessionPrompt {
|
|||
},
|
||||
],
|
||||
}),
|
||||
experimental_telemetry: { isEnabled: cfg.experimental?.openTelemetry },
|
||||
})
|
||||
if (result === "stop") break
|
||||
continue
|
||||
|
|
@ -1418,6 +1421,7 @@ export namespace SessionPrompt {
|
|||
input.history.filter((m) => m.info.role === "user" && !m.parts.every((p) => "synthetic" in p && p.synthetic))
|
||||
.length === 1
|
||||
if (!isFirst) return
|
||||
const cfg = await Config.get()
|
||||
const small =
|
||||
(await Provider.getSmallModel(input.providerID)) ?? (await Provider.getModel(input.providerID, input.modelID))
|
||||
const language = await Provider.getLanguage(small)
|
||||
|
|
@ -1464,6 +1468,7 @@ export namespace SessionPrompt {
|
|||
],
|
||||
headers: small.headers,
|
||||
model: language,
|
||||
experimental_telemetry: { isEnabled: cfg.experimental?.openTelemetry },
|
||||
})
|
||||
.then((result) => {
|
||||
if (result.text)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { Provider } from "@/provider/provider"
|
||||
import { Config } from "@/config/config"
|
||||
import { fn } from "@/util/fn"
|
||||
import z from "zod"
|
||||
import { Session } from "."
|
||||
|
|
@ -60,6 +61,7 @@ export namespace SessionSummary {
|
|||
}
|
||||
|
||||
async function summarizeMessage(input: { messageID: string; messages: MessageV2.WithParts[] }) {
|
||||
const cfg = await Config.get()
|
||||
const messages = input.messages.filter(
|
||||
(m) => m.info.id === input.messageID || (m.info.role === "assistant" && m.info.parentID === input.messageID),
|
||||
)
|
||||
|
|
@ -109,6 +111,7 @@ export namespace SessionSummary {
|
|||
],
|
||||
headers: small.headers,
|
||||
model: language,
|
||||
experimental_telemetry: { isEnabled: cfg.experimental?.openTelemetry },
|
||||
})
|
||||
log.info("title", { title: result.text })
|
||||
userMsg.summary.title = result.text
|
||||
|
|
@ -150,6 +153,7 @@ export namespace SessionSummary {
|
|||
},
|
||||
],
|
||||
headers: small.headers,
|
||||
experimental_telemetry: { isEnabled: cfg.experimental?.openTelemetry },
|
||||
}).catch(() => {})
|
||||
if (result) summary = result.text
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue