infinity-observability-sdk 0.1.0__py2.py3-none-any.whl

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,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,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,6 @@
1
+ infinity_observability_sdk/__init__.py,sha256=ncC7P_l2z8eZUo64fNtBX2pEekcoqCAOndXpqDQ36go,608
2
+ infinity_observability_sdk/sdk.py,sha256=YFVAq8x3vMJPk2qcHnH-X3_rEKHHKRpSPyu5P82RZkU,3823
3
+ infinity_observability_sdk-0.1.0.dist-info/METADATA,sha256=_azkfq3iYtxV_YFpAMwUANmiKUeFG4vMZhaVNumiQig,349
4
+ infinity_observability_sdk-0.1.0.dist-info/WHEEL,sha256=aha0VrrYvgDJ3Xxl3db_g_MDIW-ZexDdrc_m-Hk8YY4,105
5
+ infinity_observability_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=ACwmltkrXIz5VsEQcrqljq-fat6ZXAMepjXGoe40KtE,1069
6
+ infinity_observability_sdk-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py2-none-any
5
+ Tag: py3-none-any
@@ -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.