> ## Documentation Index
> Fetch the complete documentation index at: https://arize-ax.mintlify.site/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Scalekit AgentKit Tracing

> Trace Scalekit AgentKit tool calls in Arize AX with OpenTelemetry and OpenInference.

[Scalekit AgentKit](https://docs.scalekit.com/agentkit/overview/) gives agents access to tools that act on a user's connected accounts. Wrap each `executeTool` call with OpenInference's `traceTool` helper to see the tool input, result, and status in Arize AX. If the call happens while an instrumented model span is active, the tool span is nested under that model span.

## Prerequisites

* A Node.js application using Scalekit AgentKit's Node SDK
* A Scalekit Development environment, connection, and active connected account
* An Arize AX account with a Space ID and API key
* An instrumented model client if you want tool calls nested under model spans

## Install

Install OpenTelemetry and the Scalekit SDK:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
npm install @scalekit-sdk/node \
  @opentelemetry/api \
  @opentelemetry/resources \
  @opentelemetry/sdk-trace-node \
  @opentelemetry/exporter-trace-otlp-proto \
  @opentelemetry/semantic-conventions \
  @arizeai/openinference-core \
  @arizeai/openinference-semantic-conventions
```

## Configure credentials

Set the credentials in the environment where your Node application runs:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export ARIZE_SPACE_ID="<your-space-id>"
export ARIZE_API_KEY="<your-api-key>"
export ARIZE_PROJECT_NAME="scalekit-agentkit"
export SCALEKIT_ENVIRONMENT_URL="<your-development-environment-url>"
export SCALEKIT_CLIENT_ID="<your-client-id>"
export SCALEKIT_CLIENT_SECRET="<your-client-secret>"
```

## Setup tracing

Register the tracer provider before constructing your model client or running your agent. This example uses the US AX endpoint; for an EU account, replace it with `https://otlp.eu.arize.com/v1/traces`.

<CodeGroup>
  ```typescript instrumentation.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
  import { resourceFromAttributes } from "@opentelemetry/resources";
  import { NodeTracerProvider, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-node";
  import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
  import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions";
  import { ScalekitClient } from "@scalekit-sdk/node";

  const projectName = process.env.ARIZE_PROJECT_NAME ?? "scalekit-agentkit";

  export const provider = new NodeTracerProvider({
    resource: resourceFromAttributes({
      [ATTR_SERVICE_NAME]: projectName,
      [SEMRESATTRS_PROJECT_NAME]: projectName,
    }),
    spanProcessors: [
      new SimpleSpanProcessor(
        new OTLPTraceExporter({
          url: "https://otlp.arize.com/v1/traces",
          headers: {
            "arize-space-id": process.env.ARIZE_SPACE_ID ?? "",
            "arize-api-key": process.env.ARIZE_API_KEY ?? "",
          },
        }),
      ),
    ],
  });

  provider.register();

  export const scalekit = new ScalekitClient(
    process.env.SCALEKIT_ENVIRONMENT_URL!,
    process.env.SCALEKIT_CLIENT_ID!,
    process.env.SCALEKIT_CLIENT_SECRET!,
  );
  ```
</CodeGroup>

## Trace tool calls

Wrap Scalekit's `client.actions.executeTool` with `traceTool`. It creates the `TOOL` span and records the call arguments and result by default. Set the span name from `toolName`; the input also includes the connector and identifier. Discover available tool names and schemas with Scalekit's tool listing.

<CodeGroup>
  ```typescript traced-tools.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  import { traceTool } from "@arizeai/openinference-core";
  import type { ScalekitClient } from "@scalekit-sdk/node";

  type ExecuteToolParams = Parameters<ScalekitClient["actions"]["executeTool"]>[0];

  type ScalekitActions = Pick<ScalekitClient["actions"], "executeTool">;

  export function createTracedToolExecutor(actions: ScalekitActions) {
    return (params: ExecuteToolParams) =>
      traceTool(
        (toolParams: ExecuteToolParams) => actions.executeTool(toolParams),
        { name: params.toolName },
      )(params);
  }
  ```
</CodeGroup>

## Run

Call a read-only tool from your agent. Confirm the tool name and input schema in your Scalekit environment; the example below uses GitHub issue lookup.

<CodeGroup>
  ```typescript example.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
  import { scalekit } from "./instrumentation.js";
  import { createTracedToolExecutor } from "./traced-tools.js";

  const executeTool = createTracedToolExecutor(scalekit.actions);

  const result = await executeTool({
    toolName: "github_issue_get",
    connector: "github-connect",
    identifier: "test-user",
    toolInput: { owner: "octocat", repo: "Hello-World", issue_number: 1 },
  });
  console.log(result.data);
  ```
</CodeGroup>

Run the example with:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
npx tsx example.ts
```

Open the project named by `ARIZE_PROJECT_NAME` in AX. The tool span should include the connector, tool name, input, and output. When model tracing is enabled, it should appear beneath the active model or agent span.

Confirm spans are actually reaching your Arize AX project. Use whichever fits your workflow — the skill and CLI work for any framework; the SDK check is shown for each language.

<Tabs>
  <Tab title="Arize skill (agent)">
    Install the [Arize Skills](https://github.com/Arize-ai/arize-skills) plugin and let your coding agent check for you:

    ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    npx skills add Arize-ai/arize-skills
    ```

    Then prompt your agent:

    > Use the `arize-trace` skill to export and analyze recent traces from my project. Confirm spans are arriving, and summarize any errors or latency issues.
  </Tab>

  <Tab title="AX CLI">
    Export recent spans for your project — any rows mean traces are landing:

    ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
    ax spans export "$ARIZE_PROJECT_NAME" --space "$ARIZE_SPACE_ID" \
      --limit 5 --stdout | jq 'length'
    ```

    A non-zero count confirms spans reached Arize AX. Run `ax auth login` first if you have not authenticated. See the [`ax spans` reference](/docs/api-clients/cli/spans).
  </Tab>

  <Tab title="SDK">
    Query the project's spans and check that at least one came back.

    <CodeGroup>
      ```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
      import os
      from arize import ArizeClient

      client = ArizeClient(api_key=os.environ["ARIZE_API_KEY"])
      resp = client.spans.list(
          project=os.environ["ARIZE_PROJECT_NAME"],
          space=os.environ["ARIZE_SPACE_ID"],
          limit=5,
      )
      count = len(resp.spans)
      print(
          f"{count} span(s) found" if count else "No spans yet — recheck setup"
      )
      ```

      ```typescript TypeScript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
      // Reads ARIZE_API_KEY from the environment.
      import { listSpans } from "@arizeai/ax-client";

      const { data: spans } = await listSpans({
        project: process.env.ARIZE_PROJECT_NAME!,
        space: process.env.ARIZE_SPACE_ID!,
        limit: 5,
      });
      const count = spans.length;
      console.log(
        count ? `${count} span(s) found` : "No spans yet — recheck setup",
      );
      ```

      ```go Go theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
      client, err := arize.NewClient(
          arize.Config{APIKey: os.Getenv("ARIZE_API_KEY")},
      )
      if err != nil {
          log.Fatal(err)
      }
      resp, err := client.Spans.List(ctx, spans.ListRequest{
          Project: os.Getenv("ARIZE_PROJECT_NAME"),
          Space:   os.Getenv("ARIZE_SPACE_ID"),
          Limit:   5,
      })
      if err != nil {
          log.Fatal(err)
      }
      fmt.Printf("%d span(s) found\n", len(resp.Spans))
      ```
    </CodeGroup>

    SDK span references: [Python](/docs/api-clients/python/version-8/client-resources/spans) · [TypeScript](/docs/api-clients/typescript/version-1/client-resources/spans) · [Go](/docs/api-clients/go/version-2/client-resources/spans).
  </Tab>
</Tabs>

## Resources

<CardGroup>
  <Card icon="book-open" href="https://docs.scalekit.com/agentkit/reference/tools/execute-a-tool/" title="Scalekit execute a tool" horizontal />

  <Card icon="book-open" href="https://docs.scalekit.com/agentkit/connectors/" title="Scalekit connectors" horizontal />

  <Card icon="github" href="https://github.com/scalekit-developers/arize-agentkit-tracing-demo" title="Scalekit tracing demo" horizontal />
</CardGroup>
