Skip to content

Commit

Permalink
Feature/684 Python Telemetry (#773)
Browse files Browse the repository at this point in the history
* Python Telemetry

* Add span function

* update ci

* add sample test
  • Loading branch information
neoxelox authored Jan 15, 2025
1 parent 6253121 commit 57791fc
Show file tree
Hide file tree
Showing 31 changed files with 2,370 additions and 11 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ jobs:
- name: Install Node.js dependencies
run: pnpm install

# TODO: We should probably separate node from python jobs
- name: Install Python dependencies
working-directory: packages/sdks/python
run: |
cd packages/sdks/python
uv venv
uv sync --all-extras --all-groups
cd ../../telemetry/python
uv venv
uv sync --all-extras --all-groups
Expand All @@ -80,8 +84,10 @@ jobs:
run: pnpm lint

- name: Python Lint
working-directory: packages/sdks/python
run: |
cd packages/sdks/python
uv run scripts/lint.py
cd ../../telemetry/python
uv run scripts/lint.py
- name: TypeScript
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ jobs:
- name: Install Node.js dependencies
run: pnpm install

# TODO: We should probably separate node from python jobs
- name: Install Python dependencies
working-directory: packages/sdks/python
run: |
cd packages/sdks/python
uv venv
uv sync --all-extras --all-groups
cd ../../telemetry/python
uv venv
uv sync --all-extras --all-groups
Expand All @@ -106,6 +110,8 @@ jobs:
run: pnpm test

- name: Python Test
working-directory: packages/sdks/python
run: |
cd packages/sdks/python
uv run scripts/test.py
cd ../../telemetry/python
uv run scripts/test.py
2 changes: 1 addition & 1 deletion packages/sdks/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dev = [
"pytest-xdist>=3.6.1",
"pytest>=8.3.4",
"respx>=0.22.0",
"pyright>=1.1.391",
"pyright>=1.1.392",
"ruff>=0.8.3",
"sh>=1.14.3",
]
Expand Down
12 changes: 10 additions & 2 deletions packages/sdks/python/src/latitude_sdk/util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Callable, List, TypeVar

import pydantic
from typing_extensions import ParamSpec
from typing_extensions import ParamSpec, Self

T = TypeVar("T", str, bool, int, List[str])

Expand Down Expand Up @@ -49,7 +49,15 @@ def __str__(self) -> str:
return str(self.value)

@classmethod
def list(cls) -> List[str]:
def entries(cls) -> List[Self]:
return list(cls)

@classmethod
def names(cls) -> List[str]:
return [v.name for v in cls]

@classmethod
def values(cls) -> List[str]:
return [v.value for v in cls]


Expand Down
8 changes: 4 additions & 4 deletions packages/sdks/python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 141 additions & 0 deletions packages/telemetry/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Custom
.vscode/
.superinvoke_cache/
.idea/
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
.DS_Store
*.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
*.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

# pyenv
-

# pdm
.pdm.toml

# PEP 582
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

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

# Ruff
.ruff_cache/
1 change: 1 addition & 0 deletions packages/telemetry/python/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.21
33 changes: 33 additions & 0 deletions packages/telemetry/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Latitude Telemetry for Python

```sh
pip install latitude-telemetry
```

Requires Python `3.9` or higher.

Go to the [documentation](TODO) to learn more.

## Usage

```python
TODO
```

Find more [examples](TODO).

## Development

Requires uv `0.5.10` or higher.

- Install dependencies: `uv venv && uv sync --all-extras --all-groups`
- Add [dev] dependencies: `uv add [--dev] <package>`
- Run linter: `uv run scripts/lint.py`
- Run formatter: `uv run scripts/format.py`
- Run tests: `uv run scripts/test.py`
- Build package: `uv build`
- Publish package: `uv publish`

## License

The Telemetry is licensed under the [LGPL-3.0 License](https://opensource.org/licenses/LGPL-3.0) - read the [LICENSE](/LICENSE) file for details.
90 changes: 90 additions & 0 deletions packages/telemetry/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[project]
name = "latitude-telemetry"
version = "0.1.0-beta.1"
description = "Latitude Telemetry for Python"
authors = [{ name = "Latitude Data SL", email = "[email protected]" }]
maintainers = [{ name = "Latitude Data SL", email = "[email protected]" }]
readme = "README.md"
license = "LGPL-3.0"
urls.repository = "https://github.com/latitude-dev/latitude-llm/tree/main/packages/telemetry/python"
urls.homepage = "https://github.com/latitude-dev/latitude-llm/tree/main/packages/telemetry/python#readme"
urls.documentation = "https://github.com/latitude-dev/latitude-llm/tree/main/packages/telemetry/python#readme"
requires-python = ">=3.9"
dependencies = [
"opentelemetry-api>=1.29.0",
"opentelemetry-sdk>=1.29.0",
"opentelemetry-instrumentation-alephalpha>=0.36.0",
"opentelemetry-instrumentation-anthropic>=0.36.0",
"opentelemetry-instrumentation-bedrock>=0.36.0",
"opentelemetry-instrumentation-cohere>=0.36.0",
"opentelemetry-instrumentation-google-generativeai>=0.36.0",
"opentelemetry-instrumentation-groq>=0.36.0",
"opentelemetry-instrumentation-haystack>=0.36.0",
"opentelemetry-instrumentation-langchain>=0.36.0",
"openinference-instrumentation-litellm>=0.1.5",
"opentelemetry-instrumentation-llamaindex>=0.36.0",
"opentelemetry-instrumentation-mistralai>=0.36.0",
"opentelemetry-instrumentation-ollama>=0.36.0",
"opentelemetry-instrumentation-openai>=0.36.0",
"opentelemetry-instrumentation-replicate>=0.36.0",
"opentelemetry-instrumentation-sagemaker>=0.36.0",
"opentelemetry-instrumentation-together>=0.36.0",
"opentelemetry-instrumentation-threading>=0.50b0",
"opentelemetry-instrumentation-transformers>=0.36.0",
"opentelemetry-instrumentation-vertexai>=0.36.0",
"opentelemetry-instrumentation-watsonx>=0.36.0",
"httpx>=0.27.2",
"pydantic>=2.10.3",
"typing-extensions>=4.12.2",
]

[dependency-groups]
dev = [
"pytest-asyncio>=0.24.0",
"pytest-xdist>=3.6.1",
"pytest>=8.3.4",
"respx>=0.22.0",
"pyright>=1.1.392",
"ruff>=0.8.3",
"sh>=1.14.3",
]

[tool.pyright]
pythonVersion = "3.9"
typeCheckingMode = "strict"
reportMissingTypeStubs = false
reportUnnecessaryIsInstance = false
reportPrivateUsage = false

[tool.ruff]
target-version = "py39"
line-length = 120
indent-width = 4

[tool.ruff.lint]
select = ["B", "C4", "E", "F", "I", "W", "UP"]
ignore = [
"F401",
"F403",
# Needed because unnecessary str() on field aliases are needed
# https://docs.pydantic.dev/2.8/concepts/fields/#field-aliases
"UP018",
# Needed because typing.List and typing.Dict are semi-deprecated
# in new Python versions but we want to maintain compatibility
"UP006",
"UP035",
]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"

[tool.pytest.ini_options]
addopts = "-p no:warnings -n auto"
xfail_strict = true
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
8 changes: 8 additions & 0 deletions packages/telemetry/python/scripts/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys

from sh import ruff # type: ignore

files = sys.argv[1:] or ["."]

ruff("check", "--fix", *files, _out=sys.stdout)
ruff("format", *files, _out=sys.stdout)
Loading

0 comments on commit 57791fc

Please sign in to comment.