mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2026-03-13 08:10:39 +08:00
* Add initial implementation of Anthropic Agents instrumentation - Introduced `opentelemetry-instrumentation-anthropic-agents` package for tracing LLM requests using the Anthropic Python SDK. - Added support for capturing request and response attributes in accordance with GenAI semantic conventions. - Included examples for both manual and zero-code instrumentation. - Created a CHANGELOG.md to document notable changes. - Added LICENSE and README files for package details and usage instructions. This commit lays the groundwork for enhanced observability in applications utilizing Anthropic's capabilities. * Enhance instrumentation for Anthropic Agents - Added support for the `opentelemetry-instrumentation-anthropic-agents` package, enabling tracing of requests made through the Claude Agent SDK. - Updated `pyproject.toml` and `tox.ini` to include new test environments and dependencies for the Anthropic Agents instrumentation. - Modified GitHub workflows to incorporate linting and testing for the new instrumentation. - Improved documentation in README files and examples to reflect changes in usage and setup. - Introduced new examples demonstrating both manual and zero-code instrumentation approaches. This commit strengthens observability for applications utilizing Claude Agents, ensuring comprehensive tracing and logging capabilities. * Remove outdated entries from CHANGELOG.md for Anthropic Agents instrumentation, streamlining the document to reflect current features and improvements. * Update Anthropic Agents instrumentation to use Claude Agent SDK - Changed dependency from `anthropic >= 0.16.0` to `claude-agent-sdk >= 0.1.14` in `README.md`, `pyproject.toml`, and related files. - Refactored `AnthropicAgentsInstrumentor` to align with the new SDK, including updates to initialization and logging. - Removed unused utility functions and cleaned up test configurations to reflect the new dependency. - Updated tests to ensure compatibility with the Claude Agent SDK. This commit enhances the instrumentation for applications using the Claude Agent SDK, ensuring accurate tracing and logging capabilities. * Update Python version requirements and clean up workflows for Anthropic Agents instrumentation - Updated `tox.ini` and `pyproject.toml` to require Python 3.10 or higher, removing support for Python 3.9. - Cleaned up GitHub workflows by removing outdated test jobs for Python 3.9 and adding new jobs for Python 3.10. - Updated `README.md` to reflect the new dependency on `claude-agent-sdk` and removed references to the old SDK. - Made minor code cleanups in example scripts and test files to improve readability. These changes ensure compatibility with the latest Python versions and streamline the testing process for the Anthropic Agents instrumentation. * Add Anirudha as a component owner for Anthropic instrumentation. * fixing precommit errors. * Update version comment in `version.py` to indicate future stable release * Refactor imports in `__init__.py` for Anthropic Agents instrumentation. * regenerate uv.lock file. * Update uv.lock to standardize package source URLs with trailing slashes * Rename instrumentation for Anthropic Agents to Claude Agent SDK, updating references in configuration files, workflows, and documentation. Add new files for the Claude Agent SDK instrumentation, including README, examples, and changelog. Ensure proper setup for testing and linting in CI/CD workflows. * Update release documentation and workflows to include new instrumentation for Anthropic and Claude Agent SDK. * Add Mike Goldsmith as a component owner for Anthropic and Claude Agent SDK instrumentation * Revert "Merge remote-tracking branch 'upstream/main' into feat/anthropic-agents-boilerplate" This reverts commit7ed01ecb2d, reversing changes made to7e83cd7d74. * Reapply "Merge remote-tracking branch 'upstream/main' into feat/anthropic-agents-boilerplate" This reverts commit7714e3c544. * Update Python version in workflows and adjust dependencies in uv.lock. * Fix source URLs in uv.lock to ensure proper registry formatting.
155 lines
5.7 KiB
Python
Executable File
155 lines
5.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# Copyright The OpenTelemetry Authors
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import ast
|
|
import logging
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
import astor
|
|
from otel_packaging import (
|
|
get_instrumentation_packages,
|
|
root_path,
|
|
scripts_path,
|
|
)
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger("instrumentation_list_generator")
|
|
|
|
_template = """
|
|
{header}
|
|
|
|
# DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM INSTRUMENTATION PACKAGES.
|
|
# RUN `python scripts/generate_instrumentation_bootstrap.py` TO REGENERATE.
|
|
|
|
{source}
|
|
"""
|
|
|
|
_source_tmpl = """
|
|
libraries = {}
|
|
default_instrumentations = []
|
|
"""
|
|
|
|
gen_path = os.path.join(
|
|
root_path,
|
|
"opentelemetry-instrumentation",
|
|
"src",
|
|
"opentelemetry",
|
|
"instrumentation",
|
|
"bootstrap_gen.py",
|
|
)
|
|
|
|
packages_to_exclude = [
|
|
# AWS Lambda instrumentation is excluded from the default list because it often
|
|
# requires specific configurations and dependencies that may not be set up
|
|
# in all environments. Instead, users who need AWS Lambda support can opt-in
|
|
# by manually adding it to their environment.
|
|
# See https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2787
|
|
"opentelemetry-instrumentation-aws-lambda",
|
|
# Google GenAI instrumentation is currently excluded because it is still in early
|
|
# development. This filter will get removed once it is further along in its
|
|
# development lifecycle and ready to be included by default.
|
|
"opentelemetry-instrumentation-google-genai",
|
|
# Langchain instrumentation is currently excluded because it is still in early
|
|
# development. This filter will get removed once it is further along in its
|
|
# development lifecycle and ready to be included by default.
|
|
"opentelemetry-instrumentation-langchain",
|
|
# Weaviate instrumentation is currently excluded because it is still in early
|
|
# development. This filter will get removed once it is further along in its
|
|
# development lifecycle and ready to be included by default.
|
|
"opentelemetry-instrumentation-weaviate",
|
|
# OpenAI Agents instrumentation is currently excluded because it is still in early
|
|
# development. This filter will get removed once it is further along in its
|
|
# development lifecycle and ready to be included by default.
|
|
"opentelemetry-instrumentation-openai-agents-v2",
|
|
# Anthropic instrumentation is currently excluded because it is still in early
|
|
# development. This filter will get removed once it is further along in its
|
|
# development lifecycle and ready to be included by default.
|
|
"opentelemetry-instrumentation-anthropic",
|
|
# Anthropic Agents instrumentation is currently excluded because it is still in early
|
|
# development. This filter will get removed once it is further along in its
|
|
# development lifecycle and ready to be included by default.
|
|
"opentelemetry-instrumentation-claude-agent-sdk",
|
|
]
|
|
|
|
# Static version specifiers for instrumentations that are released independently
|
|
independent_packages = {
|
|
"opentelemetry-instrumentation-openai-v2": "",
|
|
"opentelemetry-instrumentation-vertexai": ">=2.0b0",
|
|
"opentelemetry-instrumentation-google-genai": "",
|
|
}
|
|
|
|
|
|
def main():
|
|
# pylint: disable=no-member
|
|
default_instrumentations = ast.List(elts=[])
|
|
libraries = ast.List(elts=[])
|
|
for pkg in get_instrumentation_packages(
|
|
independent_packages=independent_packages
|
|
):
|
|
pkg_name = pkg.get("name")
|
|
if pkg_name in packages_to_exclude:
|
|
continue
|
|
if not pkg["instruments"] and not pkg["instruments-any"]:
|
|
default_instrumentations.elts.append(ast.Str(pkg["requirement"]))
|
|
for target_pkg in pkg["instruments"]:
|
|
libraries.elts.append(
|
|
ast.Dict(
|
|
keys=[ast.Str("library"), ast.Str("instrumentation")],
|
|
values=[ast.Str(target_pkg), ast.Str(pkg["requirement"])],
|
|
)
|
|
)
|
|
# instruments-any is an optional field that can be used instead of or in addition to _instruments. While _instruments is a list of dependencies, all of which are expected by the instrumentation, instruments-any is a list any of which but not all are expected.
|
|
for target_pkg in pkg["instruments-any"]:
|
|
libraries.elts.append(
|
|
ast.Dict(
|
|
keys=[ast.Str("library"), ast.Str("instrumentation")],
|
|
values=[ast.Str(target_pkg), ast.Str(pkg["requirement"])],
|
|
)
|
|
)
|
|
|
|
tree = ast.parse(_source_tmpl)
|
|
tree.body[0].value = libraries
|
|
tree.body[1].value = default_instrumentations
|
|
source = astor.to_source(tree)
|
|
|
|
with open(
|
|
os.path.join(scripts_path, "license_header.txt"), encoding="utf-8"
|
|
) as header_file:
|
|
header = header_file.read()
|
|
source = _template.format(header=header, source=source)
|
|
|
|
with open(gen_path, "w", encoding="utf-8") as gen_file:
|
|
gen_file.write(source)
|
|
|
|
subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"scripts/eachdist.py",
|
|
"format",
|
|
"--path",
|
|
"opentelemetry-instrumentation/src",
|
|
],
|
|
check=True,
|
|
)
|
|
|
|
logger.info("generated %s", gen_path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|