Skip to content

Commit

Permalink
fix: wrong imports and missing code components (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
galkleinman authored Sep 6, 2023
1 parent 6b68bc3 commit bd70a22
Show file tree
Hide file tree
Showing 24 changed files with 586 additions and 111 deletions.
130 changes: 129 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,132 @@ Thumbs.db
reports/
.vscode/

.env
# 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/
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/
cover/

# 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
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__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/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "opentelemetry-instrumentation-chromadb",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "packages/opentelemetry-instrumentation-chromadb/opentelemetry_instrumentation_chromadb",
"sourceRoot": "packages/opentelemetry-instrumentation-chromadb/opentelemetry/instrumentation/chromadb",
"targets": {
"lock": {
"executor": "@nxlv/python:run-commands",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-instrumentation-cohere/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "opentelemetry-instrumentation-cohere",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "packages/opentelemetry-instrumentation-cohere/opentelemetry_instrumentation_cohere",
"sourceRoot": "packages/opentelemetry-instrumentation-cohere/opentelemetry/instrumentation/cohere",
"targets": {
"lock": {
"executor": "@nxlv/python:run-commands",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
unwrap,
)

from traceloop.semconv import SpanAttributes, LLMRequestTypeValues
from opentelemetry.semconv.llm import SpanAttributes, LLMRequestTypeValues

logger = logging.getLogger(__name__)

_instruments = ("openai ~= 0.27.8",)
_instruments = ("openai >= 0.27.0",)
__version__ = "0.1.0"

WRAPPED_METHODS = [
Expand All @@ -42,9 +42,11 @@ def _set_span_attribute(span, name, value):


def _set_api_attributes(span):
_set_span_attribute(span, SpanAttributes.OPENAI_API_BASE, openai.api_base)
_set_span_attribute(span, SpanAttributes.OPENAI_API_TYPE, openai.api_type)
_set_span_attribute(span, SpanAttributes.OPENAI_API_VERSION, openai.api_version)
_set_span_attribute(span, OpenAISpanAttributes.OPENAI_API_BASE, openai.api_base)
_set_span_attribute(span, OpenAISpanAttributes.OPENAI_API_TYPE, openai.api_type)
_set_span_attribute(
span, OpenAISpanAttributes.OPENAI_API_VERSION, openai.api_version
)

return

Expand Down Expand Up @@ -194,6 +196,12 @@ def _wrap(tracer, to_wrap, wrapped, instance, args, kwargs):
return response


class OpenAISpanAttributes:
OPENAI_API_VERSION = "openai.api_version"
OPENAI_API_BASE = "openai.api_base"
OPENAI_API_TYPE = "openai.api_type"


class OpenAIInstrumentor(BaseInstrumentor):
"""An instrumentor for OpenAI's client library."""

Expand Down
5 changes: 1 addition & 4 deletions packages/opentelemetry-instrumentation-openai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ python = ">=3.8.1,<3.12"
openai = "^0.28.0"
opentelemetry-api = "^1.19.0"
opentelemetry-instrumentation = "^0.40b0"

[tool.poetry.dependencies.opentelemetry-semantic-conventions-llm]
path = "../opentelemetry-semantic-conventions-llm"
develop = true
opentelemetry-semantic-conventions-llm = "^0.0.2"

[tool.poetry.group.dev.dependencies]
autopep8 = "2.0.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ include = "opentelemetry/instrumentation/pinecone"
python = ">=3.8.1,<3.12"
opentelemetry-api = "^1.19.0"
opentelemetry-instrumentation = "^0.40b0"

[tool.poetry.dependencies.opentelemetry-semantic-conventions-llm]
path = "../opentelemetry-semantic-conventions-llm"
develop = true
opentelemetry-semantic-conventions-llm = "^0.0.2"

[tool.poetry.group.dev.dependencies]
autopep8 = "2.0.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "opentelemetry-instrumentation-vertexai",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "packages/opentelemetry-instrumentation-vertexai/opentelemetry_instrumentation_vertexai",
"sourceRoot": "packages/opentelemetry-instrumentation-vertexai/opentelemetry/instrumentation/vertexai",
"targets": {
"lock": {
"executor": "@nxlv/python:run-commands",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "opentelemetry-instrumentation-weaviate",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "packages/opentelemetry-instrumentation-weaviate/opentelemetry_instrumentation_weaviate",
"sourceRoot": "packages/opentelemetry-instrumentation-weaviate/opentelemetry/instrumentation/weaviate",
"targets": {
"lock": {
"executor": "@nxlv/python:run-commands",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ class SpanAttributes:
LLM_COMPLETIONS = "llm.completions"
LLM_CHAT_STOP_SEQUENCES = "llm.chat.stop_sequences"

# OpenAI
OPENAI_API_VERSION = "openai.api_version"
OPENAI_API_BASE = "openai.api_base"
OPENAI_API_TYPE = "openai.api_type"


class LLMRequestTypeValues(Enum):
COMPLETION = "completion"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ addopts = "--cov --cov-report html:'../../coverage/packages/opentelemetry-semant

[tool.poetry]
name = "opentelemetry-semantic-conventions-llm"
version = "0.0.1"
version = "0.0.2"
description = "OpenTelemetry Semantic Conventions Extension for Large Language Models"
authors = [
"Gal Kleinman <gal@traceloop.com>",
Expand Down
Loading

0 comments on commit bd70a22

Please sign in to comment.