> ## Documentation Index
> Fetch the complete documentation index at: https://puzzlet-9ba7bb98.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenInference

> Trace LangChain, LlamaIndex, OpenAI Agents SDK, CrewAI, DSPy, and other OpenInference-instrumented frameworks in AgentMark.

[OpenInference](https://github.com/Arize-ai/openinference) is a set of OpenTelemetry instrumentors for LLM frameworks and providers. Each one auto-captures model calls, tool calls, retrieval steps, and agent runs as OTLP spans. AgentMark reads the OpenInference attribute conventions directly, so any OpenInference-instrumented app sends usable traces by pointing its exporter at AgentMark, with no per-framework setup on the AgentMark side.

## Supported frameworks

OpenInference maintains instrumentors for a wide range of libraries, including:

| Category      | Instrumentors                                                                |
| ------------- | ---------------------------------------------------------------------------- |
| Orchestration | LangChain, LangGraph, LlamaIndex, Haystack, DSPy                             |
| Agents        | OpenAI Agents SDK, CrewAI, AutoGen, smolagents, Google ADK, Agno             |
| Providers     | OpenAI, Anthropic, Amazon Bedrock, Vertex AI, Gemini, Mistral, Groq, LiteLLM |
| Other         | Instructor, Guardrails, Model Context Protocol (MCP)                         |

See the [OpenInference repository](https://github.com/Arize-ai/openinference) for the complete, current list and the Python and JavaScript package names.

## Setup

OpenInference ships instrumentors for both Python and JavaScript/TypeScript. The example below instruments OpenAI; swap the instrumentor package and class for the framework you use. The OTLP wiring stays identical.

<Steps>
  <Step title="Install the instrumentor and the OTLP exporter">
    <CodeGroup>
      ```bash TypeScript theme={null}
      npm install @arizeai/openinference-instrumentation-openai \
        @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base \
        @opentelemetry/exporter-trace-otlp-http @opentelemetry/instrumentation
      ```

      ```bash Python theme={null}
      pip install openinference-instrumentation-openai \
        opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
      ```
    </CodeGroup>
  </Step>

  <Step title="Point the exporter at AgentMark">
    Register a tracer provider that exports to AgentMark, then instrument your framework. Use your AgentMark API key and app id (from project settings).

    <CodeGroup>
      ```typescript TypeScript theme={null}
      import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
      import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
      import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
      import { registerInstrumentations } from "@opentelemetry/instrumentation";
      import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";

      const provider = new NodeTracerProvider({
        spanProcessors: [
          new BatchSpanProcessor(
            new OTLPTraceExporter({
              url: "https://api.agentmark.co/v1/traces",
              headers: {
                Authorization: process.env.AGENTMARK_API_KEY!, // raw key, no "Bearer" prefix
                "X-Agentmark-App-Id": process.env.AGENTMARK_APP_ID!,
              },
            })
          ),
        ],
      });
      provider.register();

      registerInstrumentations({ instrumentations: [new OpenAIInstrumentation()] });
      ```

      ```python Python theme={null}
      from openinference.instrumentation.openai import OpenAIInstrumentor
      from opentelemetry.sdk.trace import TracerProvider
      from opentelemetry.sdk.trace.export import BatchSpanProcessor
      from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

      provider = TracerProvider()
      provider.add_span_processor(
          BatchSpanProcessor(
              OTLPSpanExporter(
                  endpoint="https://api.agentmark.co/v1/traces",
                  headers={
                      "Authorization": "<YOUR_API_KEY>",  # raw key, no "Bearer" prefix
                      "X-Agentmark-App-Id": "<YOUR_APP_ID>",
                  },
              )
          )
      )

      OpenAIInstrumentor().instrument(tracer_provider=provider)
      ```
    </CodeGroup>

    Swap `OpenAIInstrumentation` / `OpenAIInstrumentor` for the instrumentor that matches your framework (for example `@arizeai/openinference-instrumentation-langchain` or `openinference-instrumentation-langchain`).

    <Note>
      In TypeScript, this setup must run **before** you import the instrumented libraries, so the instrumentor can patch them. Put it in its own module and load it first, for example `node -r ./instrumentation.js app.js`.
    </Note>
  </Step>

  <Step title="Run your app">
    Run your application as usual. Each model call, tool call, and retrieval step arrives in AgentMark as a span, grouped into a trace. See [Traces and logs](/observe/traces-and-logs).
  </Step>
</Steps>

<Tip>
  Every OpenInference instrumentor exports through the same OTLP endpoint, so the only thing that changes between frameworks is the instrumentor you install and register. You can also set the endpoint and headers with the standard `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` and `OTEL_EXPORTER_OTLP_TRACES_HEADERS` environment variables instead of configuring the exporter in code. See [OpenTelemetry](/integrations/tracing/opentelemetry).
</Tip>

## What AgentMark captures

AgentMark maps OpenInference attributes onto its normalized trace fields:

| OpenInference attribute                                      | AgentMark field                                                        |
| ------------------------------------------------------------ | ---------------------------------------------------------------------- |
| `llm.model_name`                                             | Model                                                                  |
| `llm.token_count.prompt` / `.completion` / `.total`          | Input / output / total tokens                                          |
| `llm.token_count.completion_details.reasoning`               | Reasoning tokens                                                       |
| `llm.input_messages.*` / `llm.output_messages.*`             | Input / output messages                                                |
| `input.value` / `output.value`                               | Input / output on chain, tool, and agent spans                         |
| `llm.output_messages.*.tool_calls.*`                         | Tool calls                                                             |
| `llm.invocation_parameters`                                  | Settings (temperature, max tokens, top-p, penalties)                   |
| `retrieval.documents.*.document.{id,content,score,metadata}` | Retrieved documents (ranked, with relevance scores) on retrieval spans |
| `openinference.span.kind`                                    | Span kind (`llm`, `tool`, `agent`, `retrieval`, …)                     |
| `session.id` / `user.id` / `metadata`                        | Session, user, and custom metadata                                     |

Token counts and the model feed AgentMark's [cost tracking](/observe/cost-and-token-tracking) automatically.

## Next steps

<CardGroup cols={2}>
  <Card title="OpenTelemetry endpoint" icon="plug" href="/integrations/tracing/opentelemetry">
    The endpoint, authentication, and environment-variable configuration
  </Card>

  <Card title="Traces and logs" icon="list-tree" href="/observe/traces-and-logs">
    Explore traces once they arrive
  </Card>
</CardGroup>

<div className="mt-8 rounded-lg bg-blue-50 p-6 dark:bg-blue-900/30">
  <h3 className="font-semibold mb-3">Have questions?</h3>
  <p className="mb-4">Reach out any time:</p>

  <ul>
    <li>
      Email the team at <a href="mailto:hello@agentmark.co" className="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-200">[hello@agentmark.co](mailto:hello@agentmark.co)</a> for support
    </li>

    <li>
      Schedule an <a href="https://cal.com/ryan-randall/enterprise" className="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-200">Enterprise Demo</a> to learn about AgentMark's business solutions
    </li>
  </ul>
</div>
