beamlit 0.0.34rc78__py3-none-any.whl → 0.0.34rc79__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.
@@ -1,5 +1,6 @@
1
+ import importlib
1
2
  import logging
2
- from typing import Any
3
+ from typing import Any, Optional, Type
3
4
 
4
5
  from fastapi import FastAPI
5
6
  from opentelemetry import _logs, metrics, trace
@@ -13,8 +14,9 @@ from opentelemetry.exporter.otlp.proto.http.metric_exporter import (
13
14
  from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
14
15
  OTLPSpanExporter,
15
16
  )
16
- from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
17
- from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
17
+ from opentelemetry.instrumentation.fastapi import ( # type: ignore
18
+ FastAPIInstrumentor,
19
+ )
18
20
  from opentelemetry.metrics import NoOpMeterProvider
19
21
  from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
20
22
  from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
@@ -34,6 +36,8 @@ tracer: trace.Tracer | None = None
34
36
  meter: metrics.Meter | None = None
35
37
  logger: LoggerProvider | None = None
36
38
 
39
+ log = logging.getLogger(__name__)
40
+
37
41
 
38
42
  def auth_headers() -> Dict[str, str]:
39
43
  settings = get_settings()
@@ -82,6 +86,121 @@ def get_log_exporter() -> OTLPLogExporter | None:
82
86
  return OTLPLogExporter(headers=auth_headers())
83
87
 
84
88
 
89
+ def _import_class(module_path: str, class_name: str) -> Optional[Type]: # type: ignore
90
+ """Dynamically import a class from a module path."""
91
+ try:
92
+ module = importlib.import_module(module_path)
93
+ return getattr(module, class_name)
94
+ except (ImportError, AttributeError) as e:
95
+ log.error(f"Could not import {class_name} from {module_path}: {str(e)}")
96
+ return None
97
+
98
+
99
+ # Define mapping of instrumentor info: (module path, class name, required package)
100
+ INSTRUMENTOR_CONFIGS = {
101
+ "httpx": (
102
+ "opentelemetry.instrumentation.httpx",
103
+ "HTTPXClientInstrumentor",
104
+ "httpx",
105
+ ),
106
+ "anthropic": (
107
+ "opentelemetry.instrumentation.anthropic",
108
+ "AnthropicInstrumentor",
109
+ "anthropic",
110
+ ),
111
+ "chroma": (
112
+ "opentelemetry.instrumentation.chroma",
113
+ "ChromaInstrumentor",
114
+ "chromadb",
115
+ ),
116
+ "cohere": (
117
+ "opentelemetry.instrumentation.cohere",
118
+ "CohereInstrumentor",
119
+ "cohere",
120
+ ),
121
+ "groq": ("opentelemetry.instrumentation.groq", "GroqInstrumentor", "groq"),
122
+ "lance": (
123
+ "opentelemetry.instrumentation.lance",
124
+ "LanceInstrumentor",
125
+ "pylance",
126
+ ),
127
+ "langchain": (
128
+ "opentelemetry.instrumentation.langchain",
129
+ "LangchainInstrumentor",
130
+ "langchain",
131
+ ),
132
+ "llama_index": (
133
+ "opentelemetry.instrumentation.llama_index",
134
+ "LlamaIndexInstrumentor",
135
+ "llama_index",
136
+ ),
137
+ "marqo": (
138
+ "opentelemetry.instrumentation.marqo",
139
+ "MarqoInstrumentor",
140
+ "marqo",
141
+ ),
142
+ "milvus": (
143
+ "opentelemetry.instrumentation.milvus",
144
+ "MilvusInstrumentor",
145
+ "pymilvus",
146
+ ),
147
+ "mistralai": (
148
+ "opentelemetry.instrumentation.mistralai",
149
+ "MistralAiInstrumentor",
150
+ "mistralai",
151
+ ),
152
+ "ollama": (
153
+ "opentelemetry.instrumentation.ollama",
154
+ "OllamaInstrumentor",
155
+ "ollama",
156
+ ),
157
+ "openai": (
158
+ "opentelemetry.instrumentation.openai",
159
+ "OpenAIInstrumentor",
160
+ "openai",
161
+ ),
162
+ "pinecone": (
163
+ "opentelemetry.instrumentation.pinecone",
164
+ "PineconeInstrumentor",
165
+ "pinecone",
166
+ ),
167
+ "qdrant": (
168
+ "opentelemetry.instrumentation.qdrant",
169
+ "QdrantInstrumentor",
170
+ "qdrant_client",
171
+ ),
172
+ "replicate": (
173
+ "opentelemetry.instrumentation.replicate",
174
+ "ReplicateInstrumentor",
175
+ "replicate",
176
+ ),
177
+ "together": (
178
+ "opentelemetry.instrumentation.together",
179
+ "TogetherAiInstrumentor",
180
+ "together",
181
+ ),
182
+ "watsonx": (
183
+ "opentelemetry.instrumentation.watsonx",
184
+ "WatsonxInstrumentor",
185
+ "ibm_watson_machine_learning",
186
+ ),
187
+ "weaviate": (
188
+ "opentelemetry.instrumentation.weaviate",
189
+ "WeaviateInstrumentor",
190
+ "weaviate",
191
+ ),
192
+ }
193
+
194
+
195
+ def _is_package_installed(package_name: str) -> bool:
196
+ """Check if a package is installed."""
197
+ try:
198
+ importlib.import_module(package_name)
199
+ return True
200
+ except (ImportError, ModuleNotFoundError):
201
+ return False
202
+
203
+
85
204
  def instrument_app(app: FastAPI):
