Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Collection, List, Optional, Union

from opentelemetry import context as context_api
from opentelemetry._events import EventLogger, get_event_logger
from opentelemetry._logs import Logger, get_logger
from opentelemetry.instrumentation.alephalpha.config import Config
from opentelemetry.instrumentation.alephalpha.event_emitter import emit_event
from opentelemetry.instrumentation.alephalpha.event_models import (
Expand Down Expand Up @@ -38,7 +38,7 @@

logger = logging.getLogger(__name__)

_instruments = ("aleph_alpha_client >= 7.1.0, <8",)
_instruments = ("aleph_alpha_client >= 7.1.0",)

WRAPPED_METHODS = [
{
Expand Down Expand Up @@ -69,7 +69,7 @@ def _set_span_attribute(span, name, value):

@dont_throw
def _handle_message_event(
event: PromptEvent, span: Span, event_logger: Optional[EventLogger], kwargs
event: PromptEvent, span: Span, event_logger: Optional[Logger], kwargs
):
if span.is_recording():
_set_span_attribute(span, GenAIAttributes.GEN_AI_REQUEST_MODEL, kwargs.get("model"))
Expand Down Expand Up @@ -141,7 +141,7 @@ def _parse_completion_event(response) -> List[CompletionEvent]:
@_with_tracer_wrapper
def _wrap(
tracer: Tracer,
event_logger: Union[EventLogger, None],
event_logger: Union[Logger, None],
to_wrap,
wrapped,
instance,
Expand Down Expand Up @@ -197,11 +197,11 @@ def _instrument(self, **kwargs):
event_logger = None

if should_emit_events():
event_logger_provider = kwargs.get("event_logger_provider")
event_logger = get_event_logger(
logger_provider = kwargs.get("logger_provider")
event_logger = get_logger(
__name__,
__version__,
event_logger_provider=event_logger_provider,
logger_provider=logger_provider,
)

for wrapped_method in WRAPPED_METHODS:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from typing import Union

from opentelemetry._events import Event
from opentelemetry._logs import LogRecord
from opentelemetry.instrumentation.alephalpha.event_models import (
CompletionEvent,
PromptEvent,
Expand Down Expand Up @@ -79,7 +79,12 @@ def _emit_prompt_event(event: PromptEvent, event_logger) -> None:
for tool_call in body["tool_calls"]:
tool_call["function"].pop("arguments", None)

event_logger.emit(Event(name=name, body=body, attributes=EVENT_ATTRIBUTES))
log_record = LogRecord(
body=body,
attributes=EVENT_ATTRIBUTES,
event_name=name
)
event_logger.emit(log_record)


def _emit_completion_event(event: CompletionEvent, event_logger) -> None:
Expand Down Expand Up @@ -108,6 +113,10 @@ def _emit_completion_event(event: CompletionEvent, event_logger) -> None:
for tool_call in body["tool_calls"]:
tool_call["function"].pop("arguments", None)

event_logger.emit(
Event(name="gen_ai.choice", body=body, attributes=EVENT_ATTRIBUTES)
log_record = LogRecord(
body=body,
attributes=EVENT_ATTRIBUTES,
event_name="gen_ai.choice"

)
event_logger.emit(log_record)
96 changes: 39 additions & 57 deletions packages/opentelemetry-instrumentation-alephalpha/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ include = "opentelemetry/instrumentation/alephalpha"

[tool.poetry.dependencies]
python = ">=3.9,<4"
opentelemetry-api = "^1.28.0"
opentelemetry-instrumentation = ">=0.50b0"
opentelemetry-semantic-conventions = ">=0.50b0"
opentelemetry-api = "^1.38.0"
opentelemetry-instrumentation = ">=0.59b0"
opentelemetry-semantic-conventions = ">=0.59b0"
opentelemetry-semantic-conventions-ai = "^0.4.13"

[tool.poetry.group.dev.dependencies]
Expand All @@ -42,7 +42,7 @@ pytest-sugar = "1.0.0"
vcrpy = "^6.0.1"
pytest-recording = "^0.13.1"
pytest-asyncio = "^0.23.7"
opentelemetry-sdk = "^1.27.0"
opentelemetry-sdk = "^1.38.0"

[build-system]
requires = ["poetry-core"]
Expand Down
Loading
Loading