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

# Add Tracing to Existing Apps

> Add HoneyHive tracing to your existing LLM application with just 5 lines of code

You have working LLM code and want to add observability without rewriting anything. This guide shows you how to add HoneyHive tracing with a few lines in your app's entry point or runtime setup layer, with no changes to your existing logic.

**What you need:**

* A HoneyHive API key (see below)
* Your LLM provider's API key (OpenAI, Anthropic, etc.)

Go to [**Settings > Project > API Keys**](https://app.us.honeyhive.ai/settings/project/keys) and click **Create API Key**. Copy the key from the modal - it will only be shown once.

**Time:** 5 minutes

***

## Three Steps to Add Tracing

### 1. Install HoneyHive

<CodeGroup>
  ```bash OpenAI theme={null}
  pip install "honeyhive[openinference-openai]"
  ```

  ```bash Anthropic theme={null}
  pip install "honeyhive[openinference-anthropic]"
  ```
</CodeGroup>

### 2. Add 5 Lines in Your App's Runtime Entry Point

```python theme={null}
from honeyhive import HoneyHiveTracer # [!code ++]
from openinference.instrumentation.openai import OpenAIInstrumentor # [!code ++]
# [!code ++]
tracer = HoneyHiveTracer.init(api_key="your-key", project="your-project") # [!code ++]
instrumentor = OpenAIInstrumentor() # [!code ++]
instrumentor.instrument(tracer_provider=tracer.provider) # [!code ++]

# Your existing code below stays exactly the same
```

<Note>
  Keep the order the same in every runtime: initialize `HoneyHiveTracer` first, then initialize instrumentors with `tracer.provider`.
</Note>

For the full runtime-specific patterns, see [Tracer Initialization](/v2/tracing/tracer-initialization).

### 3. Run Your App

```bash theme={null}
export HH_API_KEY="your-honeyhive-key"
export OPENAI_API_KEY="your-openai-key"
python your_app.py
```

View traces at [app.us.honeyhive.ai](https://app.us.honeyhive.ai) → your project → Traces.

***

## Integration Examples

### Example 1: Simple Chatbot

```python theme={null}
# ========== ADD THESE 5 LINES ========== # [!code ++:6]
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.openai import OpenAIInstrumentor

tracer = HoneyHiveTracer.init(api_key="your-key", project="chatbot")
instrumentor = OpenAIInstrumentor()
instrumentor.instrument(tracer_provider=tracer.provider)
# ========== YOUR EXISTING CODE (NO CHANGES) ==========

import openai

client = openai.OpenAI()

def chat(message):
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": message}]
    )
    return response.choices[0].message.content

if __name__ == "__main__":
    result = chat("Hello, how are you?")
    print(result)
```

That's it - a small runtime setup block, zero changes to your existing functions.

### Example 2: Multi-Step Application

```python theme={null}
# ========== ADD THESE 5 LINES ========== # [!code ++:6]
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.anthropic import AnthropicInstrumentor

tracer = HoneyHiveTracer.init(api_key="your-key", project="my-app")
instrumentor = AnthropicInstrumentor()
instrumentor.instrument(tracer_provider=tracer.provider)
# ========== YOUR EXISTING CODE (NO CHANGES) ==========

import anthropic

def summarize_text(text):
    client = anthropic.Anthropic()
    response = client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=500,
        messages=[{"role": "user", "content": f"Summarize: {text}"}]
    )
    return response.content[0].text

def generate_questions(summary):
    client = anthropic.Anthropic()
    response = client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=300,
        messages=[{"role": "user", "content": f"Generate 3 questions: {summary}"}]
    )
    return response.content[0].text

if __name__ == "__main__":
    summary = summarize_text("Long article text here...")
    questions = generate_questions(summary)
    print(questions)
```

Both LLM calls are traced automatically. You'll see the complete chain in HoneyHive.

***

## Use Environment Variables (Recommended)

For production, use environment variables instead of hardcoding keys:

```python theme={null}
from honeyhive import HoneyHiveTracer 
from openinference.instrumentation.openai import OpenAIInstrumentor 

# Reads HH_API_KEY and HH_PROJECT from environment 
tracer = HoneyHiveTracer.init() 
instrumentor = OpenAIInstrumentor() 
instrumentor.instrument(tracer_provider=tracer.provider) 
```

Set these environment variables:

```bash theme={null}
export HH_API_KEY="your-honeyhive-key"
export HH_PROJECT="production-app"
export OPENAI_API_KEY="your-openai-key"
```

***

## What Gets Traced?

All LLM SDK calls are traced automatically, including:

* Chat completions, embeddings, and streaming
* Function/tool calling
* Multi-turn conversations

Each trace captures model, prompts, responses, tokens, latency, and costs.

See integration guides for details: [OpenAI](/v2/integrations/openai) • [Anthropic](/v2/integrations/anthropic) • [More providers](/v2/integrations/openai)

***

## Multiple Providers

Using OpenAI and Anthropic in the same app? Initialize both instrumentors with the same tracer:

```python theme={null}
from honeyhive import HoneyHiveTracer 
from openinference.instrumentation.openai import OpenAIInstrumentor 
from openinference.instrumentation.anthropic import AnthropicInstrumentor 

tracer = HoneyHiveTracer.init(api_key="your-key", project="my-app") 

OpenAIInstrumentor().instrument(tracer_provider=tracer.provider) 
AnthropicInstrumentor().instrument(tracer_provider=tracer.provider) 

# Both providers now traced
```

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="Traces not appearing">
    * Check `HH_API_KEY` is set correctly
    * Verify project name matches between code and dashboard
    * Wait 2-3 seconds for processing
    * Look for errors in console output
  </Accordion>

  <Accordion title="Import errors">
    Install with the extras for your provider:

    ```bash theme={null}
    pip install "honeyhive[openinference-openai]"
    ```
  </Accordion>

  <Accordion title="Multiple files in my app - where do I add the tracing setup?">
    Add it in the entry point or runtime setup layer where your app boots. For scripts, that is often `main.py` or `app.py`. For Lambda, use cached setup outside the handler. For FastAPI, Flask, or Django, initialize once at app startup and create a session per request. See [Tracer Initialization](/v2/tracing/tracer-initialization) for the runtime-specific patterns.
  </Accordion>
</AccordionGroup>

For more help, see [Troubleshooting Guide](/v2/introduction/troubleshooting) or [join our Discord](https://discord.gg/vqctGpqA97).

***

## What's Next?

<CardGroup cols={2}>
  <Card title="Enrich Your Traces" icon="sparkles" href="/v2/tutorials/enriching-traces">
    Add metadata, user feedback, and custom evaluations
  </Card>

  <Card title="Production Best Practices" icon="rocket" href="/v2/tutorials/production-deployment">
    Deploy tracing to production with proper configuration
  </Card>
</CardGroup>