86
205
  global tracer
87
206
  global meter
@@ -106,7 +225,7 @@ def instrument_app(app: FastAPI):
106
225
  # Set up the TracerProvider if not already set
107
226
  if not isinstance(trace.get_tracer_provider(), TracerProvider):
108
227
  trace_provider = TracerProvider(resource=resource)
109
- span_processor = BatchSpanProcessor(get_span_exporter())
228
+ span_processor = BatchSpanProcessor(get_span_exporter()) # type: ignore
110
229
  trace_provider.add_span_processor(span_processor)
111
230
  trace.set_tracer_provider(trace_provider)
112
231
  tracer = trace_provider.get_tracer(__name__)
@@ -115,7 +234,7 @@ def instrument_app(app: FastAPI):
115
234
 
116
235
  # Set up the MeterProvider if not already set
117
236
  if not isinstance(metrics.get_meter_provider(), MeterProvider):
118
- metrics_exporter = PeriodicExportingMetricReader(get_metrics_exporter())
237
+ metrics_exporter = PeriodicExportingMetricReader(get_metrics_exporter()) # type: ignore
119
238
  meter_provider = MeterProvider(
120
239
  resource=resource, metric_readers=[metrics_exporter]
121
240
  )
@@ -128,7 +247,7 @@ def instrument_app(app: FastAPI):
128
247
  logger_provider = LoggerProvider(resource=resource)
129
248
  set_logger_provider(logger_provider)
130
249
  logger_provider.add_log_record_processor(
131
- BatchLogRecordProcessor(get_log_exporter())
250
+ BatchLogRecordProcessor(get_log_exporter()) # type: ignore
132
251
  )
