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

get_spans_by_ids

Retrieve complete span details including payloads using span IDs from earlier queries, enabling in-depth analysis of specific requests or traces.

Instructions

Fetch specific span recordings by their IDs.

Use this tool when you have span IDs from a previous query and need the full details including payloads.

This is useful for:

  • Getting full details for spans found via query_spans

  • Examining specific requests in detail

  • Comparing multiple specific spans

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
observableServiceIdNoService ID to query (required if multiple services available)
idsYesSpan recording IDs to fetch
fieldsNoSpecific fields to return
includePayloadsNoInclude inputValue/outputValue
maxPayloadLengthNoTruncate payload strings

Implementation Reference

  • The main handler function handleGetSpansByIds that processes the tool request: parses input, calls the API client, formats results into markdown text with span details, and returns them as text content.
    export async function handleGetSpansByIds(
      client: TuskDriftApiClient,
      args: Record<string, unknown>
    ): Promise<{ content: Array<{ type: "text"; text: string }> }> {
      const input = parseGetSpansByIdsInput(args);
      const result = await client.getSpansByIds(input);
    
      if (result.spans.length === 0) {
        return {
          content: [
            {
              type: "text",
              text: `No spans found for the provided IDs.`,
            },
          ],
        };
      }
    
      const spansText = result.spans
        .map((span, i) => {
          const lines = [
            `## Span ${i + 1}: ${span.name}`,
            `- **ID:** ${span.id}`,
            `- **Trace ID:** ${span.traceId}`,
            `- **Span ID:** ${span.spanId}`,
            `- **Package:** ${span.packageName}`,
            `- **Duration:** ${span.duration.toFixed(2)}ms`,
            `- **Status:** ${span.status.code === 0 ? "OK" : span.status.code === 1 ? "UNSET" : "ERROR"}`,
            `- **Timestamp:** ${span.timestamp}`,
            `- **Root Span:** ${span.isRootSpan ? "Yes" : "No"}`,
          ];
    
          if (span.inputValue) {
            lines.push(`\n**Input:**\n\`\`\`json\n${JSON.stringify(span.inputValue, null, 2)}\n\`\`\``);
          }
    
          if (span.outputValue) {
            lines.push(`\n**Output:**\n\`\`\`json\n${JSON.stringify(span.outputValue, null, 2)}\n\`\`\``);
          }
    
          return lines.join("\n");
        })
        .join("\n\n---\n\n");
    
      return {
        content: [
          {
            type: "text",
            text: `Found ${result.spans.length} spans:\n\n${spansText}`,
          },
        ],
      };
    }
  • Tool definition object with name 'get_spans_by_ids', description, and inputSchema defining the Zod validation schema for parameters (observableServiceId, ids, fields, includePayloads, maxPayloadLength).
    export const getSpansByIdsTool: Tool = {
      name: "get_spans_by_ids",
      description: `Fetch specific span recordings by their IDs.
    
    Use this tool when you have span IDs from a previous query and need the full details including payloads.
    
    This is useful for:
    - Getting full details for spans found via query_spans
    - Examining specific requests in detail
    - Comparing multiple specific spans`,
      inputSchema: {
        type: "object",
        properties: {
          observableServiceId: {
            type: "string",
            description: "Service ID to query. Required if multiple services are available.",
          },
          ids: {
            type: "array",
            items: { type: "string" },
            description: "Span recording IDs to fetch (max 20)",
          },
          fields: {
            type: "array",
            items: {
              type: "string",
              enum: [...selectableSpanFieldCodec.names],
            },
            description: "Optional list of fields to return",
          },
          includePayloads: {
            type: "boolean",
            description: "Include full inputValue/outputValue",
            default: true,
          },
          maxPayloadLength: {
            type: "number",
            description: "Truncate payload strings to this length",
            default: 500,
          },
        },
        required: ["ids"],
      },
    };
  • Zod schema getSpansByIdsInputSchema defining validation for the tool's input parameters.
    export const getSpansByIdsInputSchema = z.object({
      observableServiceId: z.string().optional().describe("Service ID to query (required if multiple services available)"),
      ids: z.array(z.string()).min(1).max(20).describe("Span recording IDs to fetch"),
      fields: z.array(enumNameSchema(selectableSpanFieldCodec)).optional().describe("Specific fields to return"),
      includePayloads: z.boolean().default(true).describe("Include inputValue/outputValue"),
      maxPayloadLength: z.number().min(0).default(500).describe("Truncate payload strings"),
    });
  • parseGetSpansByIdsInput function that parses raw args through the Zod schema and creates a SharedGetSpansByIdsRequest protobuf message.
    export function parseGetSpansByIdsInput(args: Record<string, unknown>): GetSpansByIdsInput {
      const input: GetSpansByIdsArgs = getSpansByIdsInputSchema.parse(args);
      return SharedGetSpansByIdsRequest.create({
        observableServiceId: input.observableServiceId ?? "",
        ids: input.ids,
        fields: (input.fields ?? []).map((field) => selectableSpanFieldCodec.byName[field]),
        includePayloads: input.includePayloads,
        maxPayloadLength: input.maxPayloadLength,
      });
    }
  • src/server.ts:466-543 (registration)
    Server-side registration of the tool via server.registerTool(...) with the name 'get_spans_by_ids', input schema, and an async handler with access control check and error handling.
      // ============================================
      // Tool: get_spans_by_ids
      // ============================================
      server.registerTool(
        "get_spans_by_ids",
        {
          description: `Fetch specific span recordings by their IDs.
    
    Use this tool when you have span IDs from a previous query and need the full details including payloads.
    
    This is useful for:
    - Getting full details for spans found via query_spans
    - Examining specific requests in detail
    - Comparing multiple specific spans`,
          inputSchema: getSpansByIdsInputSchema.shape,
        },
        async (args) => {
          const input = parseGetSpansByIdsInput(args);
    
          if (input.observableServiceId && !(await checkAccess(input.observableServiceId))) {
            return {
              content: [{ type: "text" as const, text: "Error: Access denied to observable service" }],
              isError: true,
            };
          }
    
          try {
            const result = await provider.getSpansByIds(input);
    
            if (result.spans.length === 0) {
              return {
                content: [{ type: "text" as const, text: "No spans found for the provided IDs." }],
              };
            }
    
            const spansText = result.spans
              .map((span, i) => {
                const lines = [
                  `## Span ${i + 1}: ${span.name}`,
                  `- **ID:** ${span.id}`,
                  `- **Trace ID:** ${span.traceId}`,
                  `- **Span ID:** ${span.spanId}`,
                  `- **Package:** ${span.packageName}`,
                  `- **Duration:** ${span.duration?.toFixed(2) ?? "N/A"}ms`,
                  `- **Status:** ${span.status?.code === 0 ? "OK" : span.status?.code === 1 ? "UNSET" : "ERROR"}`,
                  `- **Timestamp:** ${span.timestamp}`,
                  `- **Root Span:** ${span.isRootSpan ? "Yes" : "No"}`,
                ];
    
                if (span.inputValue) {
                  lines.push(
                    `\n**Input:**\n\`\`\`json\n${JSON.stringify(span.inputValue, null, 2)}\n\`\`\``
                  );
                }
    
                if (span.outputValue) {
                  lines.push(
                    `\n**Output:**\n\`\`\`json\n${JSON.stringify(span.outputValue, null, 2)}\n\`\`\``
                  );
                }
    
                return lines.join("\n");
              })
              .join("\n\n---\n\n");
    
            return {
              content: [
                { type: "text" as const, text: `Found ${result.spans.length} spans:\n\n${spansText}` },
              ],
            };
          } catch (error) {
            return {
              content: [{ type: "text" as const, text: `Error executing get_spans_by_ids: ${error}` }],
              isError: true,
            };
          }
        }
      );
Behavior3/5

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

No annotations provided, so description must bear full burden. It indicates fetching includes payloads, but does not disclose any side effects, permissions, or rate limits. For a read-only tool, this is acceptable but not comprehensive.

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?

Extremely concise: two sentences plus a bulleted list. No filler, all sentences are informative and front-loaded.

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

Completeness3/5

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

No output schema, so description should compensate for return value details. It mentions 'full details including payloads' but not the structure or default fields. Adequate for a straightforward fetch tool but leaves some ambiguity.

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 coverage is 100% with good parameter descriptions. The description adds context about 'full details including payloads' which complements the 'includePayloads' parameter, but does not significantly extend parameter understanding beyond the schema.

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?

Clear verb-resource combination ('Fetch specific span recordings by their IDs') and distinguishes from sibling tool 'query_spans' by emphasizing retrieval via known IDs rather than searching.

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?

Explicitly states when to use ('when you have span IDs from a previous query') and lists concrete use cases, providing clear guidance for tool selection.

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