---
updatedAt: 2026-05-19T06:45:49.000Z
agentTools:
  projectIndex: https://docs.arthur.ai/llms.txt
---

# Connect Your Application

# Connect Your Application to Arthur

This page covers everything you need to instrument a real application with Arthur. If you haven't yet deployed the engine and sent your first trace, start with the [Quickstart →](https://docs.arthur.ai/docs/quickstart-eval).

## Install the SDK

Install `arthur-observability-sdk` with the extra for your LLM framework:

```python Python SDK
# OpenAI
pip install "arthur-observability-sdk[openai]"

# Anthropic
pip install "arthur-observability-sdk[anthropic]"

# LangChain
pip install "arthur-observability-sdk[langchain]"

# LiteLLM
pip install "arthur-observability-sdk[litellm]"

# Install all extras at once
pip install "arthur-observability-sdk[all]"
```
```javascript JavaScript
# Mastra users: install the Arthur exporter
npm install @mastra/arthur
```

***

## Initialize Arthur

Create a single `Arthur` instance at application startup. You need your **API key** and **task ID** from the engine UI.

```python Python SDK
from arthur_observability_sdk import Arthur

arthur = Arthur(
    api_key="YOUR_API_KEY",      # or set ARTHUR_API_KEY env var
    base_url="YOUR_ENGINE_URL",  # or set ARTHUR_BASE_URL env var
    task_id="YOUR_TASK_ID",      # must be provided explicitly
)
```
```javascript JavaScript
import { ArthurExporter } from '@mastra/arthur';
import { Mastra } from '@mastra/core/mastra';

const mastra = new Mastra({
  observability: {
    configs: {
      arthur: {
        exporters: [
          new ArthurExporter({
            apiKey: process.env.ARTHUR_API_KEY,
            endpoint: process.env.ARTHUR_BASE_URL,
            taskId: process.env.ARTHUR_TASK_ID,
          }),
        ],
      },
    },
  },
});
```

***

## Supported Frameworks

Call the relevant `instrument_*` method once after constructing `Arthur`. Every subsequent call to that framework is automatically captured as a trace.

```python Python SDK
arthur.instrument_openai()           # OpenAI
arthur.instrument_anthropic()        # Anthropic
arthur.instrument_langchain()        # LangChain
arthur.instrument_litellm()          # LiteLLM
arthur.instrument_crewai()           # CrewAI
arthur.instrument_openai_agents()    # OpenAI Agents SDK
arthur.instrument_llama_index()      # LlamaIndex
arthur.instrument_google_adk()       # Google ADK
arthur.instrument_bedrock()          # AWS Bedrock
arthur.instrument_mistralai()        # Mistral AI
arthur.instrument_groq()             # Groq
arthur.instrument_vertexai()         # Vertex AI
# ...and more — see [Integrations Overview →](https://docs.arthur.ai/docs/integrations-overview)
```

Each method requires the matching extra to be installed (e.g. `pip install "arthur-observability-sdk[langchain]"`). If the extra is missing, the method raises an `ImportError` with the install command.

***

## Session and User Context

Tag spans with session and user identifiers to group traces by conversation or user in the Arthur UI.

### As a context manager

```python Python SDK
with arthur.session("session-abc-123"):
    response = openai_client.chat.completions.create(...)

with arthur.user("user-42"):
    response = openai_client.chat.completions.create(...)

# Combine both
with arthur.attributes(session_id="session-abc-123", user_id="user-42"):
    response = openai_client.chat.completions.create(...)
```
```javascript JavaScript
// @mastra/arthur does not have a session/user context API.
// You can attach tags to a root span via tracingOptions:
const result = await agent.generate('Hello', {
  tracingOptions: { tags: ['production', 'experiment-v2'] }
});
```

### As a decorator

```python Python SDK
@arthur.attributes(session_id="session-abc-123", user_id="user-42")
def handle_request(messages):
    return openai_client.chat.completions.create(messages=messages, ...)
```

`arthur.attributes()` accepts the full set of OpenInference context attributes: `session_id`, `user_id`, `metadata`, `tags`, `prompt_template`, `prompt_template_version`, `prompt_template_variables`.

***

## Shutdown

Call `arthur.shutdown()` before your process exits to flush all pending traces. Without this, spans buffered in the `BatchSpanProcessor` may be lost.

```python Python SDK
arthur.shutdown()
```

For long-running servers, hook into your framework's shutdown lifecycle:

```python Python SDK
import atexit
atexit.register(arthur.shutdown)
```
```javascript JavaScript
// Flush without shutting down:
await exporter.flush();

// Flush and terminate:
await exporter.shutdown();
```

***

## Next Steps

| What you want to do                        | Where to go                             |
| ------------------------------------------ | --------------------------------------- |
| Score traces automatically with LLM judges | [LLM Evaluators →](https://docs.arthur.ai/docs/llm-eval-guide)  |
| Run evaluations against production traffic | [Run Evaluations →](https://docs.arthur.ai/docs/evaluate-guide) |
| Get notified when scores drop              | [Alerts →](https://docs.arthur.ai/docs/alerts-guide)            |
| Version and manage your prompts            | [Prompts →](https://docs.arthur.ai/docs/prompts-guide)          |
| Add real-time guardrails                   | [Guardrails →](https://docs.arthur.ai/docs/guardrails-guide)    |