Skip to content

Commit ece9c97

Browse files
committed
Merge branch 'development' into release
2 parents fd9baed + 219e691 commit ece9c97

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

src/langtrace_python_sdk/instrumentation/openai/patch.py

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,31 @@
11
import json
2-
from typing import Any, Dict, List, Optional, Callable, Awaitable, Union
3-
from langtrace.trace_attributes import (
4-
LLMSpanAttributes,
5-
SpanAttributes,
6-
)
7-
from langtrace_python_sdk.utils import set_span_attribute
8-
from langtrace_python_sdk.utils.silently_fail import silently_fail
2+
from typing import Any, Awaitable, Callable, Dict, List, Optional, Union
3+
4+
from langtrace.trace_attributes import LLMSpanAttributes, SpanAttributes
95
from opentelemetry import trace
10-
from opentelemetry.trace import SpanKind, Tracer, Span
11-
from opentelemetry.trace.status import Status, StatusCode
6+
from opentelemetry.trace import Span, SpanKind, Tracer
127
from opentelemetry.trace.propagation import set_span_in_context
13-
from langtrace_python_sdk.constants.instrumentation.common import (
14-
SERVICE_PROVIDERS,
15-
)
16-
from langtrace_python_sdk.constants.instrumentation.openai import APIS
17-
from langtrace_python_sdk.utils.llm import (
18-
calculate_prompt_tokens,
19-
get_base_url,
20-
get_extra_attributes,
21-
get_langtrace_attributes,
22-
get_llm_request_attributes,
23-
get_llm_url,
24-
get_span_name,
25-
get_tool_calls,
26-
is_streaming,
27-
set_event_completion,
28-
StreamWrapper,
29-
set_span_attributes,
30-
set_usage_attributes,
31-
)
32-
from langtrace_python_sdk.types import NOT_GIVEN
8+
from opentelemetry.trace.status import Status, StatusCode
339

10+
from langtrace_python_sdk.constants.instrumentation.common import \
11+
SERVICE_PROVIDERS
12+
from langtrace_python_sdk.constants.instrumentation.openai import APIS
3413
from langtrace_python_sdk.instrumentation.openai.types import (
35-
ImagesGenerateKwargs,
36-
ChatCompletionsCreateKwargs,
37-
EmbeddingsCreateKwargs,
38-
ImagesEditKwargs,
39-
ResultType,
40-
ContentItem,
41-
)
14+
ChatCompletionsCreateKwargs, ContentItem, EmbeddingsCreateKwargs,
15+
ImagesEditKwargs, ImagesGenerateKwargs, ResultType)
16+
from langtrace_python_sdk.types import NOT_GIVEN
17+
from langtrace_python_sdk.utils import set_span_attribute
18+
from langtrace_python_sdk.utils.llm import (StreamWrapper,
19+
calculate_prompt_tokens,
20+
get_base_url, get_extra_attributes,
21+
get_langtrace_attributes,
22+
get_llm_request_attributes,
23+
get_llm_url, get_span_name,
24+
get_tool_calls, is_streaming,
25+
set_event_completion,
26+
set_span_attributes,
27+
set_usage_attributes)
28+
from langtrace_python_sdk.utils.silently_fail import silently_fail
4229

4330

4431
def filter_valid_attributes(attributes):
@@ -717,3 +704,8 @@ def _set_response_attributes(span: Span, result: ResultType) -> None:
717704
SpanAttributes.LLM_USAGE_TOTAL_TOKENS,
718705
result.usage.total_tokens,
719706
)
707+
set_span_attribute(
708+
span,
709+
"gen_ai.usage.cached_tokens",
710+
result.usage.prompt_tokens_details.cached_tokens if result.usage.prompt_tokens_details else 0,
711+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.6.0"
1+
__version__ = "3.6.1"

0 commit comments

Comments
 (0)