forked from open-telemetry/opentelemetry-python-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Decorators support #3
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
91pavan
wants to merge
10
commits into
wrisa:instrumentation-genai-langchain-sdk-cleaned
Choose a base branch
from
91pavan:instrumentation-genai-langchain-sdk-cleaned
base: instrumentation-genai-langchain-sdk-cleaned
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 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2f04b96
feat: Add decorator support in GenAI Utils SDK
91pavan da8e986
refactor: remove print statement
91pavan 1c56a53
feat: reuse the telemetry client in api.py and only set the trace pro…
91pavan 498db98
feat: call start_llm before the call is actually made
91pavan 56a11da
feat: remove publishing conversational content as span attributes in …
91pavan 04d2fcb
Merge branch 'instrumentation-genai-langchain-sdk-cleaned' into instr…
91pavan 6cc8dbb
Merge branch 'instrumentation-genai-langchain-sdk-cleaned' of https:/…
91pavan 6bed2df
feat: bug fixes and improvements
91pavan eead667
fix merge conflict
91pavan 60c7a00
feat: remove Otel SDK references
91pavan 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
170 changes: 170 additions & 0 deletions
170
instrumentation-genai/opentelemetry-genai-sdk/.gitignore
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,170 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Mac files | ||
.DS_Store | ||
|
||
# Environment variables | ||
.env | ||
|
||
# sqlite database files | ||
*.db | ||
*.db-shm | ||
*.db-wal | ||
|
||
# PNG files | ||
*.png | ||
|
||
demo/ | ||
|
||
.ruff_cache | ||
|
||
.vscode/ | ||
|
||
output/ | ||
|
||
.terraform.lock.hcl | ||
.terraform/ | ||
foo.sh | ||
tfplan | ||
tfplan.txt | ||
tfplan.json | ||
terraform_output.json | ||
|
||
|
||
# IntelliJ / PyCharm | ||
.idea | ||
|
||
|
||
*.txt | ||
|
||
.dockerconfigjson | ||
|
||
app/src/bedrock_agent/deploy |
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
140 changes: 140 additions & 0 deletions
140
...entation-genai/opentelemetry-genai-sdk/src/opentelemetry/genai/sdk/decorators/__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,140 @@ | ||
import inspect | ||
from typing import Optional, Union, TypeVar, Callable, Awaitable | ||
|
||
from typing_extensions import ParamSpec | ||
|
||
from opentelemetry.genai.sdk.decorators.base import ( | ||
entity_class, | ||
entity_method, | ||
) | ||
from opentelemetry.genai.sdk.utils.const import ( | ||
ObserveSpanKindValues, | ||
) | ||
|
||
P = ParamSpec("P") | ||
R = TypeVar("R") | ||
F = TypeVar("F", bound=Callable[P, Union[R, Awaitable[R]]]) | ||
|
||
|
||
def task( | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
version: Optional[int] = None, | ||
protocol: Optional[str] = None, | ||
method_name: Optional[str] = None, | ||
tlp_span_kind: Optional[ObserveSpanKindValues] = ObserveSpanKindValues.TASK, | ||
) -> Callable[[F], F]: | ||
def decorator(target): | ||
# Check if target is a class | ||
if inspect.isclass(target): | ||
return entity_class( | ||
name=name, | ||
description=description, | ||
version=version, | ||
protocol=protocol, | ||
method_name=method_name, | ||
tlp_span_kind=tlp_span_kind, | ||
)(target) | ||
else: | ||
# Target is a function/method | ||
return entity_method( | ||
name=name, | ||
description=description, | ||
version=version, | ||
protocol=protocol, | ||
tlp_span_kind=tlp_span_kind, | ||
)(target) | ||
return decorator | ||
|
||
|
||
def workflow( | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
version: Optional[int] = None, | ||
protocol: Optional[str] = None, | ||
method_name: Optional[str] = None, | ||
tlp_span_kind: Optional[ | ||
Union[ObserveSpanKindValues, str] | ||
] = ObserveSpanKindValues.WORKFLOW, | ||
) -> Callable[[F], F]: | ||
def decorator(target): | ||
# Check if target is a class | ||
if inspect.isclass(target): | ||
return entity_class( | ||
name=name, | ||
description=description, | ||
version=version, | ||
protocol=protocol, | ||
method_name=method_name, | ||
tlp_span_kind=tlp_span_kind, | ||
)(target) | ||
else: | ||
# Target is a function/method | ||
return entity_method( | ||
name=name, | ||
description=description, | ||
version=version, | ||
protocol=protocol, | ||
tlp_span_kind=tlp_span_kind, | ||
)(target) | ||
|
||
return decorator | ||
|
||
|
||
def agent( | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
version: Optional[int] = None, | ||
protocol: Optional[str] = None, | ||
method_name: Optional[str] = None, | ||
) -> Callable[[F], F]: | ||
return workflow( | ||
name=name, | ||
description=description, | ||
version=version, | ||
protocol=protocol, | ||
method_name=method_name, | ||
tlp_span_kind=ObserveSpanKindValues.AGENT, | ||
) | ||
|
||
|
||
def tool( | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
version: Optional[int] = None, | ||
method_name: Optional[str] = None, | ||
) -> Callable[[F], F]: | ||
return task( | ||
name=name, | ||
description=description, | ||
version=version, | ||
method_name=method_name, | ||
tlp_span_kind=ObserveSpanKindValues.TOOL, | ||
) | ||
|
||
|
||
def llm( | ||
name: Optional[str] = None, | ||
description: Optional[str] = None, | ||
version: Optional[int] = None, | ||
method_name: Optional[str] = None, | ||
) -> Callable[[F], F]: | ||
def decorator(target): | ||
# Check if target is a class | ||
if inspect.isclass(target): | ||
return entity_class( | ||
name=name, | ||
description=description, | ||
version=version, | ||
method_name=method_name, | ||
tlp_span_kind=ObserveSpanKindValues.LLM, | ||
)(target) | ||
91pavan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else: | ||
# Target is a function/method | ||
return entity_method( | ||
name=name, | ||
description=description, | ||
version=version, | ||
tlp_span_kind=ObserveSpanKindValues.LLM, | ||
)(target) | ||
return decorator |
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.
Uh oh!
There was an error while loading. Please reload this page.