Skip to content
Closed
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
@@ -1,4 +1,14 @@
from opentelemetry.trace import Span
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import (
GEN_AI_REQUEST_FREQUENCY_PENALTY,
GEN_AI_REQUEST_MAX_TOKENS,
GEN_AI_REQUEST_MODEL,
GEN_AI_REQUEST_PRESENCE_PENALTY,
GEN_AI_REQUEST_SEED,
GEN_AI_REQUEST_STOP_SEQUENCES,
GEN_AI_REQUEST_TEMPERATURE,
GEN_AI_REQUEST_TOP_P,
)
from opentelemetry.semconv_ai import SpanAttributes
import json

Expand Down Expand Up @@ -63,19 +73,25 @@ def _process_llm(self):
if value is None:
continue
if field == "model":
self._set_attribute(SpanAttributes.LLM_REQUEST_MODEL, value)
self._set_attribute(GEN_AI_REQUEST_MODEL, value)
elif field == "temperature":
self._set_attribute(SpanAttributes.LLM_REQUEST_TEMPERATURE, value)
self._set_attribute(GEN_AI_REQUEST_TEMPERATURE, value)
elif field == "top_p":
self._set_attribute(SpanAttributes.LLM_REQUEST_TOP_P, value)
self._set_attribute(GEN_AI_REQUEST_TOP_P, value)
elif field == "max_tokens":
self._set_attribute(SpanAttributes.LLM_REQUEST_MAX_TOKENS, value)
self._set_attribute(GEN_AI_REQUEST_MAX_TOKENS, value)
elif field == "presence_penalty":
self._set_attribute(SpanAttributes.LLM_PRESENCE_PENALTY, value)
self._set_attribute(GEN_AI_REQUEST_PRESENCE_PENALTY, value)
elif field == "frequency_penalty":
self._set_attribute(SpanAttributes.LLM_FREQUENCY_PENALTY, value)
else:
self._set_attribute(f"llm.{field}", value)
self._set_attribute(GEN_AI_REQUEST_FREQUENCY_PENALTY, value)
elif field == "seed":
self._set_attribute(GEN_AI_REQUEST_SEED, value)
elif field == "stop":
self._set_attribute(GEN_AI_REQUEST_STOP_SEQUENCES, value)
elif field == "n":
self._set_attribute(SpanAttributes.GEN_AI_REQUEST_N, value)
elif field == "max_completion_tokens":
self._set_attribute(SpanAttributes.GEN_AI_REQUEST_MAX_COMPLETION_TOKENS, value)

def _populate_crew_attributes(self):
for key, value in self.instance.__dict__.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from opentelemetry.semconv._incubating.attributes import (
gen_ai_attributes as GenAIAttributes,
)
from opentelemetry.semconv._incubating.attributes.gen_ai_attributes import GEN_AI_PROVIDER_NAME
from opentelemetry.semconv_ai import SpanAttributes, TraceloopSpanKindValues, Meters
from .crewai_span_attributes import CrewAISpanAttributes, set_span_attribute

Expand Down Expand Up @@ -69,6 +70,7 @@ def wrap_kickoff(tracer: Tracer, duration_histogram: Histogram, token_histogram:
kind=SpanKind.INTERNAL,
attributes={
GenAIAttributes.GEN_AI_SYSTEM: "crewai",
GEN_AI_PROVIDER_NAME: "crewai",
}
) as span:
try:
Expand Down Expand Up @@ -96,6 +98,8 @@ def wrap_agent_execute_task(tracer, duration_histogram, token_histogram, wrapped
kind=SpanKind.CLIENT,
attributes={
SpanAttributes.TRACELOOP_SPAN_KIND: TraceloopSpanKindValues.AGENT.value,
GenAIAttributes.GEN_AI_SYSTEM: "crewai",
GEN_AI_PROVIDER_NAME: "crewai",
}
) as span:
try:
Expand Down Expand Up @@ -157,6 +161,8 @@ def wrap_llm_call(tracer, duration_histogram, token_histogram, wrapped, instance
f"{llm}.llm",
kind=SpanKind.CLIENT,
attributes={
GenAIAttributes.GEN_AI_SYSTEM: "crewai",
GEN_AI_PROVIDER_NAME: "crewai",
}
) as span:
start_time = time.time()
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry-instrumentation-crewai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ select = ["E", "F", "W"]

[tool.uv]
constraint-dependencies = ["urllib3>=2.6.3", "pip>=25.3"]

[tool.uv.sources]
opentelemetry-semantic-conventions-ai = { path = "../opentelemetry-semantic-conventions-ai", editable = true }
Loading
Loading