Skip to main content
Glama

Log Trace

log_trace

Log agent execution traces with spans, tool calls, latency, and metrics for observability and evaluation in AI workflows.

Instructions

Log an agent execution trace with spans, tool calls, and metrics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_nameYesName of the agent
frameworkNoAgent framework name
inputNoAgent input text
outputNoAgent output text
tool_callsNoTool calls made during execution
latency_msNoTotal execution time in milliseconds
token_usageNoToken usage breakdown
cost_usdNoTotal cost in USD
metadataNoArbitrary metadata
spansNoDetailed execution spans
timestampNoTrace timestamp (ISO 8601)

Implementation Reference

  • The handler function for the log_trace tool which processes the input arguments, generates identifiers, constructs the trace object, and stores it using the provided storage adapter.
    async (args) => {
      const traceId = generateTraceId();
      const timestamp = args.timestamp ?? new Date().toISOString();
    
      const trace = {
        trace_id: traceId,
        agent_name: args.agent_name,
        framework: args.framework,
        input: args.input,
        output: args.output,
        tool_calls: args.tool_calls,
        latency_ms: args.latency_ms,
        token_usage: args.token_usage,
        cost_usd: args.cost_usd,
        metadata: args.metadata as Record<string, unknown> | undefined,
        timestamp,
        spans: args.spans?.map((s) => ({
          ...s,
          span_id: s.span_id ?? generateSpanId(),
          trace_id: traceId,
        })),
      };
    
      await storage.insertTrace(trace);
    
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify({ trace_id: traceId, status: 'stored' }),
          },
        ],
      };
    },
  • Zod-based input schema definition for the log_trace tool.
    const inputSchema = {
      agent_name: z.string().describe('Name of the agent'),
      framework: z.string().optional().describe('Agent framework name'),
      input: z.string().optional().describe('Agent input text'),
      output: z.string().optional().describe('Agent output text'),
      tool_calls: z.array(ToolCallSchema).optional().describe('Tool calls made during execution'),
      latency_ms: z.number().optional().describe('Total execution time in milliseconds'),
      token_usage: TokenUsageSchema.optional().describe('Token usage breakdown'),
      cost_usd: z.number().optional().describe('Total cost in USD'),
      metadata: z.record(z.unknown()).optional().describe('Arbitrary metadata'),
      spans: z.array(SpanSchema).optional().describe('Detailed execution spans'),
      timestamp: z.string().optional().describe('Trace timestamp (ISO 8601)'),
    };
  • Registration function that binds the log_trace tool to the McpServer instance.
    export function registerLogTraceTool(server: McpServer, storage: IStorageAdapter): void {
      server.registerTool(
        'log_trace',
        {
          title: 'Log Trace',
          description: 'Log an agent execution trace with spans, tool calls, and metrics',
          inputSchema,
        },
        async (args) => {
          const traceId = generateTraceId();
          const timestamp = args.timestamp ?? new Date().toISOString();
    
          const trace = {
            trace_id: traceId,
            agent_name: args.agent_name,
            framework: args.framework,
            input: args.input,
            output: args.output,
            tool_calls: args.tool_calls,
            latency_ms: args.latency_ms,
            token_usage: args.token_usage,
            cost_usd: args.cost_usd,
            metadata: args.metadata as Record<string, unknown> | undefined,
            timestamp,
            spans: args.spans?.map((s) => ({
              ...s,
              span_id: s.span_id ?? generateSpanId(),
              trace_id: traceId,
            })),
          };
    
          await storage.insertTrace(trace);
    
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({ trace_id: traceId, status: 'stored' }),
              },
            ],
          };
        },
      );
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/iris-eval/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server