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

# Agent Tracing SDKs

> Install, configure, and structure JavaScript or Python traces for Dashboard and Agent Traces.

Create an **Agent Traces API key** under **Business profile → Developers**, then select **Connect SDK** in the app. Agent-tracing keys are distinct from Merchant API and Agent Wallet keys.

## Install and initialize

<Tabs>
  <Tab title="JavaScript">
    ```bash theme={null}
    npm install @anyway-sh/node-server-sdk
    export ANYWAY_API_KEY="<Agent Traces API key>"
    ```

    ```typescript theme={null}
    import { initialize } from "@anyway-sh/node-server-sdk";

    initialize({
      appName: "support-app",
      apiKey: process.env.ANYWAY_API_KEY,
      baseUrl: "https://collector.anyway.sh",
    });
    ```
  </Tab>

  <Tab title="Python">
    ```bash theme={null}
    pip install anyway-sdk
    export ANYWAY_API_KEY="<Agent Traces API key>"
    ```

    ```python theme={null}
    import os
    from anyway.sdk import Traceloop

    Traceloop.init(
        app_name="support-app",
        api_key=os.environ["ANYWAY_API_KEY"],
        api_endpoint="https://collector.anyway.sh",
    )
    ```
  </Tab>
</Tabs>

The HTTPS collector uses OTLP/HTTP. A custom endpoint without `http://` or `https://` is treated as gRPC by the Python SDK.

## Environment configuration

| Variable | Meaning |
| - | - |
| `ANYWAY_API_KEY` | Agent Traces API key |
| `ANYWAY_BASE_URL` | Collector endpoint; defaults to `https://collector.anyway.sh` |
| `ANYWAY_HEADERS` | Optional exporter headers when using custom authentication |
| `ANYWAY_TRACE_CONTENT` | Control JavaScript prompt and completion capture |
| `TRACELOOP_TRACE_CONTENT` | Control Python prompt and completion capture |

Prefer `apiKey` / `api_key` over constructing an `Authorization` header yourself. When custom headers are required, send the collector key as `Authorization: Bearer <key>`.

## JavaScript tracing

Use function wrappers for explicit trace hierarchy:

```typescript theme={null}
import {
  withWorkflow,
  withAgent,
  withTask,
  withTool,
} from "@anyway-sh/node-server-sdk";

await withWorkflow(
  {
    name: "support-reply",
    associationProperties: {
      userId: "usr_opaque",
      sessionId: "session_opaque",
    },
  },
  async () =>
    withAgent({ name: "support-agent" }, async () =>
      withTask({ name: "draft" }, async () =>
        withTool({ name: "knowledge-search" }, async () => {
          // Call the tool here.
        }),
      ),
    ),
);
```

TypeScript class decorators are also supported:

```typescript theme={null}
import { workflow, task } from "@anyway-sh/node-server-sdk";

class SupportFlow {
  @workflow({ name: "reply" })
  async reply() {
    return this.draft();
  }

  @task({ name: "draft" })
  async draft() {
    return "response";
  }
}
```

### ESM and Next.js

Require-based automatic instrumentation cannot see normal ESM imports. Pass imported provider modules explicitly:

```typescript theme={null}
import { initialize } from "@anyway-sh/node-server-sdk";
import OpenAI from "openai";

initialize({
  appName: "next-app",
  apiKey: process.env.ANYWAY_API_KEY,
  instrumentModules: { openAI: OpenAI },
});
```

`instrumentModules` supports the providers exposed by the installed SDK, including OpenAI, Anthropic, Cohere, Bedrock, Google Vertex AI, Pinecone, Together, LangChain, LlamaIndex, ChromaDB, Qdrant, and MCP.

## Python tracing

Decorators support synchronous and asynchronous functions:

```python theme={null}
from anyway.sdk.decorators import workflow, task

@workflow(name="support_reply")
async def reply():
    return await draft()

@task(name="draft")
async def draft():
    # Call the model or tool here.
    return "response"
```

Keep decorators on the application boundary that has a useful business name. Provider instrumentation records nested model calls, token use, and supported tool or streaming behavior.

## Configuration reference

| Capability | JavaScript | Python |
| - | - | - |
| Application name | `appName` | `app_name` |
| API key | `apiKey` | `api_key` |
| Collector | `baseUrl` | `api_endpoint` |
| Disable batching | `disableBatch` | `disable_batch` |
| Custom exporter | `exporter` | `exporter` |
| Custom span processor | `processor` | `processor` |
| Content tracing | `traceContent` | environment/instrument controls |
| Custom pricing | `pricingJsonPath` | `pricing_json_path` |
| Disable pricing | `pricingEnabled: false` | `pricing_enabled=False` |

Both SDKs can export through custom OpenTelemetry exporters and processors. JavaScript additionally exposes conversation tracking, association properties, explicit provider modules, batching controls, and custom model pricing. Python additionally accepts samplers, resource attributes, instrument allow/block sets, and span post-processing.

## Custom exporter

If your organization already operates an OpenTelemetry pipeline, pass its exporter instead of the Anyway collector exporter. Authentication and delivery then follow that exporter and collector configuration; Dashboard only receives spans that ultimately reach Anyway's collector.

## Data safety

* Keep the Agent Traces API key in environment or secret storage.
* Decide whether prompt and completion content may be captured before production.
* Never record payment credentials, Agent Wallet Keys, identity documents, or payout details.
* Use stable pseudonymous IDs in association properties instead of customer email or legal identity.
* Apply redaction before values enter SDK attributes or model/tool spans.

<Warning>
  Disabling prompt capture in your own spans does not automatically redact arguments recorded by third-party provider instrumentation. Test the emitted trace payload with non-sensitive data before enabling production export.
</Warning>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.