infinity-observability-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ['main']
6
+ pull_request:
7
+
8
+ jobs:
9
+ ci:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.12"
19
+
20
+ - name: Install uv
21
+ uses: astral-sh/setup-uv@v4
22
+
23
+ - name: Run CI
24
+ run: ./scripts/run-ci.sh
25
+
26
+ build:
27
+ runs-on: ubuntu-latest
28
+
29
+ steps:
30
+ - uses: actions/checkout@v4
31
+
32
+ - name: Set up Python
33
+ uses: actions/setup-python@v5
34
+ with:
35
+ python-version: "3.12"
36
+
37
+ - name: Install uv
38
+ uses: astral-sh/setup-uv@v4
39
+
40
+ - name: Install dependencies
41
+ run: uv sync
42
+
43
+ - name: Build package
44
+ run: uv run python -m build
45
+
46
+ - name: Check package with twine
47
+ run: uv run twine check dist/*
48
+
49
+ - name: Upload build artifacts
50
+ uses: actions/upload-artifact@v4
51
+ with:
52
+ name: dist
53
+ path: dist/
54
+
55
+ publish:
56
+ needs: build
57
+ runs-on: ubuntu-latest
58
+ environment: pypi
59
+ permissions:
60
+ id-token: write
61
+
62
+ steps:
63
+ - name: Download build artifacts
64
+ uses: actions/download-artifact@v4
65
+ with:
66
+ name: dist
67
+ path: dist/
68
+
69
+ - name: Publish to PyPI
70
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,51 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ workflow_call:
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+
13
+ - name: Set up Python
14
+ uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+
18
+ - name: Install uv
19
+ uses: astral-sh/setup-uv@v4
20
+
21
+ - name: Install dependencies
22
+ run: uv sync
23
+
24
+ - name: Build package
25
+ run: uv run python -m build
26
+
27
+ - name: Check package with twine
28
+ run: uv run twine check dist/*
29
+
30
+ - name: Upload build artifacts
31
+ uses: actions/upload-artifact@v4
32
+ with:
33
+ name: dist
34
+ path: dist/
35
+
36
+ publish:
37
+ needs: build
38
+ runs-on: ubuntu-latest
39
+ environment: pypi
40
+ permissions:
41
+ id-token: write
42
+
43
+ steps:
44
+ - name: Download build artifacts
45
+ uses: actions/download-artifact@v4
46
+ with:
47
+ name: dist
48
+ path: dist/
49
+
50
+ - name: Publish to PyPI
51
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,217 @@
1
+ __pycache__
2
+
3
+ __pycache__/
4
+ *.py[codz]
5
+ *$py.class
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py.cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # UV
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi
127
+
128
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
129
+ __pypackages__/
130
+
131
+ # Celery stuff
132
+ celerybeat-schedule
133
+ celerybeat.pid
134
+
135
+ # Redis
136
+ *.rdb
137
+ *.aof
138
+ *.pid
139
+
140
+ # RabbitMQ
141
+ mnesia/
142
+ rabbitmq/
143
+ rabbitmq-data/
144
+
145
+ # ActiveMQ
146
+ activemq-data/
147
+
148
+ # SageMath parsed files
149
+ *.sage.py
150
+
151
+ # Environments
152
+ .env
153
+ .envrc
154
+ .venv
155
+ env/
156
+ venv/
157
+ ENV/
158
+ env.bak/
159
+ venv.bak/
160
+
161
+ # Spyder project settings
162
+ .spyderproject
163
+ .spyproject
164
+
165
+ # Rope project settings
166
+ .ropeproject
167
+
168
+ # mkdocs documentation
169
+ /site
170
+
171
+ # mypy
172
+ .mypy_cache/
173
+ .dmypy.json
174
+ dmypy.json
175
+
176
+ # Pyre type checker
177
+ .pyre/
178
+
179
+ # pytype static type analyzer
180
+ .pytype/
181
+
182
+ # Cython debug symbols
183
+ cython_debug/
184
+
185
+ # PyCharm
186
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
187
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
188
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
189
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
190
+ # .idea/
191
+
192
+ # Abstra
193
+ # Abstra is an AI-powered process automation framework.
194
+ # Ignore directories containing user credentials, local state, and settings.
195
+ # Learn more at https://abstra.io/docs
196
+ .abstra/
197
+
198
+ # Visual Studio Code
199
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
200
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
201
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
202
+ # you could uncomment the following to ignore the entire vscode folder
203
+ # .vscode/
204
+
205
+ # Ruff stuff:
206
+ .ruff_cache/
207
+
208
+ # PyPI configuration file
209
+ .pypirc
210
+
211
+ # Marimo
212
+ marimo/_static/
213
+ marimo/_lsp/
214
+ __marimo__/
215
+
216
+ # Streamlit
217
+ .streamlit/secrets.toml
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: infinity-observability-sdk
3
+ Version: 0.1.0
4
+ Summary: Infinity Observability SDK
5
+ License-File: LICENSE
6
+ Requires-Dist: logfire>=4.18.0
7
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.39.1
8
+ Requires-Dist: pytest>=9.0.2
9
+ Requires-Dist: ruff>=0.14.13
10
+ Description-Content-Type: text/markdown
11
+
12
+ # Infinity Observability SDK
@@ -0,0 +1 @@
1
+ # Infinity Observability SDK
@@ -0,0 +1,16 @@
1
+ """
2
+ Infinity Observability SDK
3
+
4
+ Provides standardized observability configuration for Infinity services,
5
+ including OpenTelemetry tracing via logfire with routing to the central
6
+ observability collector.
7
+
8
+ Required environment variables:
9
+ INFINITY_OBSERVABILITY_ENDPOINT: The OTLP collector endpoint
10
+ (e.g., https://observability.staging.infinityconstellation-labs.com)
11
+ SECRET_INFINITY_OBSERVABILITY_API_KEY: API key for authentication
12
+ """
13
+
14
+ from .sdk import configure_observability, agent_context, ObservabilityConfig
15
+
16
+ __all__ = ["configure_observability", "agent_context", "ObservabilityConfig"]
@@ -0,0 +1,115 @@
1
+ import os
2
+ from contextlib import contextmanager
3
+ from dataclasses import dataclass
4
+
5
+ import logfire
6
+ from opentelemetry import trace
7
+ from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
8
+ from opentelemetry.sdk.trace import TracerProvider
9
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor
10
+
11
+
12
+ @dataclass
13
+ class ObservabilityConfig:
14
+ business_unit_name: str
15
+ service_name: str
16
+ instrument_pydantic_ai: bool = True
17
+ instrument_httpx: bool = True
18
+
19
+
20
+ _config: ObservabilityConfig | None = None
21
+
22
+
23
+ @contextmanager
24
+ def agent_context(
25
+ agent_employee_equivalent: str,
26
+ hourly_rate: float,
27
+ agent_name: str,
28
+ task_description: str,
29
+ task_instance_identifier: str,
30
+ approximate_person_hours: float,
31
+ **metadata,
32
+ ):
33
+ global _config
34
+
35
+ if _config is None:
36
+ raise Exception(
37
+ "It looks like the infinity constellation monitoring SDK is not yet configured. Please run configure_observability before adding agent_context"
38
+ )
39
+
40
+ attributes = {
41
+ "infinity_observability_sdk.agent_employee_equivalent": agent_employee_equivalent,
42
+ "infinity_observability_sdk.hourly_rate": hourly_rate,
43
+ "infinity_observability_sdk.business_unit_name": _config.business_unit_name,
44
+ "infinity_observability_sdk.service_name": _config.service_name,
45
+ "infinity_observability_sdk.agent_name": agent_name,
46
+ "infinity_observability_sdk.task_description": task_description,
47
+ "infinity_observability_sdk.task_instance_identifier": task_instance_identifier,
48
+ "infinity_observability_sdk.approximate_person_hours": approximate_person_hours,
49
+ "infinity_observability_sdk.ai_wattage": approximate_person_hours * hourly_rate,
50
+ "infinity_observability_sdk.is_tracked_agent": True,
51
+ "infinity_observability_sdk.version": "0.1",
52
+ **metadata,
53
+ }
54
+
55
+ baggage = {
56
+ "infinity_observability_sdk.baggage.business_unit_name": _config.business_unit_name,
57
+ "infinity_observability_sdk.baggage.service_name": _config.service_name,
58
+ "infinity_observability_sdk.baggage.agent_name": agent_name,
59
+ "infinity_observability_sdk.baggage.is_tracked_agent": "true",
60
+ }
61
+
62
+ with (
63
+ logfire.set_baggage(**baggage),
64
+ logfire.span("agent_context", **attributes) as span,
65
+ ):
66
+ yield span
67
+
68
+
69
+ def configure_observability(config: ObservabilityConfig) -> None:
70
+ global _config
71
+
72
+ endpoint = os.environ.get("INFINITY_OBSERVABILITY_ENDPOINT")
73
+ api_key = os.environ.get("INFINITY_OBSERVABILITY_API_KEY")
74
+
75
+ if not endpoint:
76
+ raise RuntimeError(
77
+ "INFINITY_OBSERVABILITY_ENDPOINT environment variable is required. "
78
+ "Set it to the observability collector endpoint "
79
+ )
80
+
81
+ if not api_key:
82
+ raise RuntimeError(
83
+ "INFINITY_OBSERVABILITY_API_KEY environment variable is required. "
84
+ "Set it to your observability API key."
85
+ )
86
+
87
+ otlp_exporter = OTLPSpanExporter(
88
+ endpoint=f"{endpoint}/v1/traces",
89
+ headers={"X-Api-Key": api_key},
90
+ )
91
+ span_processor = BatchSpanProcessor(otlp_exporter)
92
+
93
+ provider = trace.get_tracer_provider()
94
+
95
+ if isinstance(provider, TracerProvider):
96
+ provider.add_span_processor(span_processor)
97
+ else:
98
+ logfire.configure(
99
+ send_to_logfire=False,
100
+ service_name=config.business_unit_name + "." + config.service_name,
101
+ additional_span_processors=[span_processor],
102
+ )
103
+
104
+ if config.instrument_httpx:
105
+ logfire.instrument_httpx(capture_all=True)
106
+
107
+ if config.instrument_pydantic_ai:
108
+ logfire.instrument_pydantic_ai()
109
+
110
+ _config = config
111
+
112
+ print(
113
+ "Successfully initialized Infinity Monitoring. OTLP traffic is being forwarded to:",
114
+ endpoint,
115
+ )
@@ -0,0 +1,22 @@
1
+ [project]
2
+ name = "infinity-observability-sdk"
3
+ version = "0.1.0"
4
+ description = "Infinity Observability SDK"
5
+ readme = "README.md"
6
+ uuquires-python = ">=3.12"
7
+ dependencies = [
8
+ "logfire>=4.18.0",
9
+ "opentelemetry-exporter-otlp-proto-http>=1.39.1",
10
+ "pytest>=9.0.2",
11
+ "ruff>=0.14.13",
12
+ ]
13
+
14
+ [build-system]
15
+ requires = ["hatchling"]
16
+ build-backend = "hatchling.build"
17
+
18
+ [dependency-groups]
19
+ dev = [
20
+ "build>=1.4.0",
21
+ "twine>=6.2.0",
22
+ ]
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ echo "=== Installing dependencies ==="
5
+ uv sync --dev
6
+
7
+ echo "=== Running ruff linter ==="
8
+ uv run ruff check .
9
+
10
+ echo "=== Running ruff formatter check ==="
11
+ uv run ruff format --check .
12
+
13
+ echo "=== Running tests ==="
14
+ uv run pytest
15
+
16
+ echo "=== Building package ==="
17
+ uv run python -m build
18
+
19
+ echo "=== Checking package with twine ==="
20
+ uv run twine check dist/*
21
+
22
+ echo "=== CI passed ==="
File without changes