Koog
cetra traces Koog agents through Koog’s OpenTelemetry feature: the agent build and run, the strategy and graph nodes, each model call and each tool execution in one trace.
Install
Section titled “Install”<dependency> <groupId>ai.koog</groupId> <artifactId>koog-agents-jvm</artifactId> <version>1.3.0</version></dependency><dependency> <groupId>ai.koog</groupId> <artifactId>agents-features-opentelemetry-jvm</artifactId> <version>1.3.0</version></dependency><dependency> <groupId>io.opentelemetry</groupId> <artifactId>opentelemetry-exporter-otlp</artifactId></dependency>Import the OpenTelemetry BOM 1.61.0 in dependencyManagement: that is the version Koog’s feature is built against. The tool arguments are kotlinx-serialization classes, so the Kotlin compiler needs the kotlinx-serialization plugin; the fixture was built with Kotlin 2.3.21.
Set up
Section titled “Set up”Install the feature with a synchronous span processor and verbose content:
import ai.koog.agents.core.agent.AIAgentimport ai.koog.agents.core.tools.SimpleToolimport ai.koog.agents.core.tools.ToolRegistryimport ai.koog.agents.features.opentelemetry.feature.OpenTelemetryimport ai.koog.prompt.executor.clients.openai.OpenAIClientSettingsimport ai.koog.prompt.executor.clients.openai.OpenAILLMClientimport ai.koog.prompt.executor.clients.openai.OpenAIModelsimport ai.koog.prompt.executor.llms.MultiLLMPromptExecutorimport ai.koog.serialization.typeTokenimport io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporterimport io.opentelemetry.kotlin.tracing.export.simpleSpanProcessorimport io.opentelemetry.kotlin.tracing.export.toOtelKotlinSpanExporterimport kotlinx.coroutines.runBlockingimport kotlinx.serialization.Serializable
@Serializabledata class WeatherArgs(val city: String)
class WeatherTool : SimpleTool<WeatherArgs>( argsType = typeToken<WeatherArgs>(), name = "get_weather", description = "Get the current weather for a city",) { override suspend fun execute(args: WeatherArgs): String = "Sunny in ${args.city}, 21 C"}
fun main() = runBlocking { val client = OpenAILLMClient( apiKey = System.getenv("OPENAI_API_KEY"), settings = OpenAIClientSettings(baseUrl = "https://api.openai.com"), ) val agent = AIAgent( promptExecutor = MultiLLMPromptExecutor(client), llmModel = OpenAIModels.Chat.GPT4oMini, systemPrompt = "You are a helpful assistant.", toolRegistry = ToolRegistry { tool(WeatherTool()) }, ) { install(OpenTelemetry) { val exporter = OtlpHttpSpanExporter.builder() .setEndpoint("http://localhost:8080/v1/traces") .addHeader("Authorization", "Bearer sk-cetra-…") .build() addSpanProcessor { simpleSpanProcessor(exporter.toOtelKotlinSpanExporter()) } setVerbose(true) } } println("answer: " + agent.run("What is the weather in Lyon? Use the tool.")) agent.close()}- The exporter takes the full traces URL.
- The synchronous span processor sends each span when it ends. With the feature’s default batch processor, nothing reached cetra before the process exited in the capture runs; close the agent before your program ends.
setVerbose(true)records the content of the conversation and the tools. Without it nothing of the content is captured (see Limits).- Pass
OpenAIClientSettings(baseUrl = …), without a/v1suffix, when your provider is OpenAI-compatible and is not OpenAI itself.
What you get
Section titled “What you get”One agent run with one tool round:
- an
agentspan namedcreate_agent <session id>when the agent is built; - an
agentspan namedinvoke_agent <run id>for the run, with the system prompt as its input and output and the tool definitions; - plain spans for the strategy (
strategy single_run) and each graph node, such asnode nodeCallLLM,node nodeExecuteToolandnode nodeSendToolResult; - an
llmspan namedchat <model>for each model call, with the provideropenai, the model, the input and output messages, the token counts and the cost computed from the built-in prices; - a
toolspan namedexecute_tool <tool>, with the arguments as its input and the result as its output.
Limits
Section titled “Limits”- Without
setVerbose(true), Koog masks the content: the message values start withHIDDEN:and cetra records no input, output or system prompt. The tool call arguments, tool results and tool definitions are masked as well, and the masked text is what the tool span shows. - Koog writes the system prompt under
system_instructions, without thegen_ai.prefix, so cetra does not read it as the system instructions. It stays in the span’s attributes. - Koog capitalizes the message roles (
System,User,Assistant); cetra keeps them as written. - The span names carry Koog’s session and run ids, so they differ between runs.
- The fixture was captured with Koog 1.3.0 and OpenTelemetry Java 1.61.0.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Send OpenTelemetry: the endpoint and the headers cetra expects.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.