Skip to main content
Glama
Use-Tusk
by Use-Tusk

get_trace

Retrieve hierarchical tree of spans in distributed traces to debug requests end-to-end, analyze call chains, and identify performance bottlenecks.

Instructions

Get all spans in a distributed trace as a hierarchical tree.

Use this tool to:

  • Debug a specific request end-to-end

  • See the full call chain from HTTP request to database queries

  • Understand timing and dependencies between spans

  • Identify bottlenecks in a request

First use query_spans to find spans, then use the traceId to get the full trace.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
observableServiceIdNoService ID to query (required if multiple services available)
traceIdYesTrace ID to fetch
includePayloadsNoInclude inputValue/outputValue
maxPayloadLengthNoTruncate payload strings

Implementation Reference

  • The handler function that implements the core logic of the 'get_trace' tool. It validates input using Zod schema, calls the API client to fetch the trace, handles no-trace cases, formats the trace tree using a helper function, and returns structured text content for MCP.
    export async function handleGetTrace(
      client: TuskDriftApiClient,
      args: Record<string, unknown>
    ): Promise<{ content: Array<{ type: "text"; text: string }> }> {
      const input = getTraceInputSchema.parse(args) as GetTraceInput;
      const result = await client.getTrace(input);
    
      if (!result.traceTree) {
        return {
          content: [
            {
              type: "text",
              text: `No trace found for ID: ${input.traceId}`,
            },
          ],
        };
      }
    
      const header = `Trace: ${input.traceId}\nSpan Count: ${result.spanCount}\n\nTrace Tree:\n`;
      const tree = formatTraceTree(result.traceTree, 0, input.includePayloads ?? false);
    
      return {
        content: [
          {
            type: "text",
            text: header + tree,
          },
        ],
      };
    }
  • Zod schema for validating the input parameters of the 'get_trace' tool, used in the handler for parsing arguments.
    export const getTraceInputSchema = z.object({
      observableServiceId: z.string().optional().describe("Service ID to query (required if multiple services available)"),
      traceId: z.string().describe("Trace ID to fetch"),
      includePayloads: z.boolean().default(false).describe("Include inputValue/outputValue"),
      maxPayloadLength: z.number().min(0).default(500).describe("Truncate payload strings"),
    });
  • Registration of the 'get_trace' handler in the central toolHandlers map, which is used by the MCP server to dispatch tool calls.
    export const toolHandlers: Record<string, ToolHandler> = {
      query_spans: handleQuerySpans,
      get_schema: handleGetSchema,
      list_distinct_values: handleListDistinctValues,
      aggregate_spans: handleAggregateSpans,
      get_trace: handleGetTrace,
      get_spans_by_ids: handleGetSpansByIds,
    };
  • The 'getTraceTool' is included in the exported tools array, providing the tool metadata (name, description, inputSchema) for MCP server registration.
    export const tools: Tool[] = [
      querySpansTool,
      getSchemaTool,
      listDistinctValuesTool,
      aggregateSpansTool,
      getTraceTool,
      getSpansByIdsTool,
    ];
  • Helper function to recursively format the trace spans as a hierarchical indented tree string with status icons, durations, IDs, and optional payloads.
    function formatTraceTree(span: TraceSpan, indent: number = 0, includePayloads: boolean): string {
      const prefix = "  ".repeat(indent);
      const statusIcon = span.status.code === 0 ? "✓" : span.status.code === 2 ? "✗" : "○";
    
      let result = `${prefix}${statusIcon} ${span.name} (${span.duration.toFixed(2)}ms) [${span.packageName}]\n`;
      result += `${prefix}   ID: ${span.spanId}\n`;
    
      if (includePayloads && span.inputValue) {
        const inputStr = JSON.stringify(span.inputValue, null, 2).split("\n").join(`\n${prefix}   `);
        result += `${prefix}   Input: ${inputStr}\n`;
      }
    
      if (includePayloads && span.outputValue) {
        const outputStr = JSON.stringify(span.outputValue, null, 2).split("\n").join(`\n${prefix}   `);
        result += `${prefix}   Output: ${outputStr}\n`;
      }
    
      if (span.children && span.children.length > 0) {
        for (const child of span.children) {
          result += formatTraceTree(child, indent + 1, includePayloads);
        }
      }
    
      return result;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It explains the hierarchical tree output structure and the tool's role in debugging workflows, but doesn't mention performance characteristics (e.g., response time, size limits), error conditions, or authentication requirements. The description adds useful context about the tool's purpose but lacks operational details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by bullet points for use cases and a clear workflow instruction. Every sentence adds value with no redundancy or wasted words. The two-sentence workflow guidance is particularly efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, hierarchical output) and lack of both annotations and output schema, the description does well by explaining the tree structure output and debugging context. However, it could be more complete by mentioning what the hierarchical tree actually contains (span relationships, timing data) or sample use cases beyond the bullet points. The absence of output schema means the description should ideally cover return values more explicitly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents all parameters. The description doesn't add any parameter-specific information beyond what's in the schema (e.g., it doesn't explain traceId format or observableServiceId selection logic). This meets the baseline expectation when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('get all spans', 'as a hierarchical tree') and distinguishes it from siblings by specifying it's for retrieving full traces rather than querying spans (query_spans) or getting specific spans by IDs (get_spans_by_ids). The title 'null' doesn't affect this assessment since the description carries the full burden.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('Debug a specific request end-to-end', 'See the full call chain', etc.) and when not to use it ('First use query_spans to find spans, then use the traceId to get the full trace'), clearly differentiating it from the query_spans sibling tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/Use-Tusk/drift-mcp'

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