OpenInference
OpenInference
수십 개 프레임워크·프로바이더의 instrumentor가 있는 OpenInference을 쓰면, AI 모델 추론을 OpenTelemetry 스팬으로 포착하는 개방형 표준을 따르는 애플리케이션을 쉽게 추적·평가할 수 있어요. 역할 분담은 단순합니다. OpenInference가 스팬을 만들고, confident-trace가 그것을 내보냅니다.
출처: 문서
본문
개요
OpenInference는 AI 모델 추론을 OpenTelemetry 스팬으로 포착하기 위한 개방형 표준으로, 수십 개 프레임워크·프로바이더의 instrumentor가 있어요. Confident AI는 OpenTelemetry 네이티브 추적 SDK인 confident-trace를 써서, OpenInference으로 계측된 모든 애플리케이션을 몇 줄의 코드로 추적·평가하게 해 줍니다.
역할 분담은 단순해요. OpenInference이 스팬을 만들고, confident-trace가 그것을 내보냅니다. 내 프레임워크의 instrumentor가 SDK를 패치하고 전역 OpenTelemetry 프로바이더를 통해 스팬을 만듭니다. confident-trace는 그 프로바이더와 export 파이프라인을 설치하고, 스팬을 바꾸지 않고 Observatory로 전달합니다.
이 통합은 네이티브 Confident AI 통합이 없는 프레임워크·프로바이더에, 또는 애플리케이션이 이미 OpenInference에 정착했을 때 사용하세요. LangChain, LangGraph, OpenAI, LlamaIndex 등에 대해서는 전용 통합이 타입이 지정된 스팬 유형과 토큰 사용량을 가진 더 풍부한 스팬을 만들어 줘요.
Google ADK는 자체 OpenTelemetry 스팬을 만들기 때문에 OpenInference instrumentor가 필요 없어요 — 전용 Google ADK 통합을 사용하세요.
| Runtime | Requirements | Setup |
|---|---|---|
| Python | Python 3.10+, an openinference-instrumentation-* package |
Call init(instrumentations=()), then enable the instrumentor |
| TypeScript | Node.js 22+, @opentelemetry/instrumentation, an @arizeai/openinference-instrumentation-* package |
Call init({ instrumentations: [] }), then registerInstrumentations |
자동 계측
EU 리전 사용자는 아래처럼 OTEL 엔드포인트를 EU 버전으로 설정하세요.
export CONFIDENT_OTEL_ENDPOINT="https://eu.otel.confident-ai.com/v1/traces"
의존성 설치
confident-trace를 프레임워크·프로바이더용 OpenInference instrumentor와 함께 설치하세요.
프레임워크용 특정 OpenInference instrumentor가 필요해요. 예:
openinference-instrumentation-langchain,openinference-instrumentation-openai,@arizeai/openinference-instrumentation-anthropic. 흔한 패키지는 이용 가능한 instrumentor를 참고하세요.
Python
이 예제는 LangChain instrumentor를 사용합니다.
pip install confident-trace openinference-instrumentation-langchain 'langchain>=1,<2' 'langchain-openai>=1,<2'
TypeScript
이 예제는 OpenAI instrumentor를 사용합니다. tsx는 TypeScript 소스를 직접 실행할 때만 필요해요.
npm install confident-trace @opentelemetry/instrumentation @arizeai/openinference-instrumentation-openai openai
npm install -D tsx
API 키 설정
Confident AI에서 프로젝트 API 키를 받아 앱이 쓰는 프로바이더 키와 함께 환경 변수로 설정하세요.
export CONFIDENT_API_KEY="<your-confident-project-key>"
export OPENAI_API_KEY="<your-openai-key>"
OpenInference 계측
시작 시 init()을 빈 계측 목록으로 호출한 다음, OpenInference instrumentor를 활성화하세요. 빈 목록이 중요합니다. 그렇지 않으면 confident-trace가 OpenAI, LangChain 등을 직접 계측해서, 모든 모델 호출이 두 번 — OpenInference에서 한 번, Confident 자체 통합에서 한 번 — 나타나게 돼요.
Python
init()이 전역 프로바이더와 Confident의 export 파이프라인을 설치하고, 그 뒤에 활성화하는 instrumentor가 그 프로바이더를 자동으로 잡아요.
from confident_trace import init, shutdown
from openinference.instrumentation.langchain import LangChainInstrumentor
from langchain_openai import ChatOpenAI
init(instrumentations=())
LangChainInstrumentor().instrument()
try:
llm = ChatOpenAI(model="gpt-4.1-mini")
print(llm.invoke("What are LLMs?").content)
finally:
shutdown()
TypeScript
init()이 전역 프로바이더를 만들고 등록합니다. OpenInference 계측을 패치할 SDK를 가져오기 전에 등록하세요.
import { init } from "confident-trace";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
const runtime = init({ instrumentations: [] });
registerInstrumentations({
instrumentations: [new OpenAIInstrumentation()],
});
try {
const { default: OpenAI } = await import("openai");
const client = new OpenAI();
const response = await client.chat.completions.create({
model: "gpt-4.1-mini",
messages: [{ role: "user", content: "What is OpenInference?" }],
});
console.log(response.choices[0].message.content);
} finally {
await runtime.shutdown();
}
순서가 중요해요.
registerInstrumentations는 패치된 SDK가 가져와지기 전에 실행돼야 합니다. 그래서 예제가 등록 후 동적import("openai")를 쓰는 거예요. 파일 맨 위에 정적import OpenAI from "openai"를 두면 instrumentor가 패치하기 전에 SDK가 로드되어 스팬이 하나도 없어요.
Confident AI는 내 instrumentor가 명시적으로 만드는 텔레메트리만 받아요. 전체 애플리케이션 흐름을 보려면 OpenInference로 중첩 레이어로 계측하세요 — 프레임워크 instrumentor에 프로바이더 instrumentor를 더하거나, 프레임워크 instrumentor만 — OpenInference이 다루지 않는 코드에는 커스텀 애플리케이션 스팬으로 빈틈을 채우세요.
장기 실행 서버에서는 시작 시
init()을 한 번, 활성 요청이 끝난 뒤shutdown()을 한 번 호출하세요 — 요청마다 하지 마세요. 한 번 초기화를 참고하세요.
코드 실행
Python
python main.py
TypeScript
node --import tsx src/index.ts
여기서 confident-trace/register preload는 필요 없어요 — 그 preload는 Confident 자체 통합용으로 패키지를 훅하는 것인데, 닫아 두었기 때문이에요. OpenInference은 자체 패칭을 합니다.
완료 ✅. Confident AI의 Observatory 안 트레이스 페이지에서 트레이스를 볼 수 있어요.
트레이스가 안 보이면 작업 순서를 확인하세요:
init()먼저, 그 다음 instrumentor 활성화, 그 다음 계측된 SDK 로드·실행 — 그리고 프로세스가shutdown()에 도달해 버퍼링된 스팬이 플러시되는지. 자세한 건 트러블슈팅을 참고하세요.
무엇이 포착되나
OpenInference instrumentor가 만드는 것 그대로에요. confident-trace는 통과형(pass-through) exporter로 동작합니다.
- 그대로 보존 — instrumentor의 스팬 이름, 속성, 이벤트가 만들어진 그대로 내보내짐
- 계층 — 스팬이 instrumentor가 보고하는 부모/자식 구조를 유지. 부모 없는 스팬은 새 트레이스 시작
- 재작성 없음 — OpenInference 속성이 Confident 자체 통합이 쓰는 GenAI 컨벤션으로 변환되지 않음. 각 스팬을 LLM·도구·에이전트 스팬으로 어떻게 표시하고 콘텐츠를 어떻게 추출할지는 Confident AI의 플랫폼 측 OpenInference 매핑이 결정
instrumentor가 스팬을 소유하므로, 어떤 속성(모델 이름, 메시지, 토큰 수)이 나타날지는
confident-trace가 아니라 instrumentor와 그 버전에 달려 있어요. 스팬은 나타나는데 비어 보이면, instrumentor의 자체 콘텐츠 설정을 먼저 확인하세요.
이용 가능한 Instrumentor
전역 OpenTelemetry 프로바이더를 통해 내보내는 어떤 OpenInference instrumentor든 같은 방식으로 동작합니다. 흔한 패키지는 다음과 같아요.
| Runtime | Packages |
|---|---|
| Python | openinference-instrumentation-langchain, openinference-instrumentation-openai, openinference-instrumentation-anthropic, openinference-instrumentation-llama-index |
| TypeScript | @arizeai/openinference-instrumentation-openai, @arizeai/openinference-instrumentation-anthropic, @arizeai/openinference-instrumentation-langchain |
각각 OpenInference이 문서화한 대로 설치·활성화하세요.
Confident AI에는 이 몇몇에 대한 전용 통합이 있어요. 예: OpenAI, LangChain, LangGraph, LlamaIndex. 아직 OpenInference에 정착하지 않았다면 그쪽을 선호하세요 — 기본으로 타입이 지정된 스팬 유형과 토큰 사용량을 만들어 줘요.
트레이스 스팬 속성 설정
호출이 시작되기 전에 아는 속성을 추가하려면 트레이스 컨텍스트를 사용하세요. 추가 스팬은 만들지 않아요. 계측된 프레임워크·프로바이더 호출이 시작한 트레이스가 태그, 메타데이터, 사용자 ID, 고객 ID를 상속받습니다.
Python
from confident_trace import init, trace_context
from langchain_openai import ChatOpenAI
init(instrumentations=())
llm = ChatOpenAI(model="gpt-4.1-mini")
with trace_context(
tags=["support"],
metadata={"instrumentor": "openinference"},
user_id="user-42",
customer_id="customer-7",
):
result = llm.invoke("Explain OpenTelemetry in one sentence.")
TypeScript
import { init, traceContext } from "confident-trace";
init({ instrumentations: [] });
const result = await traceContext(
{
tags: ["support"],
metadata: { instrumentor: "openinference" },
userId: "user-42",
customerId: "customer-7",
},
() => client.responses.create({
model: "gpt-4.1-mini",
input: "Explain OpenTelemetry in one sentence.",
}),
);
각 ID와 함께 선택적 표시 이름을 설정하려면 사용자와 고객을, 지원되는 모든 트레이스 속성과 갱신 동작은 트레이스 컨텍스트를 참고하세요.
다중 턴 계측
OpenInference 엔트리포인트 호출 하나가 이미 하나의 대화 턴일 때는 turn()이 필요 없어요 — 통합이 그 턴의 트레이스를 자동으로 만들어 주거든요. 경계를 직접 정의하고 싶을 때, 예를 들어 두 번의 연속 OpenInference 호출을 하나의 턴으로 묶고 싶을 때 turn()을 사용하세요. 이후 턴에서 같은 스레드 ID를 재사용해 하나의 대화로 묶으면 돼요.
Python
from confident_trace import init, turn
init(instrumentations=())
with turn("support-turn", thread_id="chat-42"):
context = llm.invoke("Find the relevant account details.")
answer = llm.invoke(f"Summarize these details: {context.content}")
TypeScript
import { init, turn } from "confident-trace";
init({ instrumentations: [] });
const answer = await turn({ name: "support-turn", threadId: "chat-42" }, async () => {
const context = await client.responses.create({ model: "gpt-4.1-mini", input: "Find the relevant account details." });
return client.responses.create({ model: "gpt-4.1-mini", input: `Summarize these details: ${context.output_text}` });
});
스레드 입출력, 턴 ID, 사용자 ID는 스레드를 참고하세요.
OpenInference 계측 비활성화
Confident AI 통합을 선택하려면 init()에 식별자 목록을 전달하세요. OpenInference에는 init() 식별자가 없습니다 — instrumentor를 별도로 등록하니까요. 비활성화 상태를 유지하려면 빈 목록을 쓰고 OpenInference instrumentor를 등록하지 마세요.
Python
from confident_trace import init
init(instrumentations=())
# OpenInference has no identifier; do not register its instrumentor.
TypeScript
import { init } from "confident-trace";
init({ instrumentations: [] });
// OpenInference has no identifier; do not register its instrumentor.
이렇게 하면 Confident AI의 자동 instrumentor가 꺼져요. 그 다음 OpenInference instrumentor를 등록하지 마세요.
다음 단계
OpenInference 스팬이 Confident AI에 도착하기 시작했으니, 더 깊이 들어가 볼까요.
OpenTelemetry 통합
자체 프로바이더를 가져오고, 컬렉터에서 트레이스를 포워딩하며, 원시 OpenTelemetry 속성이 Confident AI 필드로 매핑되는 방식을 확인하세요.
Online Evals
트레이스·스팬·스레드가 Confident AI로 수집되는 실시간으로 평가를 돌려 AI 품질을 모니터링하세요.
더 알아보기
- OpenTelemetry 개요 — 프로바이더 가져오기·속성 매핑
- OpenAI — 공식 OpenAI 클라이언트 전용 통합
- Online Evals — 실시간 트레이스·스팬 평가