beamlit 0.0.34rc53__py3-none-any.whl → 0.0.34rc54__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.
@@ -10,7 +10,6 @@ from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
10
10
  )
11
11
  from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
12
12
  from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
13
- from opentelemetry.instrumentation.logging import LoggingInstrumentor
14
13
  from opentelemetry.metrics import NoOpMeterProvider
15
14
  from opentelemetry.sdk.metrics import MeterProvider
16
15
  from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
@@ -112,12 +111,17 @@ def instrument_app(app: FastAPI):
112
111
  meter = meter_provider.get_meter(__name__)
113
112
  else:
114
113
  meter = metrics.get_meter(__name__)
115
-
116
114
  # Only instrument the app when OpenTelemetry is enabled
117
- FastAPIInstrumentor.instrument_app(
118
- app=app, tracer_provider=trace.get_tracer_provider(), meter_provider=metrics.get_meter_provider()
119
- )
120
- HTTPXClientInstrumentor().instrument(meter_provider=metrics.get_meter_provider())
121
- LoggingInstrumentor(tracer_provider=trace.get_tracer_provider()).instrument(
122
- set_logging_format=True
123
- )
115
+ FastAPIInstrumentor.instrument_app(app)
116
+ HTTPXClientInstrumentor().instrument()
117
+
118
+
119
+ def shutdown_instrumentation():
120
+ if tracer is not None:
121
+ trace_provider = trace.get_tracer_provider()
122
+ if isinstance(trace_provider, TracerProvider):
123
+ trace_provider.shutdown()
124
+ if meter is not None:
125
+ meter_provider = metrics.get_meter_provider()
126
+ if isinstance(meter_provider, MeterProvider):
127
+ meter_provider.shutdown()
beamlit/serve/app.py CHANGED
@@ -3,6 +3,7 @@ import importlib
3
3
  import os
4
4
  import sys
5
5
  import traceback
6
+ from contextlib import asynccontextmanager
6
7
  from logging import getLogger
7
8
  from uuid import uuid4
8
9
 
@@ -13,9 +14,9 @@ from traceloop.sdk import Traceloop
13
14
 
14
15
  from beamlit.common import HTTPError, get_settings, init
15
16
  from beamlit.common.instrumentation import (
16
- get_metrics_exporter,
17
17
  get_resource_attributes,
18
18
  get_span_exporter,
19
+ shutdown_instrumentation,
19
20
  instrument_app,
20
21
  )
21
22
 
@@ -41,16 +42,14 @@ logger.info(
41
42
  f" on {settings.server.host}:{settings.server.port}"
42
43
  )
43
44
 
44
- if settings.enable_opentelemetry:
45
- Traceloop.init(
46
- app_name=settings.name,
47
- exporter=get_span_exporter(),
48
- metrics_exporter=get_metrics_exporter(),
49
- resource_attributes=get_resource_attributes(),
50
- should_enrich_metrics=os.getenv("ENRICHED_METRICS", "false") == "true",
51
- )
52
45
 
