# Telemetry Provider Examples

Manual test examples for each instrumented provider against a local Latitude instance.

## Setup

1. Start your local Latitude instance at `localhost:3002`

2. Set up environment variables using one of these methods:

**Option A: Using .env file (recommended)**

```bash
# Copy the example file
cp .env.example .env

# Edit .env with your actual values
```

Then load it before running tests:

```bash
# Using dotenv
uv run --env-file examples/.env python examples/test_openai.py

# Or source it manually
set -a && source examples/.env && set +a
uv run python examples/test_openai.py
```

**Option B: Export in shell**

```bash
export LATITUDE_API_KEY="your-latitude-api-key"
export LATITUDE_PROJECT_SLUG="your-project-slug"

# Provider-specific API keys (set the ones you want to test)
export OPENAI_API_KEY="your-openai-key"
export ANTHROPIC_API_KEY="your-anthropic-key"
export GROQ_API_KEY="your-groq-key"
export MISTRAL_API_KEY="your-mistral-key"
export COHERE_API_KEY="your-cohere-key"
export TOGETHER_API_KEY="your-together-key"
export REPLICATE_API_TOKEN="your-replicate-token"
export GEMINI_API_KEY="your-gemini-key"
export ALEPH_ALPHA_API_KEY="your-aleph-alpha-key"

# For AWS-based providers (Bedrock, SageMaker)
export AWS_ACCESS_KEY_ID="your-aws-key"
export AWS_SECRET_ACCESS_KEY="your-aws-secret"
export AWS_REGION="us-east-1"

# For Azure OpenAI
export AZURE_OPENAI_API_KEY="your-azure-key"
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com"

# For Google Cloud (Vertex AI)
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
export GOOGLE_CLOUD_PROJECT="your-gcp-project"
```

3. Install the provider SDK you want to test:

```bash
# Examples:
uv add openai
uv add anthropic
uv add groq
uv add mistralai
uv add cohere
uv add together
uv add replicate
uv add google-generativeai
uv add ollama
uv add litellm
uv add boto3  # For Bedrock and SageMaker
uv add google-cloud-aiplatform  # For Vertex AI
uv add aleph-alpha-client
uv add ibm-watsonx-ai
uv add transformers torch
uv add langchain langchain-openai
uv add llama-index llama-index-llms-openai
uv add haystack-ai
uv add dspy-ai
uv add crewai
```

4. Run an example:

```bash
uv run python examples/test_openai.py
```

5. Check your Latitude dashboard for the trace at `http://localhost:8080`

## Available Examples

| Provider     | File                   | Required Package                         |
| ------------ | ---------------------- | ---------------------------------------- |
| OpenAI       | `test_openai.py`        | `openai`                                 |
| OpenAI Agents | `test_openai_agents.py` | `openai-agents`                          |
| Anthropic    | `test_anthropic.py`    | `anthropic`                              |
| Groq         | `test_groq.py`         | `groq`                                   |
| Mistral      | `test_mistral.py`      | `mistralai`                              |
| Cohere       | `test_cohere.py`       | `cohere`                                 |
| CrewAI       | `test_crewai.py`       | `crewai`                                 |
| Together     | `test_together.py`     | `together`                               |
| Replicate    | `test_replicate.py`    | `replicate`                              |
| Gemini       | `test_gemini.py`       | `google-generativeai`                    |
| Ollama       | `test_ollama.py`       | `ollama`                                 |
| LiteLLM      | `test_litellm.py`      | `litellm`                                |
| Azure OpenAI | `test_azure.py`        | `openai`                                 |
| Bedrock      | `test_bedrock.py`      | `boto3`                                  |
| Vertex AI    | `test_vertex.py`       | `google-cloud-aiplatform`                |
| SageMaker    | `test_sagemaker.py`    | `boto3`                                  |
| Aleph Alpha  | `test_aleph_alpha.py`  | `aleph-alpha-client`                     |
| watsonx      | `test_watsonx.py`      | `ibm-watsonx-ai`                         |
| Transformers | `test_transformers.py` | `transformers`, `torch`                  |
| LangChain    | `test_langchain.py`    | `langchain`, `langchain-openai`          |
| LlamaIndex   | `test_llamaindex.py`   | `llama-index`, `llama-index-llms-openai` |
| Haystack     | `test_haystack.py`     | `haystack-ai`                            |
| DSPy         | `test_dspy.py`         | `dspy-ai`                                |

## Expected Behavior

Each example should:

1. Initialize telemetry with `Latitude()`
2. Wrap the LLM call with `@capture` decorator
3. Print the response
4. Send a trace to your local Latitude instance

Example pattern:

```python
import openai

from latitude_telemetry import Latitude, capture

latitude = Latitude(
    api_key=os.environ["LATITUDE_API_KEY"],
    project=os.environ["LATITUDE_PROJECT_SLUG"],
    instrumentations={"openai": openai},
    disable_batch=True,
)

@capture("test-name", {"tags": ["test"], "session_id": "example"})
def test_function():
    # Your LLM call here
    ...

if __name__ == "__main__":
    test_function()
    latitude.flush()
```

Check the Latitude dashboard to verify:

- The trace appears with the specified tags
- Input/output messages are captured
- Token usage is recorded (where supported)
- Model information is correct
