You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With <b>microbootstrap</b>, you receive an application with lightweight built-in support for:
38
37
39
38
-`sentry`
@@ -43,6 +42,11 @@ With <b>microbootstrap</b>, you receive an application with lightweight built-in
43
42
-`cors`
44
43
-`swagger` - with additional offline version support
45
44
45
+
Those instruments can be bootstrapped for:
46
+
47
+
-`fastapi`
48
+
-`litestar`
49
+
46
50
Interested? Let's dive right in ⚡
47
51
48
52
## Table of Contents
@@ -65,18 +69,22 @@ Interested? Let's dive right in ⚡
65
69
66
70
## Installation
67
71
68
-
You can install the package using either `pip` or `poetry`.
72
+
You can install the package using either `pip` or `poetry`.
73
+
Also, you can specify extras during installation for concrete framework:
74
+
75
+
-`fastapi`
76
+
-`litestar`
69
77
70
78
For poetry:
71
79
72
80
```bash
73
-
$ poetry add microbootstrap -E litestar
81
+
$ poetry add microbootstrap -E fastapi
74
82
```
75
83
76
84
For pip:
77
85
78
86
```bash
79
-
$ pip install microbootstrap[litestar]
87
+
$ pip install microbootstrap[fastapi]
80
88
```
81
89
82
90
## Quickstart
@@ -122,16 +130,16 @@ This approach will provide you with an application that has all the essential in
122
130
123
131
The settings object is the core of microbootstrap.
124
132
125
-
All framework-related settings inherit from the `BaseBootstrapSettings` object. `BaseBootstrapSettings` defines parameters for the service and various instruments.
133
+
All framework-related settings inherit from the `BaseServiceSettings` object. `BaseServiceSettings` defines parameters for the service and various instruments.
126
134
127
-
However, the number of parameters is <b>not confined</b> to those defined in `BaseBootstrapSettings`. You can add as many as you need.
135
+
However, the number of parameters is <b>not confined</b> to those defined in `BaseServiceSettings`. You can add as many as you need.
128
136
129
137
These parameters can be sourced from your environment. By default, no prefix is added to these parameters.
130
138
131
139
Example:
132
140
133
141
```python
134
-
classYourSettings(BaseBootstrapSettings):
142
+
classYourSettings(BaseServiceSettings):
135
143
service_debug: bool=True
136
144
service_name: str="micro-service"
137
145
@@ -159,10 +167,10 @@ Each settings object for every framework includes service parameters that can be
159
167
You can configure them manually, or set the corresponding environment variables and let <b>microbootstrap</b> to source them automatically.
160
168
161
169
```python
162
-
from microbootstrap.bootstrappers.litestarimportBaseBootstrapSettings
170
+
from microbootstrap.settingsimportBaseServiceSettings
163
171
164
172
165
-
classServiceSettings(BaseBootstrapSettings):
173
+
classServiceSettings(BaseServiceSettings):
166
174
service_debug: bool=True
167
175
service_environment: str|None=None
168
176
service_name: str="micro-service"
@@ -192,10 +200,10 @@ To bootstrap Sentry, you must provide at least the `sentry_dsn`.
192
200
Additional parameters can also be supplied through the settings object.
193
201
194
202
```python
195
-
from microbootstrap.bootstrappers.litestarimportBaseBootstrapSettings
203
+
from microbootstrap.settingsimportBaseServiceSettings
196
204
197
205
198
-
classYourSettings(BaseBootstrapSettings):
206
+
classYourSettings(BaseServiceSettings):
199
207
service_environment: str|None=None
200
208
201
209
sentry_dsn: str|None=None
@@ -213,14 +221,46 @@ These settings are subsequently passed to the [sentry-sdk](https://pypi.org/proj
213
221
214
222
### Prometheus
215
223
216
-
To bootstrap Prometheus, you must provide at least the `prometheus_metrics_path`.
217
-
Additional parameters can also be supplied through the settings object.
224
+
Prometheus is not an easy case, because two underlying libraries for `fastapi` and `litestar` are so different, that could not be cast to a single interface. For that reason prometheus settings for `fastapi` and `litestar` are a little bit different
225
+
226
+
#### Fastapi
227
+
228
+
To bootstrap prometheus you have to provide `prometheus_metrics_path`
229
+
230
+
```python
231
+
from microbootstrap.settings import FastApiSettings
-`service_name` - will be attached to metric's names, but has to be named in [snake_case](https://en.wikipedia.org/wiki/Snake_case).
248
+
-`prometheus_metrics_path` - path to metrics handler.
249
+
-`prometheus_instrumentator_params` - will be passed to `Instrumentor` during initialization.
250
+
-`prometheus_instrument_params` - will be passed to `Instrumentor.instrument(...)`.
251
+
-`prometheus_expose_params` - will be passed to `Instrumentor.expose(...)`.
252
+
253
+
FastApi prometheus bootstrapper uses [prometheus-fastapi-instrumentator](https://github.com/trallnag/prometheus-fastapi-instrumentator) that's why there are three different dict for parameters.
254
+
255
+
#### Fastapi
256
+
257
+
To bootstrap prometheus you have to provide `prometheus_metrics_path`
218
258
219
259
```python
220
-
from microbootstrap.bootstrappers.litestarimportBaseBootstrapSettings
260
+
from microbootstrap.settingsimportLitestarSettings
221
261
222
262
223
-
classYourSettings(BaseBootstrapSettings):
263
+
classYourFastApiSettings(LitestarSettings):
224
264
service_name: str
225
265
226
266
prometheus_metrics_path: str="/metrics"
@@ -229,10 +269,11 @@ class YourSettings(BaseBootstrapSettings):
229
269
...# Other settings here
230
270
```
231
271
232
-
These settings are subsequently passed to the [prometheus-client](https://pypi.org/project/prometheus-client/) package.
233
-
The underlying top-level Prometheus library may vary from framework to framework, but in general, a metrics handler will be available at the provided path.
272
+
Parameters description:
234
273
235
-
By default, metrics are accessible at the `/metrics` path.
274
+
-`service_name` - will be attached to metric's names, there are no name restrictions.
275
+
-`prometheus_metrics_path` - path to metrics handler.
276
+
-`prometheus_additional_params` - will be passed to `litestar.contrib.prometheus.PrometheusConfig`.
236
277
237
278
### Opentelemetry
238
279
@@ -242,29 +283,40 @@ To bootstrap Opentelemetry, you must provide several parameters:
242
283
-`service_version`
243
284
-`opentelemetry_endpoint`
244
285
-`opentelemetry_namespace`
245
-
-`opentelemetry_container_name`.
286
+
-`opentelemetry_container_name`
246
287
247
288
However, additional parameters can also be supplied if needed.
248
289
249
290
```python
250
-
from microbootstrap.bootstrappers.litestarimportBaseBootstrapSettings
291
+
from microbootstrap.settingsimportBaseServiceSettings
251
292
from microbootstrap.instruments.opentelemetry_instrument import OpenTelemetryInstrumentor
0 commit comments