53
- app = FastAPI(docs_url=None, redoc_url=None)
46
+ @asynccontextmanager
47
+ async def lifespan(app: FastAPI):
48
+ yield
49
+ shutdown_instrumentation()
50
+
51
+
52
+ app = FastAPI(docs_url=None, redoc_url=None, lifespan=lifespan)
54
53
  app.add_middleware(
55
54
  CorrelationIdMiddleware,
56
55
  header_name="x-beamlit-request-id",
@@ -59,6 +58,13 @@ app.add_middleware(
59
58
  app.add_middleware(AddProcessTimeHeader)
60
59
  app.add_middleware(AccessLogMiddleware)
61
60
  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
+ )
62
68
 
63
69
 
64
70
  @app.get("/health")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beamlit
3
- Version: 0.0.34rc53
3
+ Version: 0.0.34rc54
4
4
  Summary: Add your description here
5
5
  Author-email: cploujoux <ch.ploujoux@gmail.com>
6
6
  Requires-Python: >=3.12
@@ -17,7 +17,6 @@ Requires-Dist: opentelemetry-api>=1.28.2
17
17
  Requires-Dist: opentelemetry-exporter-otlp>=1.28.2
18
18
  Requires-Dist: opentelemetry-instrumentation-fastapi>=0.49b2
19
19
  Requires-Dist: opentelemetry-instrumentation-httpx>=0.49b2
20
- Requires-Dist: opentelemetry-instrumentation-logging>=0.49b2
21
20
  Requires-Dist: opentelemetry-sdk>=1.28.2
22
21
  Requires-Dist: pydantic-settings<2.7.0,>=2.6.1
23
22
  Requires-Dist: pydantic<2.11.0,>=2.10.3
@@ -130,7 +130,7 @@ beamlit/authentication/credentials.py,sha256=p_1xenabCbQuRz7BiFk7oTK4uCxAt_zoyku
130
130
  beamlit/authentication/device_mode.py,sha256=tmr22gllKOZwBRub_QjF5pYa425x-nE8tQNpZ_EGR6g,3644
131
131
  beamlit/common/__init__.py,sha256=saX5X3hRCJ9erSlXuSkZ2VGgquvpgdcofAU_9sM4bCE,354
132
132
  beamlit/common/error.py,sha256=f9oJDFxhoHK-vpjxBgEp0NwWIk0N_THPemUI7uQxVzU,270
133
- beamlit/common/instrumentation.py,sha256=GVYeat7qCcqzDoKSYig3s8ZCC172R9JiQIr3Evv3kik,4293
133
+ beamlit/common/instrumentation.py,sha256=snsH72EA2_RsM3E9qL9KRiuTSNYGkFKVN3NlGblRogw,4331
134
134
  beamlit/common/logger.py,sha256=nN_dSOl4bs13QU3Rod-w3e3jYOnlSrHx3_bs-ACY6Aw,1115
135
135
  beamlit/common/secrets.py,sha256=sid81bOe3LflkMKDHwBsBs9nIju8bp5-v9qU9gkyNMc,212
136
136
  beamlit/common/settings.py,sha256=b2rvby-ufG3M0AB1ReoWFM-1EzF1LaE-gbokO9HvQDI,3810
@@ -252,10 +252,10 @@ beamlit/models/websocket_channel.py,sha256=jg3vN7yS_oOIwGtndtIUr1LsyEA58RXLXahqS
252
252
  beamlit/models/workspace.py,sha256=l__bIpbA4oJvxXo7UbEoCcqkvu9MiNt5aXXpZ3bgwHg,4309
253
253
  beamlit/models/workspace_labels.py,sha256=WbnUY6eCTkUNdY7hhhSF-KQCl8fWFfkCf7hzCTiNp4A,1246
254
254
  beamlit/models/workspace_user.py,sha256=70CcifQWYbeWG7TDui4pblTzUe5sVK0AS19vNCzKE8g,3423
255
- beamlit/serve/app.py,sha256=DXWxQoMeuA5FYvBMyLrP94OEWQbwLf4GZk3I9fkwSPA,3523
255
+ beamlit/serve/app.py,sha256=gYQvUK_S7g0Em-idND8HrVDqgg5LlIemheSGlX2Jj8U,3638
256
256
  beamlit/serve/middlewares/__init__.py,sha256=1dVmnOmhAQWvWktqHkKSIX-YoF6fmMU8xkUQuhg_rJU,148
257
257
  beamlit/serve/middlewares/accesslog.py,sha256=Mu4T4_9OvHybjA0ApzZFpgi2C8f3X1NbUk-76v634XM,631
258
258
  beamlit/serve/middlewares/processtime.py,sha256=lDAaIasZ4bwvN-HKHvZpaD9r-yrkVNZYx4abvbjbrCg,411
259
- beamlit-0.0.34rc53.dist-info/METADATA,sha256=mYmSQ4b1y6e0X4Ead4ZQOE4Bk0akR7ot4Q-7NOCzC9I,2405
260
- beamlit-0.0.34rc53.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
261
- beamlit-0.0.34rc53.dist-info/RECORD,,
259
+ beamlit-0.0.34rc54.dist-info/METADATA,sha256=Dio5lsBaSZ3GI-top1rPGxCQCkykLx7cgLL274ZimBo,2344
260
+ beamlit-0.0.34rc54.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
261
+ beamlit-0.0.34rc54.dist-info/RECORD,,