fix(platform): move opentelemetry import to top-level in both copilot paths

This commit is contained in:
Zamil Majdy
2026-04-02 18:57:36 +02:00
parent 6fa66ac7da
commit 9a08011d7d
2 changed files with 2 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ from typing import Any, cast
import orjson
from langfuse import propagate_attributes
from openai.types.chat import ChatCompletionMessageParam, ChatCompletionToolParam
from opentelemetry import trace as otel_trace
from backend.copilot.context import set_execution_context
from backend.copilot.model import (
@@ -556,8 +557,6 @@ async def stream_chat_completion_baseline(
# Set cost attributes on OTEL span before closing
if _trace_ctx is not None:
try:
from opentelemetry import trace as otel_trace
span = otel_trace.get_current_span()
if span and span.is_recording():
span.set_attribute(

View File

@@ -29,6 +29,7 @@ from claude_agent_sdk import (
)
from langfuse import propagate_attributes
from langsmith.integrations.claude_agent_sdk import configure_claude_agent_sdk
from opentelemetry import trace as otel_trace
from pydantic import BaseModel
from backend.copilot.context import get_workspace_manager
@@ -2323,8 +2324,6 @@ async def stream_chat_completion_sdk(
# --- Close OTEL context (with cost attributes) ---
if _otel_ctx is not None:
try:
from opentelemetry import trace as otel_trace
span = otel_trace.get_current_span()
if span and span.is_recording():
span.set_attribute("gen_ai.usage.prompt_tokens", turn_prompt_tokens)