Skip to content
Closed
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
12 changes: 10 additions & 2 deletions agentops/instrumentation/crewai/instrumentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from agentops.instrumentation.crewai.version import __version__
from agentops.semconv import SpanAttributes, AgentOpsSpanKindValues, Meters, ToolAttributes, MessageAttributes
from .crewai_span_attributes import CrewAISpanAttributes, set_span_attribute
from agentops import get_client

Check warning on line 17 in agentops/instrumentation/crewai/instrumentation.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/crewai/instrumentation.py#L17

Added line #L17 was not covered by tests


# Initialize logger
Expand Down Expand Up @@ -380,14 +381,21 @@
def wrap_task_execute(
tracer, duration_histogram, token_histogram, environment, application_name, wrapped, instance, args, kwargs
):
task_name = instance.description if hasattr(instance, "description") else "task"
# Get the span name from default tags if available
config = get_client().config
span_name = "crewai.task"
if config.default_tags and len(config.default_tags) > 0:

Check warning on line 387 in agentops/instrumentation/crewai/instrumentation.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/crewai/instrumentation.py#L385-L387

Added lines #L385 - L387 were not covered by tests
# Get the first tag from the set
first_tag = next(iter(config.default_tags))
span_name = f"{first_tag}.task"

Check warning on line 390 in agentops/instrumentation/crewai/instrumentation.py

View check run for this annotation

Codecov / codecov/patch

agentops/instrumentation/crewai/instrumentation.py#L389-L390

Added lines #L389 - L390 were not covered by tests

with tracer.start_as_current_span(
f"{task_name}.task",
kind=SpanKind.CLIENT,
attributes={
SpanAttributes.AGENTOPS_SPAN_KIND: AgentOpsSpanKindValues.TASK.value,
SpanAttributes.OPERATION_NAME: span_name,
},
name=span_name,
) as span:
try:
span.set_attribute(TELEMETRY_SDK_NAME, "agentops")
Expand Down
Loading