generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 29
feat: Add native Crew AI instrumentation support #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
liustve
wants to merge
16
commits into
main
Choose a base branch
from
crewai-instrumentor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d0569b5
test
liustve e41409d
Merge branch 'main' of https://github.com/aws-observability/aws-otel-…
liustve fe61645
Merge branch 'main' of https://github.com/aws-observability/aws-otel-…
liustve 71d8d6a
Merge branch 'main' of https://github.com/aws-observability/aws-otel-…
liustve 47a8238
Merge branch 'main' of https://github.com/aws-observability/aws-otel-…
liustve d905478
Merge branch 'main' of https://github.com/aws-observability/aws-otel-…
liustve 8cc2103
Merge branch 'main' of https://github.com/aws-observability/aws-otel-…
liustve c65638a
Merge branch 'main' of https://github.com/aws-observability/aws-otel-…
liustve 0ba682e
add native crew ai support
liustve 54389f0
Merge branch 'main' into crewai-instrumentor
liustve 10a40d2
fix import
liustve 84bdeaa
add all unit/contract tests
liustve e802c17
Merge branch 'main' into crewai-instrumentor
liustve ac25fde
remove multi agent span attr
liustve f398aa4
Merge branch 'crewai-instrumentor' of https://github.com/aws-observab…
liustve d1f92da
Merge branch 'main' into crewai-instrumentor
liustve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
aws-opentelemetry-distro/src/amazon/opentelemetry/distro/instrumentation/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
46 changes: 46 additions & 0 deletions
46
aws-opentelemetry-distro/src/amazon/opentelemetry/distro/instrumentation/crewai/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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") | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the method useful?