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

# IBM Instana

> Langtrace and IBM Instana Integration Guide

## Overview

IBM Instana is a powerful platform for monitoring the performance of your applications. This guide focuses on integrating Langtrace AI with IBM Instana for distributed tracing of your LLM powered applications.

## Prerequisites

Before you begin, ensure you have the following:

* An [IBM Instana](https://www.ibm.com/products/instana) account

## Setup

In your OpenTelemetry collector setup, make sure you have the collector endpoint environment variable set like this example:

```bash theme={null}
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
```

### Initialize the Langtrace SDK

Initialize the Langtrace SDK in your application with your OTLP collector endpoint:

```python theme={null}
import os
from openai import OpenAI

from langtrace_python_sdk import langtrace
from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span

from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import \
    OTLPSpanExporter

# Set up the OTLP exporter with the endpoint from your collector
otlp_exporter = OTLPSpanExporter(
    # This should match your collector's OTLP gRPC endpoint
    endpoint=os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT"),
    insecure=True  # Set to False if using HTTPS
)

# set up langtrace
langtrace.init(custom_remote_exporter=otlp_exporter)

# rest of your code
@with_langtrace_root_span() # This optional annotation is used to create a parent root span for the entire application
def app():
    client = OpenAI(
        api_key="<YOUR_OPENAI_API_KEY>")
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {
                "role": "system",
                "content": "How many states of matter are there?"
            }
        ],
    )
    print(response.choices[0].message.content)


app()
```

Note: The OTLP collector is setup using a config file in this example. The config file is shown below:

```yaml theme={null}
receivers:
  otlp:
    protocols:
      http:
        endpoint: "localhost:4318"
      grpc:
        endpoint: "localhost:4317"

processors:
  batch:

exporters:
  otlp:
    endpoint: "otlp-coral-saas.instana.io:4317"
    headers:
      "x-instana-key": "<YOUR_INSTANA_API_KEY>" # Replace with your actual Instana API key which you can find in your email confirmation after signing up for Instana.

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp]
```

### **Run the Application**

With the environment variables set, run your application with OpenTelemetry instrumentation. Use the following command:

```bash theme={null}
python main.py
```

Note: Make sure your collector is running and configured correctly. To run the collector locally, you can use the following command:

```bash theme={null}
otelcol-contrib --config otel-collector-config.yaml
```

### **Verifying the Setup**

Once the application is running, you should see traces in your Instana APM dashboard as shown below:

<img src="https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/instana1.png?fit=max&auto=format&n=m7BVnnhK3Cx2yRxS&q=85&s=7c6e296fc66c7eda756084eefbb62689" alt="IBM Instana Tracing 1" width="3092" height="1778" data-path="images/instana1.png" />

<img src="https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/instana2.png?fit=max&auto=format&n=m7BVnnhK3Cx2yRxS&q=85&s=16b59d251a1087f62fc370c5df4192d0" alt="IBM Instana Tracing 2" width="3084" height="1758" data-path="images/instana2.png" />

<img src="https://mintcdn.com/langtraceai-2/m7BVnnhK3Cx2yRxS/images/instana3.png?fit=max&auto=format&n=m7BVnnhK3Cx2yRxS&q=85&s=b45aacade6adc9a2580a4c3d370a2bc6" alt="IBM Instana Tracing 3" width="3098" height="1790" data-path="images/instana3.png" />

**Missing Libraries**: Verify that all necessary libraries are installed. If you encounter any errors, reinstall the libraries using the provided commands.

**Additional Resources**

* [IBM Instana OpenTelemetry Documentation](https://www.ibm.com/docs/en/instana-observability/current?topic=instana-backend#endpoints-of-the-instana-backend-otlp-acceptor)
