Skip to content

Commit a9f0f64

Browse files
keith-deckerzhirafovod
authored andcommitted
update documentation
1 parent 4404c20 commit a9f0f64

File tree

6 files changed

+84
-28
lines changed

6 files changed

+84
-28
lines changed

util/opentelemetry-util-genai/README.rst

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ while providing standardization for generating both types of otel, "spans and me
88

99
This package provides these span attributes.
1010
-> gen_ai.operation.name: Str(chat)
11+
-> gen_ai.provider.name: Str(openai)
1112
-> gen_ai.system: Str(ChatOpenAI)
1213
-> gen_ai.request.model: Str(gpt-3.5-turbo)
13-
-> gen_ai.request.top_p: Double(0.9)
14-
-> gen_ai.request.frequency_penalty: Double(0.5)
15-
-> gen_ai.request.presence_penalty: Double(0.5)
16-
-> gen_ai.request.stop_sequences: Slice(["\n","Human:","AI:"])
17-
-> gen_ai.request.seed: Int(100)
18-
-> gen_ai.request.max_tokens: Int(100)
19-
-> gen_ai.provider.name: Str(openai)
20-
-> gen_ai.request.temperature: Double(0.1)
2114
-> gen_ai.response.finish_reasons: Slice(["stop"])
2215
-> gen_ai.response.model: Str(gpt-3.5-turbo-0125)
2316
-> gen_ai.response.id: Str(chatcmpl-Bz8yrvPnydD9pObv625n2CGBPHS13)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

util/opentelemetry-util-genai/src/opentelemetry/util/genai/data.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
from dataclasses import dataclass
216

317

util/opentelemetry-util-genai/src/opentelemetry/util/genai/emitters.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""
16+
Emitters for GenAI telemetry instrumentation.
17+
18+
This module defines classes and utilities for mapping GenAI (Generative AI) invocations
19+
to OpenTelemetry spans, metrics, and events. Emitters manage the lifecycle of telemetry
20+
data for LLM (Large Language Model) operations, including success and error reporting.
21+
22+
Classes:
23+
BaseEmitter: Abstract base class for GenAI telemetry emitters.
24+
SpanMetricEventEmitter: Emits spans, metrics, and events for full telemetry.
25+
SpanMetricEmitter: Emits only spans and metrics (no events).
26+
27+
Functions:
28+
_get_property_value: Utility to extract property values from objects or dicts.
29+
_message_to_log_record: Converts a GenAI message to an OpenTelemetry LogRecord.
30+
_chat_generation_to_log_record: Converts a chat generation to a LogRecord.
31+
_get_metric_attributes: Builds metric attributes for telemetry reporting.
32+
33+
"""
34+
1535
from dataclasses import dataclass, field
1636
from typing import Dict, List, Optional
1737
from uuid import UUID
@@ -214,17 +234,6 @@ def init(self, invocation: LLMInvocation):
214234

215235
for message in invocation.messages:
216236
system = invocation.attributes.get("system")
217-
# Event API is deprecated, use structured logs instead
218-
# event = _message_to_event(
219-
# message=message,
220-
# provider_name=system,
221-
# framework=invocation.attributes.get("framework"),
222-
# )
223-
# if event and self._event_logger:
224-
# self._event_logger.emit(
225-
# event
226-
# )
227-
228237
log = _message_to_log_record(
229238
message=message,
230239
provider_name=system,
@@ -280,15 +289,6 @@ def emit(self, invocation: LLMInvocation):
280289
for index, chat_generation in enumerate(
281290
invocation.chat_generations
282291
):
283-
# Event API is deprecated. Use structured logs instead
284-
# event = _chat_generation_to_event(
285-
# chat_generation, index, system, framework
286-
# )
287-
# if event and self._event_logger:
288-
# self._event_logger.emit(
289-
# event
290-
# )
291-
292292
log = _chat_generation_to_log_record(
293293
chat_generation,
294294
index,

util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""
16+
Telemetry handler for GenAI invocations.
17+
18+
This module provides the `TelemetryHandler` class, which manages the lifecycle of
19+
GenAI (Generative AI) invocations and emits telemetry data as spans, metrics, and events.
20+
It supports starting, stopping, and failing LLM invocations,
21+
and provides module-level convenience functions for these operations.
22+
23+
Classes:
24+
TelemetryHandler: Manages GenAI invocation lifecycles and emits telemetry.
25+
26+
Functions:
27+
get_telemetry_handler: Returns a singleton TelemetryHandler instance.
28+
llm_start: Starts a new LLM invocation.
29+
llm_stop: Stops an LLM invocation and emits telemetry.
30+
llm_fail: Marks an LLM invocation as failed and emits error telemetry.
31+
32+
Usage:
33+
Use the module-level functions (`llm_start`, `llm_stop`, `llm_fail`) to
34+
instrument GenAI invocations for telemetry collection.
35+
"""
36+
1537
import time
1638
from threading import Lock
1739
from typing import Any, List, Optional

util/opentelemetry-util-genai/src/opentelemetry/util/genai/instruments.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
from opentelemetry.metrics import Histogram, Meter
216
from opentelemetry.semconv._incubating.metrics import gen_ai_metrics
317

0 commit comments

Comments
 (0)