beamlit 0.0.31rc39__py3-none-any.whl → 0.0.31rc41__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- beamlit/common/instrumentation.py +53 -31
- beamlit/common/settings.py +1 -0
- beamlit/deploy/deploy.py +2 -2
- beamlit/serve/app.py +8 -7
- {beamlit-0.0.31rc39.dist-info → beamlit-0.0.31rc41.dist-info}/METADATA +1 -1
- {beamlit-0.0.31rc39.dist-info → beamlit-0.0.31rc41.dist-info}/RECORD +7 -7
- {beamlit-0.0.31rc39.dist-info → beamlit-0.0.31rc41.dist-info}/WHEEL +0 -0
@@ -8,22 +8,16 @@ from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import (
|
|
8
8
|
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
|
9
9
|
OTLPSpanExporter,
|
10
10
|
)
|
11
|
-
from opentelemetry.instrumentation.fastapi import
|
12
|
-
|
13
|
-
|
14
|
-
from opentelemetry.
|
15
|
-
HTTPXClientInstrumentor,
|
16
|
-
)
|
17
|
-
from opentelemetry.instrumentation.logging import ( # type: ignore
|
18
|
-
LoggingInstrumentor,
|
19
|
-
)
|
11
|
+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
|
12
|
+
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
|
13
|
+
from opentelemetry.instrumentation.logging import LoggingInstrumentor
|
14
|
+
from opentelemetry.metrics import NoOpMeterProvider
|
20
15
|
from opentelemetry.sdk.metrics import MeterProvider
|
21
|
-
from opentelemetry.sdk.metrics.export import
|
22
|
-
PeriodicExportingMetricReader,
|
23
|
-
)
|
16
|
+
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
|
24
17
|
from opentelemetry.sdk.resources import Resource
|
25
18
|
from opentelemetry.sdk.trace import TracerProvider
|
26
19
|
from opentelemetry.sdk.trace.export import BatchSpanProcessor
|
20
|
+
from opentelemetry.trace import NoOpTracerProvider
|
27
21
|
from typing_extensions import Dict
|
28
22
|
|
29
23
|
from .settings import get_settings
|
@@ -57,11 +51,20 @@ def get_resource_attributes() -> Dict[str, Any]:
|
|
57
51
|
return resources_dict
|
58
52
|
|
59
53
|
|
60
|
-
def get_metrics_exporter() -> OTLPMetricExporter:
|
54
|
+
def get_metrics_exporter() -> OTLPMetricExporter | None:
|
55
|
+
settings = get_settings()
|
56
|
+
if settings is None:
|
57
|
+
raise Exception("Settings are not initialized")
|
58
|
+
if not settings.enable_opentelemetry:
|
59
|
+
# Return None or a NoOpExporter equivalent
|
60
|
+
return None
|
61
61
|
return OTLPMetricExporter()
|
62
62
|
|
63
63
|
|
64
|
-
def get_span_exporter() -> OTLPSpanExporter:
|
64
|
+
def get_span_exporter() -> OTLPSpanExporter | None:
|
65
|
+
settings = get_settings()
|
66
|
+
if not settings.enable_opentelemetry:
|
67
|
+
return None
|
65
68
|
return OTLPSpanExporter()
|
66
69
|
|
67
70
|
|
@@ -71,6 +74,16 @@ def instrument_app(app: FastAPI):
|
|
71
74
|
settings = get_settings()
|
72
75
|
if settings is None:
|
73
76
|
raise Exception("Settings are not initialized")
|
77
|
+
|
78
|
+
if not settings.enable_opentelemetry:
|
79
|
+
# Use NoOp implementations to stub tracing and metrics
|
80
|
+
trace.set_tracer_provider(NoOpTracerProvider())
|
81
|
+
tracer = trace.get_tracer(__name__)
|
82
|
+
|
83
|
+
metrics.set_meter_provider(NoOpMeterProvider())
|
84
|
+
meter = metrics.get_meter(__name__)
|
85
|
+
return
|
86
|
+
|
74
87
|
resource = Resource.create(
|
75
88
|
{
|
76
89
|
"service.name": settings.name,
|
@@ -78,24 +91,33 @@ def instrument_app(app: FastAPI):
|
|
78
91
|
"service.workspace": settings.workspace,
|
79
92
|
}
|
80
93
|
)
|
81
|
-
# Set up the TracerProvider
|
82
|
-
trace_provider = TracerProvider(resource=resource)
|
83
|
-
span_processor = BatchSpanProcessor(get_span_exporter())
|
84
|
-
trace_provider.add_span_processor(span_processor)
|
85
|
-
trace.set_tracer_provider(trace_provider)
|
86
|
-
tracer = trace_provider.get_tracer(__name__)
|
87
|
-
|
88
|
-
metrics_exporter = PeriodicExportingMetricReader(get_metrics_exporter())
|
89
|
-
meter_provider = MeterProvider(
|
90
|
-
resource=resource, metric_readers=[metrics_exporter]
|
91
|
-
)
|
92
|
-
metrics.set_meter_provider(meter_provider)
|
93
|
-
meter = meter_provider.get_meter(__name__)
|
94
94
|
|
95
|
-
|
96
|
-
|
95
|
+
# Set up the TracerProvider if not already set
|
96
|
+
if not isinstance(trace.get_tracer_provider(), TracerProvider):
|
97
|
+
trace_provider = TracerProvider(resource=resource)
|
98
|
+
span_processor = BatchSpanProcessor(get_span_exporter())
|
99
|
+
trace_provider.add_span_processor(span_processor)
|
100
|
+
trace.set_tracer_provider(trace_provider)
|
101
|
+
tracer = trace_provider.get_tracer(__name__)
|
102
|
+
else:
|
103
|
+
tracer = trace.get_tracer(__name__)
|
104
|
+
|
105
|
+
# Set up the MeterProvider if not already set
|
106
|
+
if not isinstance(metrics.get_meter_provider(), MeterProvider):
|
107
|
+
metrics_exporter = PeriodicExportingMetricReader(get_metrics_exporter())
|
108
|
+
meter_provider = MeterProvider(
|
109
|
+
resource=resource, metric_readers=[metrics_exporter]
|
110
|
+
)
|
111
|
+
metrics.set_meter_provider(meter_provider)
|
112
|
+
meter = meter_provider.get_meter(__name__)
|
113
|
+
else:
|
114
|
+
meter = metrics.get_meter(__name__)
|
115
|
+
|
116
|
+
# 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()
|
97
119
|
)
|
98
|
-
HTTPXClientInstrumentor().instrument(meter_provider=
|
99
|
-
LoggingInstrumentor(tracer_provider=
|
120
|
+
HTTPXClientInstrumentor().instrument(meter_provider=metrics.get_meter_provider())
|
121
|
+
LoggingInstrumentor(tracer_provider=trace.get_tracer_provider()).instrument(
|
100
122
|
set_logging_format=True
|
101
123
|
)
|
beamlit/common/settings.py
CHANGED
@@ -67,6 +67,7 @@ class Settings(BaseSettings):
|
|
67
67
|
mcp_hub_url: str = Field(default="https://mcp-hub-server.beamlit.workers.com")
|
68
68
|
registry_url: str = Field(default="https://us.registry.beamlit.com")
|
69
69
|
log_level: str = Field(default="INFO")
|
70
|
+
enable_opentelemetry: bool = Field(default=False)
|
70
71
|
agent: SettingsAgent = SettingsAgent()
|
71
72
|
server: SettingsServer = SettingsServer()
|
72
73
|
authentication: SettingsAuthentication = SettingsAuthentication()
|
beamlit/deploy/deploy.py
CHANGED
@@ -23,7 +23,7 @@ from .parser import Resource, get_description, get_parameters, get_resources
|
|
23
23
|
sys.path.insert(0, os.getcwd())
|
24
24
|
sys.path.insert(0, os.path.join(os.getcwd(), "src"))
|
25
25
|
|
26
|
-
|
26
|
+
random_id = str(uuid.uuid4())[:8]
|
27
27
|
def slugify(name: str) -> str:
|
28
28
|
return name.lower().replace(" ", "-").replace("_", "-")
|
29
29
|
|
@@ -32,7 +32,7 @@ def get_runtime_image(type: str, name: str) -> str:
|
|
32
32
|
registry_url = settings.registry_url.replace("https://", "").replace("http://", "")
|
33
33
|
image = f"{registry_url}/{settings.workspace}/{type}s/{name}"
|
34
34
|
# Generate a random ID to ensure unique image tags
|
35
|
-
image = f"{image}:{
|
35
|
+
image = f"{image}:{random_id}"
|
36
36
|
return image
|
37
37
|
|
38
38
|
|
beamlit/serve/app.py
CHANGED
@@ -41,13 +41,14 @@ logger.info(
|
|
41
41
|
f" on {settings.server.host}:{settings.server.port}"
|
42
42
|
)
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
)
|
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
|
+
)
|
51
52
|
|
52
53
|
app = FastAPI(docs_url=None, redoc_url=None)
|
53
54
|
app.add_middleware(
|
@@ -131,13 +131,13 @@ beamlit/authentication/device_mode.py,sha256=tmr22gllKOZwBRub_QjF5pYa425x-nE8tQN
|
|
131
131
|
beamlit/common/__init__.py,sha256=vj4_boIBVitMsaQR8BqBqE2eupOIh6MWBAYlYyCCH98,341
|
132
132
|
beamlit/common/error.py,sha256=f9oJDFxhoHK-vpjxBgEp0NwWIk0N_THPemUI7uQxVzU,270
|
133
133
|
beamlit/common/generate.py,sha256=LtdCju_QayRS4lZrrb_0VHqWWvTcv4Mbf-iV1TB_Qko,7522
|
134
|
-
beamlit/common/instrumentation.py,sha256=
|
134
|
+
beamlit/common/instrumentation.py,sha256=GVYeat7qCcqzDoKSYig3s8ZCC172R9JiQIr3Evv3kik,4293
|
135
135
|
beamlit/common/logger.py,sha256=nN_dSOl4bs13QU3Rod-w3e3jYOnlSrHx3_bs-ACY6Aw,1115
|
136
136
|
beamlit/common/secrets.py,sha256=sid81bOe3LflkMKDHwBsBs9nIju8bp5-v9qU9gkyNMc,212
|
137
|
-
beamlit/common/settings.py,sha256=
|
137
|
+
beamlit/common/settings.py,sha256=_4oCVrJZOMaTZoK2Zzo2DWqtUyBsspuOH3iAJ_nU0tw,5923
|
138
138
|
beamlit/common/utils.py,sha256=jouz5igBvT37Xn_e94-foCHyQczVim-UzVcoIF6RWJ4,657
|
139
139
|
beamlit/deploy/__init__.py,sha256=GS7l7Jtm2yKs7iNLKcfjYO-rAhUzggQ3xiYSf3oxLBY,91
|
140
|
-
beamlit/deploy/deploy.py,sha256=
|
140
|
+
beamlit/deploy/deploy.py,sha256=xo2fAdF6jR1cG75sXMzpqsJlG_qGAKVnMwjuDa_8sk8,9936
|
141
141
|
beamlit/deploy/format.py,sha256=PJ8kU7Y1pwiS3tqqyvFaag9LO3jju-4ua574163VPk4,1820
|
142
142
|
beamlit/deploy/parser.py,sha256=Ga0poCZkoRnuTw082QnTcNGCBJncoRAnVsn8-1FsaJE,6907
|
143
143
|
beamlit/functions/__init__.py,sha256=_RPG1Bfg54JGdIPnViAU6n9zD7E1cDNsdXi8oYGskzE,138
|
@@ -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=
|
255
|
+
beamlit/serve/app.py,sha256=QzReZZjGFQWhNA1XBDq81rsn9zpEihtLZLrfZi9ThT0,3554
|
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.
|
260
|
-
beamlit-0.0.
|
261
|
-
beamlit-0.0.
|
259
|
+
beamlit-0.0.31rc41.dist-info/METADATA,sha256=4Q1xmITkbqqcVdkeR0OMCX4UI0q8QlKj12h3sE_ps-Q,2405
|
260
|
+
beamlit-0.0.31rc41.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
261
|
+
beamlit-0.0.31rc41.dist-info/RECORD,,
|
File without changes
|