Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3dad6f9
updated input & output tokens attributes
martimfasantos Jul 15, 2025
e1cec0a
added opentelemetry gen_ai attributes
martimfasantos Jul 19, 2025
01b6fc1
Merge branch 'main' into task-update-genai-attributes
martimfasantos Jul 19, 2025
64ade2b
fixed remaining opentelemetry gen_ai attributes
martimfasantos Jul 19, 2025
f8914d6
fixed remaining opentelemetry gen_ai attributes
martimfasantos Jul 19, 2025
da625af
Merge branch 'main' into task-update-genai-attributes
martimfasantos Jul 22, 2025
2bed2c9
Merge branch 'main' into task-update-genai-attributes
martimfasantos Jul 25, 2025
c44af4c
deprecating gen_ai attributes from our semconv AI
martimfasantos Aug 19, 2025
0129a0a
deprecating gen_ai attributes from our semconv AI
martimfasantos Aug 19, 2025
ca73fdf
Merge remote-tracking branch 'upstream/main' into task-update-genai-a…
martimfasantos Aug 19, 2025
0959a96
deprecating gen_ai attributes from our semconv AI
martimfasantos Aug 19, 2025
9d4ad88
deprecating gen_ai attributes from our semconv AI
martimfasantos Aug 19, 2025
6538cad
small fixes
martimfasantos Aug 19, 2025
f7fb725
Merge branch 'main' into task-update-genai-attributes
martimfasantos Sep 5, 2025
a0e5e06
fix linting and some tests
martimfasantos Sep 6, 2025
857150b
Merge branch 'main' into task-update-genai-attributes
martimfasantos Sep 27, 2025
31ad6cc
fixed linting
martimfasantos Sep 27, 2025
8acb4c7
fixed linting
martimfasantos Sep 27, 2025
93f9d82
added linting & tests passing
martimfasantos Oct 1, 2025
ff53da7
Merge branch 'main' into task-update-genai-attributes
martimfasantos Oct 6, 2025
039dc6e
Merge branch 'main' into task-update-genai-attributes
martimfasantos Oct 30, 2025
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 @@ -23,6 +23,9 @@
_SUPPRESS_INSTRUMENTATION_KEY,
unwrap,
)
from opentelemetry.semconv._incubating.attributes import (
gen_ai_attributes as GenAIAttributes,
)
from opentelemetry.semconv_ai import (
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY,
LLMRequestTypeValues,
Expand Down Expand Up @@ -69,7 +72,7 @@ def _handle_message_event(
event: PromptEvent, span: Span, event_logger: Optional[EventLogger], kwargs
):
if span.is_recording():
_set_span_attribute(span, SpanAttributes.LLM_REQUEST_MODEL, kwargs.get("model"))
_set_span_attribute(span, GenAIAttributes.GEN_AI_REQUEST_MODEL, kwargs.get("model"))

if should_emit_events():
return emit_event(event, event_logger)
Expand All @@ -86,9 +89,9 @@ def _handle_completion_event(event: CompletionEvent, span, event_logger, respons
span, SpanAttributes.LLM_USAGE_TOTAL_TOKENS, input_tokens + output_tokens
)
_set_span_attribute(
span, SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, output_tokens
span, GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens
)
_set_span_attribute(span, SpanAttributes.LLM_USAGE_PROMPT_TOKENS, input_tokens)
_set_span_attribute(span, GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)

if should_emit_events():
emit_event(event, event_logger)
Expand Down Expand Up @@ -157,7 +160,7 @@ def _wrap(
name,
kind=SpanKind.CLIENT,
attributes={
SpanAttributes.LLM_SYSTEM: "AlephAlpha",
GenAIAttributes.GEN_AI_SYSTEM: "AlephAlpha",
SpanAttributes.LLM_REQUEST_TYPE: llm_request_type.value,
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
CompletionEvent,
PromptEvent,
)
from opentelemetry.semconv_ai import SpanAttributes
from opentelemetry.semconv._incubating.attributes import (
gen_ai_attributes as GenAIAttributes,
)
from opentelemetry.trace.span import Span


Expand All @@ -16,10 +18,10 @@ def set_prompt_attributes(event: PromptEvent, span: Span):
return

if should_send_prompts():
_set_span_attribute(span, f"{SpanAttributes.LLM_PROMPTS}.0.role", "user")
_set_span_attribute(span, f"{GenAIAttributes.GEN_AI_PROMPT}.0.role", "user")
_set_span_attribute(
span,
f"{SpanAttributes.LLM_PROMPTS}.0.content",
f"{GenAIAttributes.GEN_AI_PROMPT}.0.content",
event.content[0].get("data"),
)

Expand All @@ -36,9 +38,9 @@ def set_completion_attributes(event: CompletionEvent, span: Span):
if should_send_prompts():
_set_span_attribute(
span,
f"{SpanAttributes.LLM_COMPLETIONS}.0.content",
f"{GenAIAttributes.GEN_AI_COMPLETION}.0.content",
event.message["content"],
)
_set_span_attribute(
span, f"{SpanAttributes.LLM_COMPLETIONS}.0.role", "assistant"
span, f"{GenAIAttributes.GEN_AI_COMPLETION}.0.role", "assistant"
)

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 @@ -35,12 +35,12 @@ def test_alephalpha_completion(
together_span.attributes.get("gen_ai.completion.0.content")
== response.completions[0].completion
)
assert together_span.attributes.get("gen_ai.usage.prompt_tokens") == 9
assert together_span.attributes.get("gen_ai.usage.input_tokens") == 9
assert together_span.attributes.get(
"llm.usage.total_tokens"
) == together_span.attributes.get(
"gen_ai.usage.completion_tokens"
) + together_span.attributes.get("gen_ai.usage.prompt_tokens")
"gen_ai.usage.output_tokens"
) + together_span.attributes.get("gen_ai.usage.input_tokens")

logs = log_exporter.get_finished_logs()
assert (
Expand All @@ -66,12 +66,12 @@ def test_alephalpha_completion_with_events_with_content(
assert together_span.attributes.get("gen_ai.system") == "AlephAlpha"
assert together_span.attributes.get("llm.request.type") == "completion"
assert together_span.attributes.get("gen_ai.request.model") == "luminous-base"
assert together_span.attributes.get("gen_ai.usage.prompt_tokens") == 9
assert together_span.attributes.get("gen_ai.usage.input_tokens") == 9
assert together_span.attributes.get(
"llm.usage.total_tokens"
) == together_span.attributes.get(
"gen_ai.usage.completion_tokens"
) + together_span.attributes.get("gen_ai.usage.prompt_tokens")
"gen_ai.usage.output_tokens"
) + together_span.attributes.get("gen_ai.usage.input_tokens")

logs = log_exporter.get_finished_logs()
assert len(logs) == 2
Expand Down Expand Up @@ -116,12 +116,12 @@ def test_alephalpha_completion_with_events_with_no_content(
assert together_span.attributes.get("gen_ai.system") == "AlephAlpha"
assert together_span.attributes.get("llm.request.type") == "completion"
assert together_span.attributes.get("gen_ai.request.model") == "luminous-base"
assert together_span.attributes.get("gen_ai.usage.prompt_tokens") == 9
assert together_span.attributes.get("gen_ai.usage.input_tokens") == 9
assert together_span.attributes.get(
"llm.usage.total_tokens"
) == together_span.attributes.get(
"gen_ai.usage.completion_tokens"
) + together_span.attributes.get("gen_ai.usage.prompt_tokens")
"gen_ai.usage.output_tokens"
) + together_span.attributes.get("gen_ai.usage.input_tokens")

logs = log_exporter.get_finished_logs()
assert len(logs) == 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import _SUPPRESS_INSTRUMENTATION_KEY, unwrap
from opentelemetry.metrics import Counter, Histogram, Meter, get_meter
from opentelemetry.semconv._incubating.attributes import (
gen_ai_attributes as GenAIAttributes,
)
from opentelemetry.semconv_ai import (
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY,
LLMRequestTypeValues,
Expand Down Expand Up @@ -223,7 +226,7 @@ async def _aset_token_usage(
input_tokens,
attributes={
**metric_attributes,
SpanAttributes.LLM_TOKEN_TYPE: "input",
GenAIAttributes.GEN_AI_TOKEN_TYPE: "input",
},
Comment thread
martimfasantos marked this conversation as resolved.
)

Expand All @@ -250,7 +253,7 @@ async def _aset_token_usage(
completion_tokens,
attributes={
**metric_attributes,
SpanAttributes.LLM_TOKEN_TYPE: "output",
GenAIAttributes.GEN_AI_TOKEN_TYPE: "output",
},
)

Expand All @@ -273,18 +276,18 @@ async def _aset_token_usage(
},
)

set_span_attribute(span, SpanAttributes.LLM_USAGE_PROMPT_TOKENS, input_tokens)
set_span_attribute(span, GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
set_span_attribute(
span, SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, completion_tokens
span, GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS, completion_tokens
)
set_span_attribute(span, SpanAttributes.LLM_USAGE_TOTAL_TOKENS, total_tokens)

set_span_attribute(
span, SpanAttributes.LLM_USAGE_CACHE_READ_INPUT_TOKENS, cache_read_tokens
span, GenAIAttributes.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, cache_read_tokens
)
set_span_attribute(
span,
SpanAttributes.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS,
GenAIAttributes.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS,
cache_creation_tokens,
)

Expand Down Expand Up @@ -337,7 +340,7 @@ def _set_token_usage(
input_tokens,
attributes={
**metric_attributes,
SpanAttributes.LLM_TOKEN_TYPE: "input",
GenAIAttributes.GEN_AI_TOKEN_TYPE: "input",
},
)

Expand All @@ -364,7 +367,7 @@ def _set_token_usage(
completion_tokens,
attributes={
**metric_attributes,
SpanAttributes.LLM_TOKEN_TYPE: "output",
GenAIAttributes.GEN_AI_TOKEN_TYPE: "output",
},
)

Expand All @@ -387,18 +390,18 @@ def _set_token_usage(
},
)

set_span_attribute(span, SpanAttributes.LLM_USAGE_PROMPT_TOKENS, input_tokens)
set_span_attribute(span, GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)
set_span_attribute(
span, SpanAttributes.LLM_USAGE_COMPLETION_TOKENS, completion_tokens
span, GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS, completion_tokens
)
set_span_attribute(span, SpanAttributes.LLM_USAGE_TOTAL_TOKENS, total_tokens)

set_span_attribute(
span, SpanAttributes.LLM_USAGE_CACHE_READ_INPUT_TOKENS, cache_read_tokens
span, GenAIAttributes.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, cache_read_tokens
)
set_span_attribute(
span,
SpanAttributes.LLM_USAGE_CACHE_CREATION_INPUT_TOKENS,
GenAIAttributes.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS,
cache_creation_tokens,
)

Expand Down Expand Up @@ -532,7 +535,7 @@ def _wrap(
name,
kind=SpanKind.CLIENT,
attributes={
SpanAttributes.LLM_SYSTEM: "Anthropic",
GenAIAttributes.GEN_AI_SYSTEM: "Anthropic",
SpanAttributes.LLM_REQUEST_TYPE: LLMRequestTypeValues.COMPLETION.value,
},
)
Expand Down Expand Up @@ -656,7 +659,7 @@ async def _awrap(
name,
kind=SpanKind.CLIENT,
attributes={
SpanAttributes.LLM_SYSTEM: "Anthropic",
GenAIAttributes.GEN_AI_SYSTEM: "Anthropic",
SpanAttributes.LLM_REQUEST_TYPE: LLMRequestTypeValues.COMPLETION.value,
},
)
Expand Down
Loading