133
252
  handler = LoggingHandler(
134
253
  level=logging.NOTSET, logger_provider=logger_provider
@@ -138,8 +257,27 @@ def instrument_app(app: FastAPI):
138
257
  logger_provider = _logs.get_logger_provider()
139
258
 
140
259
  # Only instrument the app when OpenTelemetry is enabled
141
- FastAPIInstrumentor.instrument_app(app)
142
- HTTPXClientInstrumentor().instrument()
260
+ FastAPIInstrumentor.instrument_app(app) # type: ignore
261
+
262
+ for name, (
263
+ module_path,
264
+ class_name,
265
+ required_package,
266
+ ) in INSTRUMENTOR_CONFIGS.items():
267
+ if _is_package_installed(required_package):
268
+ instrumentor_class = _import_class(module_path, class_name) # type: ignore
269
+ if instrumentor_class:
270
+ try:
271
+ instrumentor_class().instrument()
272
+ log.info(f"Successfully instrumented {name}")
273
+ except Exception as e:
274
+ log.error(f"Failed to instrument {name}: {str(e)}")
275
+ else:
276
+ log.error(f"Could not load instrumentor for {name}")
277
+ else:
278
+ log.debug(
279
+ f"Skipping {name} instrumentation - required package '{required_package}' not installed"
280
+ )
143
281
 
144
282
 
145
283
  def shutdown_instrumentation():
beamlit/serve/app.py CHANGED
@@ -10,12 +10,9 @@ from uuid import uuid4
10
10
  from asgi_correlation_id import CorrelationIdMiddleware
11
11
  from fastapi import FastAPI, Request, Response
12
12
  from fastapi.responses import JSONResponse
13
- from traceloop.sdk import Traceloop
14
13
 
15
14
  from beamlit.common import HTTPError, get_settings, init
16
15
  from beamlit.common.instrumentation import (
17
- get_resource_attributes,
18
- get_span_exporter,
19
16
  instrument_app,
20
17
  shutdown_instrumentation,
21
18
  )
@@ -58,13 +55,6 @@ app.add_middleware(
58
55
  app.add_middleware(AddProcessTimeHeader)
59
56
  app.add_middleware(AccessLogMiddleware)
60
57
  instrument_app(app)
61
- if settings.enable_opentelemetry:
62
- Traceloop.init(
63
- app_name=settings.name,
64
- exporter=get_span_exporter(),
65
- resource_attributes=get_resource_attributes(),
66
- should_enrich_metrics=os.getenv("ENRICHED_METRICS", "false") == "true",
67
- )
68
58
 
69
59
 
70
60
  @app.get("/health")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beamlit
3
- Version: 0.0.34rc78
3
+ Version: 0.0.34rc79
4
4
  Summary: Add your description here
5
5
  Author-email: cploujoux <ch.ploujoux@gmail.com>
6
6
  Requires-Python: >=3.12
@@ -15,9 +15,27 @@ Requires-Dist: langgraph<0.3.0,>=0.2.40
15
15
  Requires-Dist: mcp>=1.1.2
16
16
  Requires-Dist: opentelemetry-api>=1.28.2
17
17
  Requires-Dist: opentelemetry-exporter-otlp>=1.28.2
18
+ Requires-Dist: opentelemetry-instrumentation-anthropic>=0.35.0
19
+ Requires-Dist: opentelemetry-instrumentation-chromadb>=0.35.0
20
+ Requires-Dist: opentelemetry-instrumentation-cohere>=0.35.0
18
21
  Requires-Dist: opentelemetry-instrumentation-fastapi>=0.49b2
22
+ Requires-Dist: opentelemetry-instrumentation-groq>=0.35.0
19
23
  Requires-Dist: opentelemetry-instrumentation-httpx>=0.49b2
24
+ Requires-Dist: opentelemetry-instrumentation-lancedb>=0.35.0
25
+ Requires-Dist: opentelemetry-instrumentation-langchain>=0.35.0
26
+ Requires-Dist: opentelemetry-instrumentation-llamaindex>=0.35.0
27
+ Requires-Dist: opentelemetry-instrumentation-marqo>=0.35.0
28
+ Requires-Dist: opentelemetry-instrumentation-milvus>=0.35.0
29
+ Requires-Dist: opentelemetry-instrumentation-mistralai>=0.35.0
30
+ Requires-Dist: opentelemetry-instrumentation-ollama>=0.35.0
31
+ Requires-Dist: opentelemetry-instrumentation-openai>=0.35.0
32
+ Requires-Dist: opentelemetry-instrumentation-pinecone>=0.35.0
33
+ Requires-Dist: opentelemetry-instrumentation-qdrant>=0.35.0
34
+ Requires-Dist: opentelemetry-instrumentation-replicate>=0.35.0
20
35
  Requires-Dist: opentelemetry-instrumentation-system-metrics>=0.50b0
36
+ Requires-Dist: opentelemetry-instrumentation-together>=0.35.0
37
+ Requires-Dist: opentelemetry-instrumentation-watsonx>=0.35.0
38
+ Requires-Dist: opentelemetry-instrumentation-weaviate>=0.35.0
21
39
  Requires-Dist: opentelemetry-sdk>=1.28.2
22
40
  Requires-Dist: pydantic-settings<2.7.0,>=2.6.1
23
41
  Requires-Dist: pydantic<2.11.0,>=2.10.3
@@ -25,7 +43,6 @@ Requires-Dist: pyjwt>=2.10.1
25
43
  Requires-Dist: python-dateutil>=2.8.0
26
44
  Requires-Dist: pyyaml<6.1.0,>=6.0.2
27
45
  Requires-Dist: requests<2.33.0,>=2.32.3
28
- Requires-Dist: traceloop-sdk>=0.33.12
29
46
  Description-Content-Type: text/markdown
30
47
 
31
48
  # beamlit
@@ -131,7 +131,7 @@ beamlit/authentication/credentials.py,sha256=p_1xenabCbQuRz7BiFk7oTK4uCxAt_zoyku
131
131
  beamlit/authentication/device_mode.py,sha256=LNHjoKe3u4TWApLKO34cJjN92UsVkHSYSbXr6eKxo64,3721
132
132
  beamlit/common/__init__.py,sha256=saX5X3hRCJ9erSlXuSkZ2VGgquvpgdcofAU_9sM4bCE,354
133
133
  beamlit/common/error.py,sha256=f9oJDFxhoHK-vpjxBgEp0NwWIk0N_THPemUI7uQxVzU,270
134
- beamlit/common/instrumentation.py,sha256=u-eZjv1hWMAlYQ3b6YPmOPHBJCCgPebLuLO5DhDRgAA,5351
134
+ beamlit/common/instrumentation.py,sha256=TKBbLNSPz0TKGufxSbVuLdJ9Tunh7-Y967SxwIX4j-o,9287
135
135
  beamlit/common/logger.py,sha256=nN_dSOl4bs13QU3Rod-w3e3jYOnlSrHx3_bs-ACY6Aw,1115
136
136
  beamlit/common/secrets.py,sha256=sid81bOe3LflkMKDHwBsBs9nIju8bp5-v9qU9gkyNMc,212
137
137
  beamlit/common/settings.py,sha256=OL1pZLB3BgN7QPCz9VR7gjYb-LoYpelilS7rU7FubCE,3962
@@ -280,10 +280,10 @@ beamlit/models/websocket_channel.py,sha256=jg3vN7yS_oOIwGtndtIUr1LsyEA58RXLXahqS
280
280
  beamlit/models/workspace.py,sha256=J_YibDQqp0esl1G941ryVQCQfGk0EDSo4qXrjUWDXI8,4261
281
281
  beamlit/models/workspace_labels.py,sha256=WbnUY6eCTkUNdY7hhhSF-KQCl8fWFfkCf7hzCTiNp4A,1246
282
282
  beamlit/models/workspace_user.py,sha256=70CcifQWYbeWG7TDui4pblTzUe5sVK0AS19vNCzKE8g,3423
283
- beamlit/serve/app.py,sha256=_aG2UVQ3Y85rUW3ehu9TlzLnowkfh54IIz558ftqOMw,3638
283
+ beamlit/serve/app.py,sha256=ROS_tb9cO4GvOQKCwloyAzpYraTdIb3oG6sChXikeNw,3285
284
284
  beamlit/serve/middlewares/__init__.py,sha256=1dVmnOmhAQWvWktqHkKSIX-YoF6fmMU8xkUQuhg_rJU,148
285
285
  beamlit/serve/middlewares/accesslog.py,sha256=Mu4T4_9OvHybjA0ApzZFpgi2C8f3X1NbUk-76v634XM,631
286
286
  beamlit/serve/middlewares/processtime.py,sha256=lDAaIasZ4bwvN-HKHvZpaD9r-yrkVNZYx4abvbjbrCg,411
287
- beamlit-0.0.34rc78.dist-info/METADATA,sha256=T3UNX5GmFkovN9C3aFTf5Vonj8VGqQlc68aR7m-xVOU,2441
288
- beamlit-0.0.34rc78.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
289
- beamlit-0.0.34rc78.dist-info/RECORD,,
287
+ beamlit-0.0.34rc79.dist-info/METADATA,sha256=IrL2gJ5NSmdT8TtON7BnbT5ke8z3Dn22XW5xbL_c1oA,3506
288
+ beamlit-0.0.34rc79.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
289
+ beamlit-0.0.34rc79.dist-info/RECORD,,