Skip to content

Conversation

@liustve
Copy link
Contributor

@liustve liustve commented Jan 22, 2026

Description of changes:

  • Adds native OTel instrumentation for CrewAI following OTel's Gen's AI Agent semantic conventions 1.39

  • Instruments and wraps Crew.kickoff, Task._execute_core, and ToolUsage._use methods to generate spans that capture the execution cycle of agentic workflows.

  • Add auto-wiring using OTel's entry points system, so applications using ADOT Python auto-instrumentation will automatically trace CrewAI workflows without any code changes.

Testing

  • Unit tests added
  • Contract tests added
  • Manual E2E test with a CrewAI sample app, example spans shown below:
{
    "resource": {
        "attributes": {
            "aws.local.service": "petclinic-agent",
            "aws.service.type": "gen_ai_agent",
            "telemetry.sdk.language": "python",
            "service.name": "petclinic-agent",
            "telemetry.sdk.version": "1.33.1",
            "telemetry.auto.version": "0.14.1.dev0-aws",
            "telemetry.sdk.name": "opentelemetry"
        }
    },
    "scope": {
        "name": "amazon.opentelemetry.distro.instrumentation.crewai",
        "version": "0.14.1.dev0"
    },
    "traceId": "6972789dd2bc5b849300f34485616656",
    "spanId": "1420fb295a4aebb7",
    "parentSpanId": "218643bcd7c15cea",
    "flags": 256,
    "name": "invoke_agent Pet Triage Specialist",
    "kind": "INTERNAL",
    "startTimeUnixNano": 1769109661451673000,
    "endTimeUnixNano": 1769109669236677000,
    "durationNano": 7785004000,
    "attributes": {
        "aws.local.service": "petclinic-agent",
        "gen_ai.request.temperature": 0.7,
        "gen_ai.operation.name": "invoke_agent",
        "gen_ai.agent.name": "Pet Triage Specialist",
        "gen_ai.request.model": "anthropic.claude-3-haiku-20240307-v1:0",
        "gen_ai.system_instructions": "You are an experienced veterinary triage specialist. You help determine if a pet needs immediate emergency care, a regular appointment, or if the owner can monitor at home. You always err on the side of caution.",
        "PlatformType": "Generic",
        "gen_ai.agent.description": "Assess pet health concerns and determine urgency level",
        "gen_ai.agent.id": "ba3885e8-ea40-41a1-957f-9e0c8ae9e895",
        "gen_ai.provider.name": "aws.bedrock",
        "aws.local.environment": "generic:default"
    },
    "status": {
        "code": "OK"
    }
}
{
    "resource": {
        "attributes": {
            "aws.local.service": "petclinic-agent",
            "aws.service.type": "gen_ai_agent",
            "telemetry.sdk.language": "python",
            "service.name": "petclinic-agent",
            "telemetry.sdk.version": "1.33.1",
            "telemetry.auto.version": "0.14.1.dev0-aws",
            "telemetry.sdk.name": "opentelemetry"
        }
    },
    "scope": {
        "name": "amazon.opentelemetry.distro.instrumentation.crewai",
        "version": "0.14.1.dev0"
    },
    "traceId": "6972789dd2bc5b849300f34485616656",
    "spanId": "218643bcd7c15cea",
    "parentSpanId": "57061b3c07fb6398",
    "flags": 256,
    "name": "crew_kickoff PetClinicCrew",
    "kind": "INTERNAL",
    "startTimeUnixNano": 1769109661438292000,
    "endTimeUnixNano": 1769109675162985000,
    "durationNano": 13724693000,
    "attributes": {
        "aws.local.service": "petclinic-agent",
        "gen_ai.operation.name": "invoke_agent",
        "gen_ai.agent.name": "PetClinicCrew",
        "PlatformType": "Generic",
        "gen_ai.agent.id": "53da431a-ecf5-4ae2-bac7-848cfbfe43e8",
        "gen_ai.tool.definitions": "[{\"type\": \"function\", \"name\": \"get_emergency_contact\", \"description\": \"Tool Name: get_emergency_contact\\nTool Arguments: {\\n  \\\"properties\\\": {},\\n  \\\"title\\\": \\\"Get_Emergency_Contact\\\",\\n  \\\"type\\\": \\\"object\\\",\\n  \\\"additionalProperties\\\": false\\n}\\nTool Description: Get emergency contact information.\", \"parameters\": {\"properties\": {}, \"title\": \"Get_Emergency_Contact\", \"type\": \"object\"}}, {\"type\": \"function\", \"name\": \"get_specialist_referral\", \"description\": \"Tool Name: get_specialist_referral\\nTool Arguments: {\\n  \\\"properties\\\": {\\n    \\\"specialty\\\": {\\n      \\\"title\\\": \\\"Specialty\\\",\\n      \\\"type\\\": \\\"string\\\"\\n    }\\n  },\\n  \\\"required\\\": [\\n    \\\"specialty\\\"\\n  ],\\n  \\\"title\\\": \\\"Get_Specialist_Referral\\\",\\n  \\\"type\\\": \\\"object\\\",\\n  \\\"additionalProperties\\\": false\\n}\\nTool Description: Get information about specialist referrals.\", \"parameters\": {\"properties\": {\"specialty\": {\"title\": \"Specialty\", \"type\": \"string\"}}, \"required\": [\"specialty\"], \"title\": \"Get_Specialist_Referral\", \"type\": \"object\"}}, {\"type\": \"function\", \"name\": \"get_clinic_hours\", \"description\": \"Tool Name: get_clinic_hours\\nTool Arguments: {\\n  \\\"properties\\\": {},\\n  \\\"title\\\": \\\"Get_Clinic_Hours\\\",\\n  \\\"type\\\": \\\"object\\\",\\n  \\\"additionalProperties\\\": false\\n}\\nTool Description: Get pet clinic operating hours.\", \"parameters\": {\"properties\": {}, \"title\": \"Get_Clinic_Hours\", \"type\": \"object\"}}, {\"type\": \"function\", \"name\": \"get_emergency_contact\", \"description\": \"Tool Name: get_emergency_contact\\nTool Arguments: {\\n  \\\"properties\\\": {},\\n  \\\"title\\\": \\\"Get_Emergency_Contact\\\",\\n  \\\"type\\\": \\\"object\\\",\\n  \\\"additionalProperties\\\": false\\n}\\nTool Description: Get emergency contact information.\", \"parameters\": {\"properties\": {}, \"title\": \"Get_Emergency_Contact\", \"type\": \"object\"}}, {\"type\": \"function\", \"name\": \"get_specialist_referral\", \"description\": \"Tool Name: get_specialist_referral\\nTool Arguments: {\\n  \\\"properties\\\": {\\n    \\\"specialty\\\": {\\n      \\\"title\\\": \\\"Specialty\\\",\\n      \\\"type\\\": \\\"string\\\"\\n    }\\n  },\\n  \\\"required\\\": [\\n    \\\"specialty\\\"\\n  ],\\n  \\\"title\\\": \\\"Get_Specialist_Referral\\\",\\n  \\\"type\\\": \\\"object\\\",\\n  \\\"additionalProperties\\\": false\\n}\\nTool Description: Get information about specialist referrals.\", \"parameters\": {\"properties\": {\"specialty\": {\"title\": \"Specialty\", \"type\": \"string\"}}, \"required\": [\"specialty\"], \"title\": \"Get_Specialist_Referral\", \"type\": \"object\"}}, {\"type\": \"function\", \"name\": \"get_appointment_availability\", \"description\": \"Tool Name: get_appointment_availability\\nTool Arguments: {\\n  \\\"properties\\\": {},\\n  \\\"title\\\": \\\"Get_Appointment_Availability\\\",\\n  \\\"type\\\": \\\"object\\\",\\n  \\\"additionalProperties\\\": false\\n}\\nTool Description: Check current appointment availability.\", \"parameters\": {\"properties\": {}, \"title\": \"Get_Appointment_Availability\", \"type\": \"object\"}}]",
        "aws.local.environment": "generic:default"
    },
    "status": {
        "code": "OK"
    }
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@liustve liustve requested a review from a team as a code owner January 22, 2026 01:35
@liustve liustve marked this pull request as draft January 22, 2026 01:49
@liustve liustve marked this pull request as ready for review January 22, 2026 22:02
@liustve liustve force-pushed the crewai-instrumentor branch from a059c3e to 84bdeaa Compare January 22, 2026 23:59
Note: Semantic conventions may change in future versions.
"""

def instrumentation_dependencies(self) -> Collection[str]: # pylint: disable=no-self-use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the method useful?

from crewai.tools.structured_tool import CrewStructuredTool
from crewai.tools.tool_calling import ToolCalling
from crewai.tools.tool_usage import ToolUsage
from pydantic import BaseModel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pydantic might be architecture incompatibility, bring in trouble if we want to support one-click enablement. Is it required?

GEN_AI_TOOL_DEFINITIONS,
GEN_AI_TOOL_DESCRIPTION,
GEN_AI_TOOL_NAME,
GEN_AI_TOOL_TYPE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these except GEN_AI_PROVIDER_NAME, GEN_AI_SYSTEM_INSTRUCTIONS, GEN_AI_TOOL_CALL_ARGUMENTS, GEN_AI_TOOL_CALL_RESULT, and.GEN_AI_TOOL_DEFINITIONS are available in the 1.33.1/0.54b1 version of Otel we depend on.

P.S we should do an Otel version bump (see nightly build) to get the latest version of opentelemetry-semantic-coonventions where all of these attributes are available.

"claude": "anthropic",
"azure": "azure.ai.openai",
"azure_openai": "azure.ai.openai",
"google": "gcp.vertex_ai",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gcp.vertex_ai should be the mapping for Vertex AI specifically. gcp.gen_ai is the generic Google fallback per https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants