Skip to content

Commit

Permalink
remove LLMSpanAttributes validation layer
Browse files Browse the repository at this point in the history
  • Loading branch information
alizenhom committed Sep 25, 2024
1 parent 48fb3fb commit e9a76c4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ classifiers = [
dependencies = [
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.48b0.dev",
"opentelemetry-semantic-conventions == 0.48b0.dev",
"pydantic>=1.8"
"opentelemetry-semantic-conventions == 0.48b0.dev"

]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.openai.package import _instruments
from opentelemetry.semconv.schemas import Schemas
from opentelemetry.trace import get_tracer

from .patch import chat_completions_create
Expand All @@ -64,7 +65,7 @@ def _instrument(self, **kwargs):
__name__,
"",
tracer_provider,
schema_url="https://opentelemetry.io/schemas/1.27.0",
schema_url=Schemas.V1_27_0,
)
wrap_function_wrapper(
module="openai.resources.chat.completions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from opentelemetry.trace import Span, SpanKind, Tracer
from opentelemetry.trace.status import Status, StatusCode

from .span_attributes import LLMSpanAttributes
from .utils import (
extract_content,
extract_tools_prompt,
Expand All @@ -49,13 +48,10 @@ def traced_method(wrapped, instance, args, kwargs):
llm_prompts.append(tools_prompt if tools_prompt else item)

span_attributes = {**get_llm_request_attributes(kwargs)}

attributes = LLMSpanAttributes(**span_attributes)

span_name = f"{attributes.gen_ai_operation_name} {attributes.gen_ai_request_model}"
span_name = f"{span_attributes[GenAIAttributes.GEN_AI_OPERATION_NAME]} {span_attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL]}"

span = tracer.start_span(name=span_name, kind=SpanKind.CLIENT)
_set_input_attributes(span, attributes)
_set_input_attributes(span, span_attributes)
set_event_prompt(span, json.dumps(llm_prompts))

try:
Expand Down Expand Up @@ -84,8 +80,8 @@ def traced_method(wrapped, instance, args, kwargs):


@silently_fail
def _set_input_attributes(span, attributes: LLMSpanAttributes):
for field, value in attributes.model_dump(by_alias=True).items():
def _set_input_attributes(span, attributes):
for field, value in attributes.items():
set_span_attribute(span, field, value)


Expand Down Expand Up @@ -219,7 +215,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
self.span.set_status(Status(StatusCode.ERROR, str(exc_val)))
self.span.set_attribute(
ErrorAttributes.ERROR_TYPE, exc_type.__name__
ErrorAttributes.ERROR_TYPE, exc_type.__qualname__
)
finally:
self.cleanup()
Expand Down

This file was deleted.

0 comments on commit e9a76c4

Please sign in to comment.