# Observability for AutoGen with Opik

> Start here to integrate Opik into your AutoGen-based genai application for end-to-end LLM observability, unit testing, and optimization.

[Autogen](https://microsoft.github.io/autogen/stable/) is a framework for building AI agents and applications built and maintained by Microsoft.

Autogen's primary advantage is its enterprise-ready architecture with built-in logging and observability features, making it ideal for production multi-agent systems that require robust monitoring and debugging capabilities.

<Frame>
  <img src="https://files.buildwithfern.com/https://opik.docs.buildwithfern.com/docs/opik/2026-01-30T17:33:07.444Z/img/tracing/autogen_integration.png" alt="Autogen tracing" />
</Frame>

## Getting started

To use the Autogen integration with Opik, you will need to have the following
packages installed:

```bash
pip install -U "autogen-agentchat" "autogen-ext[openai]" opik opentelemetry-sdk opentelemetry-instrumentation-openai opentelemetry-exporter-otlp
```

In addition, you will need to set the following environment variables to
configure the OpenTelemetry integration:

<Tabs>
  <Tab value="Opik Cloud" title="Opik Cloud">
    If you are using Opik Cloud, you will need to set the following
    environment variables:

    ```bash wordWrap
    export OTEL_EXPORTER_OTLP_ENDPOINT=https://www.comet.com/opik/api/v1/private/otel
    export OTEL_EXPORTER_OTLP_HEADERS='Authorization=<your-api-key>,Comet-Workspace=default'
    ```

    <Tip>
      To log the traces to a specific project, you can add the
      `projectName` parameter to the `OTEL_EXPORTER_OTLP_HEADERS`
      environment variable:

      ```bash wordWrap
      export OTEL_EXPORTER_OTLP_HEADERS='Authorization=<your-api-key>,Comet-Workspace=default,projectName=<your-project-name>'
      ```

      You can also update the `Comet-Workspace` parameter to a different
      value if you would like to log the data to a different workspace.
    </Tip>
  </Tab>

  <Tab value="Enterprise deployment" title="Enterprise deployment">
    If you are using an Enterprise deployment of Opik, you will need to set the following
    environment variables:

    ```bash wordWrap
    export OTEL_EXPORTER_OTLP_ENDPOINT=https://<comet-deployment-url>/opik/api/v1/private/otel
    export OTEL_EXPORTER_OTLP_HEADERS='Authorization=<your-api-key>,Comet-Workspace=default'
    ```

    <Tip>
      To log the traces to a specific project, you can add the
      `projectName` parameter to the `OTEL_EXPORTER_OTLP_HEADERS`
      environment variable:

      ```bash wordWrap
      export OTEL_EXPORTER_OTLP_HEADERS='Authorization=<your-api-key>,Comet-Workspace=default,projectName=<your-project-name>'
      ```

      You can also update the `Comet-Workspace` parameter to a different
      value if you would like to log the data to a different workspace.
    </Tip>
  </Tab>

  <Tab value="Self-hosted instance" title="Self-hosted instance">
    If you are self-hosting Opik, you will need to set the following environment
    variables:

    ```bash
    export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:5173/api/v1/private/otel
    ```

    <Tip>
      To log the traces to a specific project, you can add the `projectName`
      parameter to the `OTEL_EXPORTER_OTLP_HEADERS` environment variable:

      ```bash
      export OTEL_EXPORTER_OTLP_HEADERS='projectName=<your-project-name>'
      ```
    </Tip>
  </Tab>
</Tabs>

## Using Opik with Autogen

The Autogen library includes some examples on how to integrate with OpenTelemetry
compatible tools, you can learn more about it here:

1. If you are using [autogen-core](https://microsoft.github.io/autogen/stable/user-guide/core-user-guide/framework/telemetry.html)
2. If you are using [autogen\_agentchat](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tracing.html)

In the example below, we will focus on the `autogen_agentchat` library that is a
little easier to use:

```python