Skip to content
Open
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
8 changes: 8 additions & 0 deletions .coveragerc-py39
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[run]
omit =
*/instrumentation/crewai/*

[report]
include_namespace_packages = true
fail_under = 95.00
precision = 2
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ If your change does not need a CHANGELOG entry, add the "skip changelog" label t

## Unreleased

- Add native CrewAI instrumentation support
([#586](https://github.com/aws-observability/aws-otel-python-instrumentation/pull/586))
- Fix: Support new fields in X-Ray API responses
([#577](https://github.com/aws-observability/aws-otel-python-instrumentation/pull/577))
- Sign Lambda layer by AWS Signer
Expand Down
3 changes: 3 additions & 0 deletions aws-opentelemetry-distro/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ aws_configurator = "amazon.opentelemetry.distro.aws_opentelemetry_configurator:A
[project.entry-points.opentelemetry_distro]
aws_distro = "amazon.opentelemetry.distro.aws_opentelemetry_distro:AwsOpenTelemetryDistro"

[project.entry-points.opentelemetry_instrumentor]
crewai = "amazon.opentelemetry.distro.instrumentation.crewai:CrewAIInstrumentor"

[project.urls]
Homepage = "https://github.com/aws-observability/aws-otel-python-instrumentation/tree/main/aws-opentelemetry-distro"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@
SERVICE_METRIC,
MetricAttributeGenerator,
)
from amazon.opentelemetry.distro.patches.semconv._incubating.attributes.gen_ai_attributes import (
from amazon.opentelemetry.distro.regional_resource_arn_parser import RegionalResourceArnParser
from amazon.opentelemetry.distro.semconv._incubating.attributes.gen_ai_attributes import (
GEN_AI_BROWSER_ID,
GEN_AI_CODE_INTERPRETER_ID,
GEN_AI_GATEWAY_ID,
GEN_AI_MEMORY_ID,
GEN_AI_RUNTIME_ID,
)
from amazon.opentelemetry.distro.regional_resource_arn_parser import RegionalResourceArnParser
from amazon.opentelemetry.distro.sqs_url_parser import SqsUrlParser
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import BoundedAttributes, ReadableSpan
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Collection

from wrapt import wrap_function_wrapper

from amazon.opentelemetry.distro.instrumentation.crewai._wrappers import (
_CrewKickoffWrapper,
_TaskExecuteCoreWrapper,
_ToolUseWrapper,
)
from amazon.opentelemetry.distro.version import __version__
from opentelemetry import trace
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import unwrap


class CrewAIInstrumentor(BaseInstrumentor):
"""
OpenTelemetry instrumentor for CrewAI.

Instrumentation currently follows OpenTelemetry semantic conventions v1.39 for gen_ai attributes.
See: https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/
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?

return ("crewai >= 0.41.0",)

# disabling these linters rules as these are instance methods from BaseInstrumentor
def _instrument(self, **kwargs: Any) -> None: # pylint: disable=no-self-use
tracer_provider = kwargs.get("tracer_provider") or trace.get_tracer_provider()
tracer = trace.get_tracer(__name__, __version__, tracer_provider=tracer_provider)

wrap_function_wrapper("crewai", "Crew.kickoff", _CrewKickoffWrapper(tracer))
wrap_function_wrapper("crewai", "Task._execute_core", _TaskExecuteCoreWrapper(tracer))
wrap_function_wrapper("crewai.tools.tool_usage", "ToolUsage._use", _ToolUseWrapper(tracer))

def _uninstrument(self, **kwargs: Any) -> None: # pylint: disable=no-self-use
# pylint: disable=import-outside-toplevel
import crewai
from crewai.tools import tool_usage

unwrap(crewai.Crew, "kickoff")
unwrap(crewai.Task, "_execute_core")
unwrap(tool_usage.ToolUsage, "_use")
Loading
Loading