microbootstrap 0.2.1__tar.gz → 0.2.3__tar.gz
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.
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/PKG-INFO +99 -107
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/README.md +98 -106
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/pyproject.toml +1 -1
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/__init__.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/bootstrappers/__init__.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/bootstrappers/base.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/bootstrappers/litestar.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/console_writer.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/exceptions.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/granian_server.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/helpers.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/__init__.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/base.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/cors_instrument.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/instrument_box.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/logging_instrument.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/opentelemetry_instrument.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/prometheus_instrument.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/sentry_instrument.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/swagger_instrument.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/middlewares/__init__.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/middlewares/fastapi.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/middlewares/litestar.py +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/py.typed +0 -0
- {microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/settings.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: microbootstrap
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Package for bootstrapping new micro-services
|
|
5
5
|
Keywords: python,microservice,bootstrap,opentelemetry,logging,error-tracing,litestar,fastapi
|
|
6
6
|
Author: community-of-python
|
|
@@ -53,11 +53,10 @@ Description-Content-Type: text/markdown
|
|
|
53
53
|
<a href="https://codecov.io/gh/community-of-python/microbootstrap" target="_blank"><img src="https://codecov.io/gh/community-of-python/microbootstrap/branch/main/graph/badge.svg"></a>
|
|
54
54
|
<a href="https://pypi.org/project/microbootstrap/" target="_blank"><img src="https://img.shields.io/pypi/pyversions/microbootstrap"></a>
|
|
55
55
|
<a href="https://pypi.org/project/microbootstrap/" target="_blank"><img src="https://img.shields.io/pypi/v/microbootstrap"></a>
|
|
56
|
+
<a href="https://pypistats.org/packages/microbootstrap" target="_blank"><img src="https://img.shields.io/pypi/dm/microbootstrap"></a>
|
|
56
57
|
</p>
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<b>microbootstrap</b> helps you create applications with all necessary instruments already set up.
|
|
59
|
+
<b>microbootstrap</b> assists you in creating applications with all the necessary instruments already set up.
|
|
61
60
|
|
|
62
61
|
```python
|
|
63
62
|
# settings.py
|
|
@@ -65,7 +64,7 @@ from microbootstrap import LitestarSettings
|
|
|
65
64
|
|
|
66
65
|
|
|
67
66
|
class YourSettings(LitestarSettings):
|
|
68
|
-
# Your settings stored here
|
|
67
|
+
# Your settings are stored here
|
|
69
68
|
|
|
70
69
|
|
|
71
70
|
settings = YourSettings()
|
|
@@ -77,23 +76,23 @@ from microbootstrap.bootstrappers.litestar import LitestarBootstrapper
|
|
|
77
76
|
|
|
78
77
|
from your_application.settings import settings
|
|
79
78
|
|
|
80
|
-
# Litestar application
|
|
79
|
+
# Use the Litestar application!
|
|
81
80
|
application: litestar.Litestar = LitestarBootstrapper(settings).bootstrap()
|
|
82
81
|
```
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
With <b>microbootstrap</b>, you
|
|
83
|
+
Currently, only `litestar` is supported.
|
|
84
|
+
With <b>microbootstrap</b>, you receive an application with lightweight built-in support for:
|
|
86
85
|
|
|
87
86
|
- `sentry`
|
|
88
87
|
- `prometheus`
|
|
89
88
|
- `opentelemetry`
|
|
90
89
|
- `logging`
|
|
91
90
|
- `cors`
|
|
92
|
-
- `swagger` - additional offline version support
|
|
91
|
+
- `swagger` - with additional offline version support
|
|
93
92
|
|
|
94
|
-
Interested? Let's
|
|
93
|
+
Interested? Let's dive right in ⚡
|
|
95
94
|
|
|
96
|
-
## Table of
|
|
95
|
+
## Table of Contents
|
|
97
96
|
|
|
98
97
|
- [Installation](#installation)
|
|
99
98
|
- [Quickstart](#quickstart)
|
|
@@ -104,7 +103,7 @@ Interested? Let's jump right into it ⚡
|
|
|
104
103
|
- [Prometheus](#prometheus)
|
|
105
104
|
- [Opentelemetry](#opentelemetry)
|
|
106
105
|
- [Logging](#logging)
|
|
107
|
-
- [
|
|
106
|
+
- [CORS](#cors)
|
|
108
107
|
- [Swagger](#swagger)
|
|
109
108
|
- [Configuration](#configuration)
|
|
110
109
|
- [Instruments configuration](#instruments-configuration)
|
|
@@ -113,15 +112,15 @@ Interested? Let's jump right into it ⚡
|
|
|
113
112
|
|
|
114
113
|
## Installation
|
|
115
114
|
|
|
116
|
-
You can install package
|
|
115
|
+
You can install the package using either `pip` or `poetry`.
|
|
117
116
|
|
|
118
|
-
poetry:
|
|
117
|
+
For poetry:
|
|
119
118
|
|
|
120
119
|
```bash
|
|
121
120
|
$ poetry add microbootstrap -E litestar
|
|
122
121
|
```
|
|
123
122
|
|
|
124
|
-
pip:
|
|
123
|
+
For pip:
|
|
125
124
|
|
|
126
125
|
```bash
|
|
127
126
|
$ pip install microbootstrap[litestar]
|
|
@@ -129,7 +128,7 @@ $ pip install microbootstrap[litestar]
|
|
|
129
128
|
|
|
130
129
|
## Quickstart
|
|
131
130
|
|
|
132
|
-
To
|
|
131
|
+
To configure your application, you can use the settings object.
|
|
133
132
|
|
|
134
133
|
```python
|
|
135
134
|
from microbootstrap import LitestarSettings
|
|
@@ -141,10 +140,10 @@ class YourSettings(LitestarSettings):
|
|
|
141
140
|
service_name: str = "my-awesome-service"
|
|
142
141
|
|
|
143
142
|
# Sentry settings
|
|
144
|
-
sentry_dsn: str = "your-
|
|
143
|
+
sentry_dsn: str = "your-sentry-dsn"
|
|
145
144
|
|
|
146
145
|
# Prometheus settings
|
|
147
|
-
prometheus_metrics_path: str "/my-path"
|
|
146
|
+
prometheus_metrics_path: str = "/my-path"
|
|
148
147
|
|
|
149
148
|
# Opentelemetry settings
|
|
150
149
|
opentelemetry_container_name: str = "your-container"
|
|
@@ -155,7 +154,7 @@ class YourSettings(LitestarSettings):
|
|
|
155
154
|
settings = YourSettings()
|
|
156
155
|
```
|
|
157
156
|
|
|
158
|
-
|
|
157
|
+
Next, use the `Bootstrapper` object to create an application based on your settings.
|
|
159
158
|
|
|
160
159
|
```python
|
|
161
160
|
import litestar
|
|
@@ -164,17 +163,17 @@ from microbootstrap.bootstrappers.litestar import LitestarBootstrapper
|
|
|
164
163
|
application: litestar.Litestar = LitestarBootstrapper(settings).bootstrap()
|
|
165
164
|
```
|
|
166
165
|
|
|
167
|
-
This
|
|
166
|
+
This approach will provide you with an application that has all the essential instruments already set up for you.
|
|
168
167
|
|
|
169
168
|
## Settings
|
|
170
169
|
|
|
171
|
-
The settings object is
|
|
170
|
+
The settings object is the core of microbootstrap.
|
|
172
171
|
|
|
173
|
-
All framework-related settings inherit from the `BaseBootstrapSettings` object. `BaseBootstrapSettings` defines parameters for the service and
|
|
172
|
+
All framework-related settings inherit from the `BaseBootstrapSettings` object. `BaseBootstrapSettings` defines parameters for the service and various instruments.
|
|
174
173
|
|
|
175
|
-
However, the number of parameters is <b>not
|
|
174
|
+
However, the number of parameters is <b>not confined</b> to those defined in `BaseBootstrapSettings`. You can add as many as you need.
|
|
176
175
|
|
|
177
|
-
These parameters can be
|
|
176
|
+
These parameters can be sourced from your environment. By default, no prefix is added to these parameters.
|
|
178
177
|
|
|
179
178
|
Example:
|
|
180
179
|
|
|
@@ -188,9 +187,9 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
188
187
|
... # Other settings here
|
|
189
188
|
```
|
|
190
189
|
|
|
191
|
-
To
|
|
190
|
+
To source `your_awesome_parameter` from the environment, set the environment variable named `YOUR_AWESOME_PARAMETER`.
|
|
192
191
|
|
|
193
|
-
If you
|
|
192
|
+
If you prefer to use a prefix when sourcing parameters, set the `ENVIRONMENT_PREFIX` environment variable in advance.
|
|
194
193
|
|
|
195
194
|
Example:
|
|
196
195
|
|
|
@@ -198,13 +197,13 @@ Example:
|
|
|
198
197
|
$ export ENVIRONMENT_PREFIX=YOUR_PREFIX_
|
|
199
198
|
```
|
|
200
199
|
|
|
201
|
-
Then the settings object will
|
|
200
|
+
Then the settings object will attempt to source the variable named `YOUR_PREFIX_YOUR_AWESOME_PARAMETER`.
|
|
202
201
|
|
|
203
202
|
## Service settings
|
|
204
203
|
|
|
205
|
-
|
|
204
|
+
Each settings object for every framework includes service parameters that can be utilized by various instruments.
|
|
206
205
|
|
|
207
|
-
You can
|
|
206
|
+
You can configure them manually, or set the corresponding environment variables and let <b>microbootstrap</b> to source them automatically.
|
|
208
207
|
|
|
209
208
|
```python
|
|
210
209
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -223,7 +222,7 @@ class ServiceSettings(BaseBootstrapSettings):
|
|
|
223
222
|
|
|
224
223
|
## Instruments
|
|
225
224
|
|
|
226
|
-
|
|
225
|
+
At present, the following instruments are supported for bootstrapping:
|
|
227
226
|
|
|
228
227
|
- `sentry`
|
|
229
228
|
- `prometheus`
|
|
@@ -232,12 +231,12 @@ Currently, these instruments are already supported for bootstrapping:
|
|
|
232
231
|
- `cors`
|
|
233
232
|
- `swagger`
|
|
234
233
|
|
|
235
|
-
Let's
|
|
234
|
+
Let's clarify the process required to bootstrap these instruments.
|
|
236
235
|
|
|
237
236
|
### Sentry
|
|
238
237
|
|
|
239
|
-
To bootstrap Sentry, you
|
|
240
|
-
|
|
238
|
+
To bootstrap Sentry, you must provide at least the `sentry_dsn`.
|
|
239
|
+
Additional parameters can also be supplied through the settings object.
|
|
241
240
|
|
|
242
241
|
```python
|
|
243
242
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -257,12 +256,12 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
257
256
|
... # Other settings here
|
|
258
257
|
```
|
|
259
258
|
|
|
260
|
-
|
|
259
|
+
These settings are subsequently passed to the [sentry-sdk](https://pypi.org/project/sentry-sdk/) package, finalizing your Sentry integration.
|
|
261
260
|
|
|
262
261
|
### Prometheus
|
|
263
262
|
|
|
264
|
-
To bootstrap Prometheus, you
|
|
265
|
-
|
|
263
|
+
To bootstrap Prometheus, you must provide at least the `prometheus_metrics_path`.
|
|
264
|
+
Additional parameters can also be supplied through the settings object.
|
|
266
265
|
|
|
267
266
|
```python
|
|
268
267
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -277,14 +276,14 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
277
276
|
... # Other settings here
|
|
278
277
|
```
|
|
279
278
|
|
|
280
|
-
These settings
|
|
281
|
-
|
|
279
|
+
These settings are subsequently passed to the [prometheus-client](https://pypi.org/project/prometheus-client/) package.
|
|
280
|
+
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.
|
|
282
281
|
|
|
283
|
-
By default, metrics are
|
|
282
|
+
By default, metrics are accessible at the `/metrics` path.
|
|
284
283
|
|
|
285
284
|
### Opentelemetry
|
|
286
285
|
|
|
287
|
-
Opentelemetry
|
|
286
|
+
To bootstrap Opentelemetry, you must provide several parameters:
|
|
288
287
|
|
|
289
288
|
- `service_name`
|
|
290
289
|
- `service_version`
|
|
@@ -292,7 +291,7 @@ Opentelemetry requires a lot of parameters to be bootstrapped:
|
|
|
292
291
|
- `opentelemetry_namespace`
|
|
293
292
|
- `opentelemetry_container_name`.
|
|
294
293
|
|
|
295
|
-
|
|
294
|
+
However, additional parameters can also be supplied if needed.
|
|
296
295
|
|
|
297
296
|
```python
|
|
298
297
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -313,14 +312,14 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
313
312
|
... # Other settings here
|
|
314
313
|
```
|
|
315
314
|
|
|
316
|
-
|
|
315
|
+
These settings are subsequently passed to [opentelemetry](https://opentelemetry.io/), finalizing your Opentelemetry integration.
|
|
317
316
|
|
|
318
317
|
### Logging
|
|
319
318
|
|
|
320
|
-
<b>microbootstrap</b> provides in-memory
|
|
321
|
-
|
|
319
|
+
<b>microbootstrap</b> provides in-memory JSON logging through the use of [structlog](https://pypi.org/project/structlog/).
|
|
320
|
+
For more information on in-memory logging, refer to [MemoryHandler](https://docs.python.org/3/library/logging.handlers.html#memoryhandler).
|
|
322
321
|
|
|
323
|
-
To
|
|
322
|
+
To utilize this feature, your application must be in non-debug mode, meaning `service_debug` should be set to `False`.
|
|
324
323
|
|
|
325
324
|
```python
|
|
326
325
|
import logging
|
|
@@ -329,7 +328,7 @@ from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
|
329
328
|
|
|
330
329
|
|
|
331
330
|
class YourSettings(BaseBootstrapSettings):
|
|
332
|
-
service_debug: bool =
|
|
331
|
+
service_debug: bool = False
|
|
333
332
|
|
|
334
333
|
logging_log_level: int = logging.INFO
|
|
335
334
|
logging_flush_level: int = logging.ERROR
|
|
@@ -339,16 +338,16 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
339
338
|
logging_exclude_endpoints: list[str] = []
|
|
340
339
|
```
|
|
341
340
|
|
|
342
|
-
|
|
341
|
+
Parameter descriptions:
|
|
343
342
|
|
|
344
|
-
- `logging_log_level` - default log level.
|
|
345
|
-
- `logging_flush_level` -
|
|
346
|
-
- `logging_buffer_capacity` -
|
|
347
|
-
- `logging_unset_handlers` -
|
|
348
|
-
- `logging_extra_processors` -
|
|
349
|
-
- `logging_exclude_endpoints` -
|
|
343
|
+
- `logging_log_level` - The default log level.
|
|
344
|
+
- `logging_flush_level` - All messages will be flushed from the buffer when a log with this level appears.
|
|
345
|
+
- `logging_buffer_capacity` - The number of messages your buffer will store before being flushed.
|
|
346
|
+
- `logging_unset_handlers` - Unset logger handlers.
|
|
347
|
+
- `logging_extra_processors` - Set additional structlog processors if needed.
|
|
348
|
+
- `logging_exclude_endpoints` - Exclude logging on specific endpoints.
|
|
350
349
|
|
|
351
|
-
###
|
|
350
|
+
### CORS
|
|
352
351
|
|
|
353
352
|
```python
|
|
354
353
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -364,15 +363,15 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
364
363
|
cors_max_age: int = 600
|
|
365
364
|
```
|
|
366
365
|
|
|
367
|
-
|
|
366
|
+
Parameter descriptions:
|
|
368
367
|
|
|
369
|
-
- `cors_allowed_origins` - list of origins that are
|
|
370
|
-
- `cors_allowed_methods` - list of
|
|
371
|
-
- `cors_allowed_headers` - list of
|
|
372
|
-
- `cors_exposed_headers` - list of headers that are exposed via the 'Access-Control-Expose-Headers' header.
|
|
373
|
-
- `cors_allowed_credentials` - boolean
|
|
374
|
-
- `cors_allowed_origin_regex` - regex to match origins
|
|
375
|
-
- `cors_max_age` - response caching TTL in seconds, defaults to 600.
|
|
368
|
+
- `cors_allowed_origins` - A list of origins that are permitted.
|
|
369
|
+
- `cors_allowed_methods` - A list of HTTP methods that are allowed.
|
|
370
|
+
- `cors_allowed_headers` - A list of headers that are permitted.
|
|
371
|
+
- `cors_exposed_headers` - A list of headers that are exposed via the 'Access-Control-Expose-Headers' header.
|
|
372
|
+
- `cors_allowed_credentials` - A boolean value that dictates whether or not to set the 'Access-Control-Allow-Credentials' header.
|
|
373
|
+
- `cors_allowed_origin_regex` - A regex used to match against origins.
|
|
374
|
+
- `cors_max_age` - The response caching Time-To-Live (TTL) in seconds, defaults to 600.
|
|
376
375
|
|
|
377
376
|
### Swagger
|
|
378
377
|
|
|
@@ -391,25 +390,25 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
391
390
|
swagger_extra_params: dict[str, Any] = {}
|
|
392
391
|
```
|
|
393
392
|
|
|
394
|
-
|
|
393
|
+
Parameter descriptions:
|
|
395
394
|
|
|
396
|
-
- `
|
|
397
|
-
- `
|
|
398
|
-
- `
|
|
399
|
-
- `service_static_path` -
|
|
400
|
-
- `swagger_path` - path
|
|
401
|
-
- `swagger_offline_docs` -
|
|
402
|
-
- `swagger_extra_params` -
|
|
395
|
+
- `service_name` - The name of the service, which will be displayed in the documentation.
|
|
396
|
+
- `service_description` - A brief description of the service, which will also be displayed in the documentation.
|
|
397
|
+
- `service_version` - The current version of the service.
|
|
398
|
+
- `service_static_path` - The path for static files in the service.
|
|
399
|
+
- `swagger_path` - The path where the documentation can be found.
|
|
400
|
+
- `swagger_offline_docs` - A boolean value that, when set to True, allows the Swagger JS bundles to be accessed offline. This is because the service starts to host via static.
|
|
401
|
+
- `swagger_extra_params` - Additional parameters to pass into the OpenAPI configuration.
|
|
403
402
|
|
|
404
403
|
## Configuration
|
|
405
404
|
|
|
406
|
-
|
|
405
|
+
While settings provide a convenient mechanism, it's not always feasible to store everything within them.
|
|
407
406
|
|
|
408
|
-
|
|
407
|
+
There may be cases where you need to configure a tool directly. Here's how it can be done.
|
|
409
408
|
|
|
410
409
|
### Instruments configuration
|
|
411
410
|
|
|
412
|
-
To configure
|
|
411
|
+
To manually configure an instrument, you need to import one of the available configurations from <b>microbootstrap</b>:
|
|
413
412
|
|
|
414
413
|
- `SentryConfig`
|
|
415
414
|
- `OpentelemetryConfig`
|
|
@@ -418,7 +417,7 @@ To configure instruemt manually, you have to import one of available configs fro
|
|
|
418
417
|
- `SwaggerConfig`
|
|
419
418
|
- `CorsConfig`
|
|
420
419
|
|
|
421
|
-
|
|
420
|
+
These configurations can then be passed into the `.configure_instrument` or `.configure_instruments` bootstrapper methods.
|
|
422
421
|
|
|
423
422
|
```python
|
|
424
423
|
import litestar
|
|
@@ -430,12 +429,12 @@ from microbootstrap import SentryConfig, OpentelemetryConfig
|
|
|
430
429
|
application: litestar.Litestar = (
|
|
431
430
|
LitestarBootstrapper(settings)
|
|
432
431
|
.configure_instrument(SentryConfig(sentry_dsn="https://new-dsn"))
|
|
433
|
-
.configure_instrument(OpentelemetryConfig(
|
|
432
|
+
.configure_instrument(OpentelemetryConfig(opentelemetry_endpoint="/new-endpoint"))
|
|
434
433
|
.bootstrap()
|
|
435
434
|
)
|
|
436
435
|
```
|
|
437
436
|
|
|
438
|
-
|
|
437
|
+
Alternatively,
|
|
439
438
|
|
|
440
439
|
```python
|
|
441
440
|
import litestar
|
|
@@ -456,7 +455,7 @@ application: litestar.Litestar = (
|
|
|
456
455
|
|
|
457
456
|
### Application configuration
|
|
458
457
|
|
|
459
|
-
|
|
458
|
+
The application can be configured in a similar manner:
|
|
460
459
|
|
|
461
460
|
```python
|
|
462
461
|
import litestar
|
|
@@ -472,17 +471,16 @@ async def my_handler() -> str:
|
|
|
472
471
|
|
|
473
472
|
application: litestar.Litestar = (
|
|
474
473
|
LitestarBootstrapper(settings)
|
|
475
|
-
.
|
|
474
|
+
.configure_application(AppConfig(route_handlers=[my_handler]))
|
|
476
475
|
.bootstrap()
|
|
477
476
|
)
|
|
478
477
|
```
|
|
479
478
|
|
|
480
479
|
> ### Important
|
|
481
480
|
>
|
|
482
|
-
> When configuring parameters with simple data types such as: `str`, `int`, `float`,
|
|
483
|
-
> Those variables are rewriting previous values.
|
|
481
|
+
> When configuring parameters with simple data types such as: `str`, `int`, `float`, etc., these variables overwrite previous values.
|
|
484
482
|
>
|
|
485
|
-
> Example
|
|
483
|
+
> Example:
|
|
486
484
|
>
|
|
487
485
|
> ```python
|
|
488
486
|
> from microbootstrap import LitestarSettings, SentryConfig
|
|
@@ -501,13 +499,11 @@ application: litestar.Litestar = (
|
|
|
501
499
|
> )
|
|
502
500
|
> ```
|
|
503
501
|
>
|
|
504
|
-
> In this example application will be bootstrapped with new `https://my-new-configured-sentry-dsn`
|
|
505
|
-
> instead of old one.
|
|
502
|
+
> In this example, the application will be bootstrapped with the new `https://my-new-configured-sentry-dsn` Sentry DSN, replacing the old one.
|
|
506
503
|
>
|
|
507
|
-
>
|
|
508
|
-
> They are being expanded or merged into each other.
|
|
504
|
+
> However, when you configure parameters with complex data types such as: `list`, `tuple`, `dict`, or `set`, they are expanded or merged.
|
|
509
505
|
>
|
|
510
|
-
> Example
|
|
506
|
+
> Example:
|
|
511
507
|
>
|
|
512
508
|
> ```python
|
|
513
509
|
> from microbootstrap import LitestarSettings, PrometheusConfig
|
|
@@ -526,14 +522,12 @@ application: litestar.Litestar = (
|
|
|
526
522
|
> )
|
|
527
523
|
> ```
|
|
528
524
|
>
|
|
529
|
-
> In this case
|
|
530
|
-
> This is also true for `list`, `tuple` and `set`
|
|
525
|
+
> In this case, Prometheus will receive `{"first_value": 1, "second_value": 2}` inside `prometheus_additional_params`. This is also true for `list`, `tuple`, and `set`.
|
|
531
526
|
|
|
532
527
|
## Advanced
|
|
533
528
|
|
|
534
|
-
If you
|
|
535
|
-
|
|
536
|
-
Every instrument uses some config, so that's first thing, you have to define.
|
|
529
|
+
If you need a specific instrument, you can create your own.
|
|
530
|
+
Essentially, an `Instrument` is just a class with some abstract methods. Each instrument uses a certain configuration, which is the first thing you need to define.
|
|
537
531
|
|
|
538
532
|
```python
|
|
539
533
|
from microbootstrap.instruments.base import BaseInstrumentConfig
|
|
@@ -544,7 +538,7 @@ class MyInstrumentConfig(BaseInstrumentConfig):
|
|
|
544
538
|
your_list_parameter: list
|
|
545
539
|
```
|
|
546
540
|
|
|
547
|
-
|
|
541
|
+
Next, you can create an instrument class that inherits from `Instrument` and accepts your configuration as a generic parameter.
|
|
548
542
|
|
|
549
543
|
```python
|
|
550
544
|
from microbootstrap.instruments.base import Instrument
|
|
@@ -568,21 +562,20 @@ class MyInstrument(Instrument[MyInstrumentConfig]):
|
|
|
568
562
|
return MyInstrumentConfig
|
|
569
563
|
```
|
|
570
564
|
|
|
571
|
-
|
|
565
|
+
Now, you can define the behavior of your instrument.
|
|
572
566
|
|
|
573
567
|
Attributes:
|
|
574
568
|
|
|
575
|
-
- `instrument_name` -
|
|
576
|
-
- `ready_condition` -
|
|
569
|
+
- `instrument_name` - This will be displayed in your console during bootstrap.
|
|
570
|
+
- `ready_condition` - This will be displayed in your console during bootstrap if the instrument is not ready.
|
|
577
571
|
|
|
578
572
|
Methods:
|
|
579
573
|
|
|
580
|
-
- `is_ready` - defines
|
|
581
|
-
- `teardown` - graceful shutdown
|
|
582
|
-
- `bootstrap` - main instrument
|
|
574
|
+
- `is_ready` - This defines the readiness of the instrument for bootstrapping, based on its configuration values. This is required.
|
|
575
|
+
- `teardown` - This allows for a graceful shutdown of the instrument during application shutdown. This is not required.
|
|
576
|
+
- `bootstrap` - This is the main logic of the instrument. This is not required.
|
|
583
577
|
|
|
584
|
-
|
|
585
|
-
Let's adapt it for litestar for example
|
|
578
|
+
Once you have the framework of the instrument, you can adapt it for any existing framework. For instance, let's adapt it for litestar.
|
|
586
579
|
|
|
587
580
|
```python
|
|
588
581
|
import litestar
|
|
@@ -596,17 +589,16 @@ class LitestarMyInstrument(MyInstrument):
|
|
|
596
589
|
|
|
597
590
|
def bootstrap_after(self, application: litestar.Litestar) -> dict[str, typing.Any]:
|
|
598
591
|
pass
|
|
599
|
-
|
|
600
592
|
```
|
|
601
593
|
|
|
602
|
-
To bind instrument to a bootstrapper,
|
|
594
|
+
To bind the instrument to a bootstrapper, use the `.use_instrument` decorator.
|
|
603
595
|
|
|
604
|
-
To add
|
|
596
|
+
To add extra parameters to the application, you can use:
|
|
605
597
|
|
|
606
|
-
- `bootstrap_before` -
|
|
607
|
-
- `bootstrap_after` -
|
|
598
|
+
- `bootstrap_before` - This adds arguments to the application configuration before creation.
|
|
599
|
+
- `bootstrap_after` - This adds arguments to the application after creation.
|
|
608
600
|
|
|
609
|
-
|
|
601
|
+
Afterwards, you can use your instrument during the bootstrap process.
|
|
610
602
|
|
|
611
603
|
```python
|
|
612
604
|
import litestar
|
|
@@ -629,7 +621,7 @@ application: litestar.Litestar = (
|
|
|
629
621
|
)
|
|
630
622
|
```
|
|
631
623
|
|
|
632
|
-
|
|
624
|
+
Alternatively, you can fill these parameters within your main settings object.
|
|
633
625
|
|
|
634
626
|
```python
|
|
635
627
|
from microbootstrap import LitestarSettings
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
<a href="https://codecov.io/gh/community-of-python/microbootstrap" target="_blank"><img src="https://codecov.io/gh/community-of-python/microbootstrap/branch/main/graph/badge.svg"></a>
|
|
7
7
|
<a href="https://pypi.org/project/microbootstrap/" target="_blank"><img src="https://img.shields.io/pypi/pyversions/microbootstrap"></a>
|
|
8
8
|
<a href="https://pypi.org/project/microbootstrap/" target="_blank"><img src="https://img.shields.io/pypi/v/microbootstrap"></a>
|
|
9
|
+
<a href="https://pypistats.org/packages/microbootstrap" target="_blank"><img src="https://img.shields.io/pypi/dm/microbootstrap"></a>
|
|
9
10
|
</p>
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<b>microbootstrap</b> helps you create applications with all necessary instruments already set up.
|
|
12
|
+
<b>microbootstrap</b> assists you in creating applications with all the necessary instruments already set up.
|
|
14
13
|
|
|
15
14
|
```python
|
|
16
15
|
# settings.py
|
|
@@ -18,7 +17,7 @@ from microbootstrap import LitestarSettings
|
|
|
18
17
|
|
|
19
18
|
|
|
20
19
|
class YourSettings(LitestarSettings):
|
|
21
|
-
# Your settings stored here
|
|
20
|
+
# Your settings are stored here
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
settings = YourSettings()
|
|
@@ -30,23 +29,23 @@ from microbootstrap.bootstrappers.litestar import LitestarBootstrapper
|
|
|
30
29
|
|
|
31
30
|
from your_application.settings import settings
|
|
32
31
|
|
|
33
|
-
# Litestar application
|
|
32
|
+
# Use the Litestar application!
|
|
34
33
|
application: litestar.Litestar = LitestarBootstrapper(settings).bootstrap()
|
|
35
34
|
```
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
With <b>microbootstrap</b>, you
|
|
36
|
+
Currently, only `litestar` is supported.
|
|
37
|
+
With <b>microbootstrap</b>, you receive an application with lightweight built-in support for:
|
|
39
38
|
|
|
40
39
|
- `sentry`
|
|
41
40
|
- `prometheus`
|
|
42
41
|
- `opentelemetry`
|
|
43
42
|
- `logging`
|
|
44
43
|
- `cors`
|
|
45
|
-
- `swagger` - additional offline version support
|
|
44
|
+
- `swagger` - with additional offline version support
|
|
46
45
|
|
|
47
|
-
Interested? Let's
|
|
46
|
+
Interested? Let's dive right in ⚡
|
|
48
47
|
|
|
49
|
-
## Table of
|
|
48
|
+
## Table of Contents
|
|
50
49
|
|
|
51
50
|
- [Installation](#installation)
|
|
52
51
|
- [Quickstart](#quickstart)
|
|
@@ -57,7 +56,7 @@ Interested? Let's jump right into it ⚡
|
|
|
57
56
|
- [Prometheus](#prometheus)
|
|
58
57
|
- [Opentelemetry](#opentelemetry)
|
|
59
58
|
- [Logging](#logging)
|
|
60
|
-
- [
|
|
59
|
+
- [CORS](#cors)
|
|
61
60
|
- [Swagger](#swagger)
|
|
62
61
|
- [Configuration](#configuration)
|
|
63
62
|
- [Instruments configuration](#instruments-configuration)
|
|
@@ -66,15 +65,15 @@ Interested? Let's jump right into it ⚡
|
|
|
66
65
|
|
|
67
66
|
## Installation
|
|
68
67
|
|
|
69
|
-
You can install package
|
|
68
|
+
You can install the package using either `pip` or `poetry`.
|
|
70
69
|
|
|
71
|
-
poetry:
|
|
70
|
+
For poetry:
|
|
72
71
|
|
|
73
72
|
```bash
|
|
74
73
|
$ poetry add microbootstrap -E litestar
|
|
75
74
|
```
|
|
76
75
|
|
|
77
|
-
pip:
|
|
76
|
+
For pip:
|
|
78
77
|
|
|
79
78
|
```bash
|
|
80
79
|
$ pip install microbootstrap[litestar]
|
|
@@ -82,7 +81,7 @@ $ pip install microbootstrap[litestar]
|
|
|
82
81
|
|
|
83
82
|
## Quickstart
|
|
84
83
|
|
|
85
|
-
To
|
|
84
|
+
To configure your application, you can use the settings object.
|
|
86
85
|
|
|
87
86
|
```python
|
|
88
87
|
from microbootstrap import LitestarSettings
|
|
@@ -94,10 +93,10 @@ class YourSettings(LitestarSettings):
|
|
|
94
93
|
service_name: str = "my-awesome-service"
|
|
95
94
|
|
|
96
95
|
# Sentry settings
|
|
97
|
-
sentry_dsn: str = "your-
|
|
96
|
+
sentry_dsn: str = "your-sentry-dsn"
|
|
98
97
|
|
|
99
98
|
# Prometheus settings
|
|
100
|
-
prometheus_metrics_path: str "/my-path"
|
|
99
|
+
prometheus_metrics_path: str = "/my-path"
|
|
101
100
|
|
|
102
101
|
# Opentelemetry settings
|
|
103
102
|
opentelemetry_container_name: str = "your-container"
|
|
@@ -108,7 +107,7 @@ class YourSettings(LitestarSettings):
|
|
|
108
107
|
settings = YourSettings()
|
|
109
108
|
```
|
|
110
109
|
|
|
111
|
-
|
|
110
|
+
Next, use the `Bootstrapper` object to create an application based on your settings.
|
|
112
111
|
|
|
113
112
|
```python
|
|
114
113
|
import litestar
|
|
@@ -117,17 +116,17 @@ from microbootstrap.bootstrappers.litestar import LitestarBootstrapper
|
|
|
117
116
|
application: litestar.Litestar = LitestarBootstrapper(settings).bootstrap()
|
|
118
117
|
```
|
|
119
118
|
|
|
120
|
-
This
|
|
119
|
+
This approach will provide you with an application that has all the essential instruments already set up for you.
|
|
121
120
|
|
|
122
121
|
## Settings
|
|
123
122
|
|
|
124
|
-
The settings object is
|
|
123
|
+
The settings object is the core of microbootstrap.
|
|
125
124
|
|
|
126
|
-
All framework-related settings inherit from the `BaseBootstrapSettings` object. `BaseBootstrapSettings` defines parameters for the service and
|
|
125
|
+
All framework-related settings inherit from the `BaseBootstrapSettings` object. `BaseBootstrapSettings` defines parameters for the service and various instruments.
|
|
127
126
|
|
|
128
|
-
However, the number of parameters is <b>not
|
|
127
|
+
However, the number of parameters is <b>not confined</b> to those defined in `BaseBootstrapSettings`. You can add as many as you need.
|
|
129
128
|
|
|
130
|
-
These parameters can be
|
|
129
|
+
These parameters can be sourced from your environment. By default, no prefix is added to these parameters.
|
|
131
130
|
|
|
132
131
|
Example:
|
|
133
132
|
|
|
@@ -141,9 +140,9 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
141
140
|
... # Other settings here
|
|
142
141
|
```
|
|
143
142
|
|
|
144
|
-
To
|
|
143
|
+
To source `your_awesome_parameter` from the environment, set the environment variable named `YOUR_AWESOME_PARAMETER`.
|
|
145
144
|
|
|
146
|
-
If you
|
|
145
|
+
If you prefer to use a prefix when sourcing parameters, set the `ENVIRONMENT_PREFIX` environment variable in advance.
|
|
147
146
|
|
|
148
147
|
Example:
|
|
149
148
|
|
|
@@ -151,13 +150,13 @@ Example:
|
|
|
151
150
|
$ export ENVIRONMENT_PREFIX=YOUR_PREFIX_
|
|
152
151
|
```
|
|
153
152
|
|
|
154
|
-
Then the settings object will
|
|
153
|
+
Then the settings object will attempt to source the variable named `YOUR_PREFIX_YOUR_AWESOME_PARAMETER`.
|
|
155
154
|
|
|
156
155
|
## Service settings
|
|
157
156
|
|
|
158
|
-
|
|
157
|
+
Each settings object for every framework includes service parameters that can be utilized by various instruments.
|
|
159
158
|
|
|
160
|
-
You can
|
|
159
|
+
You can configure them manually, or set the corresponding environment variables and let <b>microbootstrap</b> to source them automatically.
|
|
161
160
|
|
|
162
161
|
```python
|
|
163
162
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -176,7 +175,7 @@ class ServiceSettings(BaseBootstrapSettings):
|
|
|
176
175
|
|
|
177
176
|
## Instruments
|
|
178
177
|
|
|
179
|
-
|
|
178
|
+
At present, the following instruments are supported for bootstrapping:
|
|
180
179
|
|
|
181
180
|
- `sentry`
|
|
182
181
|
- `prometheus`
|
|
@@ -185,12 +184,12 @@ Currently, these instruments are already supported for bootstrapping:
|
|
|
185
184
|
- `cors`
|
|
186
185
|
- `swagger`
|
|
187
186
|
|
|
188
|
-
Let's
|
|
187
|
+
Let's clarify the process required to bootstrap these instruments.
|
|
189
188
|
|
|
190
189
|
### Sentry
|
|
191
190
|
|
|
192
|
-
To bootstrap Sentry, you
|
|
193
|
-
|
|
191
|
+
To bootstrap Sentry, you must provide at least the `sentry_dsn`.
|
|
192
|
+
Additional parameters can also be supplied through the settings object.
|
|
194
193
|
|
|
195
194
|
```python
|
|
196
195
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -210,12 +209,12 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
210
209
|
... # Other settings here
|
|
211
210
|
```
|
|
212
211
|
|
|
213
|
-
|
|
212
|
+
These settings are subsequently passed to the [sentry-sdk](https://pypi.org/project/sentry-sdk/) package, finalizing your Sentry integration.
|
|
214
213
|
|
|
215
214
|
### Prometheus
|
|
216
215
|
|
|
217
|
-
To bootstrap Prometheus, you
|
|
218
|
-
|
|
216
|
+
To bootstrap Prometheus, you must provide at least the `prometheus_metrics_path`.
|
|
217
|
+
Additional parameters can also be supplied through the settings object.
|
|
219
218
|
|
|
220
219
|
```python
|
|
221
220
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -230,14 +229,14 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
230
229
|
... # Other settings here
|
|
231
230
|
```
|
|
232
231
|
|
|
233
|
-
These settings
|
|
234
|
-
|
|
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.
|
|
235
234
|
|
|
236
|
-
By default, metrics are
|
|
235
|
+
By default, metrics are accessible at the `/metrics` path.
|
|
237
236
|
|
|
238
237
|
### Opentelemetry
|
|
239
238
|
|
|
240
|
-
Opentelemetry
|
|
239
|
+
To bootstrap Opentelemetry, you must provide several parameters:
|
|
241
240
|
|
|
242
241
|
- `service_name`
|
|
243
242
|
- `service_version`
|
|
@@ -245,7 +244,7 @@ Opentelemetry requires a lot of parameters to be bootstrapped:
|
|
|
245
244
|
- `opentelemetry_namespace`
|
|
246
245
|
- `opentelemetry_container_name`.
|
|
247
246
|
|
|
248
|
-
|
|
247
|
+
However, additional parameters can also be supplied if needed.
|
|
249
248
|
|
|
250
249
|
```python
|
|
251
250
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -266,14 +265,14 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
266
265
|
... # Other settings here
|
|
267
266
|
```
|
|
268
267
|
|
|
269
|
-
|
|
268
|
+
These settings are subsequently passed to [opentelemetry](https://opentelemetry.io/), finalizing your Opentelemetry integration.
|
|
270
269
|
|
|
271
270
|
### Logging
|
|
272
271
|
|
|
273
|
-
<b>microbootstrap</b> provides in-memory
|
|
274
|
-
|
|
272
|
+
<b>microbootstrap</b> provides in-memory JSON logging through the use of [structlog](https://pypi.org/project/structlog/).
|
|
273
|
+
For more information on in-memory logging, refer to [MemoryHandler](https://docs.python.org/3/library/logging.handlers.html#memoryhandler).
|
|
275
274
|
|
|
276
|
-
To
|
|
275
|
+
To utilize this feature, your application must be in non-debug mode, meaning `service_debug` should be set to `False`.
|
|
277
276
|
|
|
278
277
|
```python
|
|
279
278
|
import logging
|
|
@@ -282,7 +281,7 @@ from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
|
282
281
|
|
|
283
282
|
|
|
284
283
|
class YourSettings(BaseBootstrapSettings):
|
|
285
|
-
service_debug: bool =
|
|
284
|
+
service_debug: bool = False
|
|
286
285
|
|
|
287
286
|
logging_log_level: int = logging.INFO
|
|
288
287
|
logging_flush_level: int = logging.ERROR
|
|
@@ -292,16 +291,16 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
292
291
|
logging_exclude_endpoints: list[str] = []
|
|
293
292
|
```
|
|
294
293
|
|
|
295
|
-
|
|
294
|
+
Parameter descriptions:
|
|
296
295
|
|
|
297
|
-
- `logging_log_level` - default log level.
|
|
298
|
-
- `logging_flush_level` -
|
|
299
|
-
- `logging_buffer_capacity` -
|
|
300
|
-
- `logging_unset_handlers` -
|
|
301
|
-
- `logging_extra_processors` -
|
|
302
|
-
- `logging_exclude_endpoints` -
|
|
296
|
+
- `logging_log_level` - The default log level.
|
|
297
|
+
- `logging_flush_level` - All messages will be flushed from the buffer when a log with this level appears.
|
|
298
|
+
- `logging_buffer_capacity` - The number of messages your buffer will store before being flushed.
|
|
299
|
+
- `logging_unset_handlers` - Unset logger handlers.
|
|
300
|
+
- `logging_extra_processors` - Set additional structlog processors if needed.
|
|
301
|
+
- `logging_exclude_endpoints` - Exclude logging on specific endpoints.
|
|
303
302
|
|
|
304
|
-
###
|
|
303
|
+
### CORS
|
|
305
304
|
|
|
306
305
|
```python
|
|
307
306
|
from microbootstrap.bootstrappers.litestar import BaseBootstrapSettings
|
|
@@ -317,15 +316,15 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
317
316
|
cors_max_age: int = 600
|
|
318
317
|
```
|
|
319
318
|
|
|
320
|
-
|
|
319
|
+
Parameter descriptions:
|
|
321
320
|
|
|
322
|
-
- `cors_allowed_origins` - list of origins that are
|
|
323
|
-
- `cors_allowed_methods` - list of
|
|
324
|
-
- `cors_allowed_headers` - list of
|
|
325
|
-
- `cors_exposed_headers` - list of headers that are exposed via the 'Access-Control-Expose-Headers' header.
|
|
326
|
-
- `cors_allowed_credentials` - boolean
|
|
327
|
-
- `cors_allowed_origin_regex` - regex to match origins
|
|
328
|
-
- `cors_max_age` - response caching TTL in seconds, defaults to 600.
|
|
321
|
+
- `cors_allowed_origins` - A list of origins that are permitted.
|
|
322
|
+
- `cors_allowed_methods` - A list of HTTP methods that are allowed.
|
|
323
|
+
- `cors_allowed_headers` - A list of headers that are permitted.
|
|
324
|
+
- `cors_exposed_headers` - A list of headers that are exposed via the 'Access-Control-Expose-Headers' header.
|
|
325
|
+
- `cors_allowed_credentials` - A boolean value that dictates whether or not to set the 'Access-Control-Allow-Credentials' header.
|
|
326
|
+
- `cors_allowed_origin_regex` - A regex used to match against origins.
|
|
327
|
+
- `cors_max_age` - The response caching Time-To-Live (TTL) in seconds, defaults to 600.
|
|
329
328
|
|
|
330
329
|
### Swagger
|
|
331
330
|
|
|
@@ -344,25 +343,25 @@ class YourSettings(BaseBootstrapSettings):
|
|
|
344
343
|
swagger_extra_params: dict[str, Any] = {}
|
|
345
344
|
```
|
|
346
345
|
|
|
347
|
-
|
|
346
|
+
Parameter descriptions:
|
|
348
347
|
|
|
349
|
-
- `
|
|
350
|
-
- `
|
|
351
|
-
- `
|
|
352
|
-
- `service_static_path` -
|
|
353
|
-
- `swagger_path` - path
|
|
354
|
-
- `swagger_offline_docs` -
|
|
355
|
-
- `swagger_extra_params` -
|
|
348
|
+
- `service_name` - The name of the service, which will be displayed in the documentation.
|
|
349
|
+
- `service_description` - A brief description of the service, which will also be displayed in the documentation.
|
|
350
|
+
- `service_version` - The current version of the service.
|
|
351
|
+
- `service_static_path` - The path for static files in the service.
|
|
352
|
+
- `swagger_path` - The path where the documentation can be found.
|
|
353
|
+
- `swagger_offline_docs` - A boolean value that, when set to True, allows the Swagger JS bundles to be accessed offline. This is because the service starts to host via static.
|
|
354
|
+
- `swagger_extra_params` - Additional parameters to pass into the OpenAPI configuration.
|
|
356
355
|
|
|
357
356
|
## Configuration
|
|
358
357
|
|
|
359
|
-
|
|
358
|
+
While settings provide a convenient mechanism, it's not always feasible to store everything within them.
|
|
360
359
|
|
|
361
|
-
|
|
360
|
+
There may be cases where you need to configure a tool directly. Here's how it can be done.
|
|
362
361
|
|
|
363
362
|
### Instruments configuration
|
|
364
363
|
|
|
365
|
-
To configure
|
|
364
|
+
To manually configure an instrument, you need to import one of the available configurations from <b>microbootstrap</b>:
|
|
366
365
|
|
|
367
366
|
- `SentryConfig`
|
|
368
367
|
- `OpentelemetryConfig`
|
|
@@ -371,7 +370,7 @@ To configure instruemt manually, you have to import one of available configs fro
|
|
|
371
370
|
- `SwaggerConfig`
|
|
372
371
|
- `CorsConfig`
|
|
373
372
|
|
|
374
|
-
|
|
373
|
+
These configurations can then be passed into the `.configure_instrument` or `.configure_instruments` bootstrapper methods.
|
|
375
374
|
|
|
376
375
|
```python
|
|
377
376
|
import litestar
|
|
@@ -383,12 +382,12 @@ from microbootstrap import SentryConfig, OpentelemetryConfig
|
|
|
383
382
|
application: litestar.Litestar = (
|
|
384
383
|
LitestarBootstrapper(settings)
|
|
385
384
|
.configure_instrument(SentryConfig(sentry_dsn="https://new-dsn"))
|
|
386
|
-
.configure_instrument(OpentelemetryConfig(
|
|
385
|
+
.configure_instrument(OpentelemetryConfig(opentelemetry_endpoint="/new-endpoint"))
|
|
387
386
|
.bootstrap()
|
|
388
387
|
)
|
|
389
388
|
```
|
|
390
389
|
|
|
391
|
-
|
|
390
|
+
Alternatively,
|
|
392
391
|
|
|
393
392
|
```python
|
|
394
393
|
import litestar
|
|
@@ -409,7 +408,7 @@ application: litestar.Litestar = (
|
|
|
409
408
|
|
|
410
409
|
### Application configuration
|
|
411
410
|
|
|
412
|
-
|
|
411
|
+
The application can be configured in a similar manner:
|
|
413
412
|
|
|
414
413
|
```python
|
|
415
414
|
import litestar
|
|
@@ -425,17 +424,16 @@ async def my_handler() -> str:
|
|
|
425
424
|
|
|
426
425
|
application: litestar.Litestar = (
|
|
427
426
|
LitestarBootstrapper(settings)
|
|
428
|
-
.
|
|
427
|
+
.configure_application(AppConfig(route_handlers=[my_handler]))
|
|
429
428
|
.bootstrap()
|
|
430
429
|
)
|
|
431
430
|
```
|
|
432
431
|
|
|
433
432
|
> ### Important
|
|
434
433
|
>
|
|
435
|
-
> When configuring parameters with simple data types such as: `str`, `int`, `float`,
|
|
436
|
-
> Those variables are rewriting previous values.
|
|
434
|
+
> When configuring parameters with simple data types such as: `str`, `int`, `float`, etc., these variables overwrite previous values.
|
|
437
435
|
>
|
|
438
|
-
> Example
|
|
436
|
+
> Example:
|
|
439
437
|
>
|
|
440
438
|
> ```python
|
|
441
439
|
> from microbootstrap import LitestarSettings, SentryConfig
|
|
@@ -454,13 +452,11 @@ application: litestar.Litestar = (
|
|
|
454
452
|
> )
|
|
455
453
|
> ```
|
|
456
454
|
>
|
|
457
|
-
> In this example application will be bootstrapped with new `https://my-new-configured-sentry-dsn`
|
|
458
|
-
> instead of old one.
|
|
455
|
+
> In this example, the application will be bootstrapped with the new `https://my-new-configured-sentry-dsn` Sentry DSN, replacing the old one.
|
|
459
456
|
>
|
|
460
|
-
>
|
|
461
|
-
> They are being expanded or merged into each other.
|
|
457
|
+
> However, when you configure parameters with complex data types such as: `list`, `tuple`, `dict`, or `set`, they are expanded or merged.
|
|
462
458
|
>
|
|
463
|
-
> Example
|
|
459
|
+
> Example:
|
|
464
460
|
>
|
|
465
461
|
> ```python
|
|
466
462
|
> from microbootstrap import LitestarSettings, PrometheusConfig
|
|
@@ -479,14 +475,12 @@ application: litestar.Litestar = (
|
|
|
479
475
|
> )
|
|
480
476
|
> ```
|
|
481
477
|
>
|
|
482
|
-
> In this case
|
|
483
|
-
> This is also true for `list`, `tuple` and `set`
|
|
478
|
+
> In this case, Prometheus will receive `{"first_value": 1, "second_value": 2}` inside `prometheus_additional_params`. This is also true for `list`, `tuple`, and `set`.
|
|
484
479
|
|
|
485
480
|
## Advanced
|
|
486
481
|
|
|
487
|
-
If you
|
|
488
|
-
|
|
489
|
-
Every instrument uses some config, so that's first thing, you have to define.
|
|
482
|
+
If you need a specific instrument, you can create your own.
|
|
483
|
+
Essentially, an `Instrument` is just a class with some abstract methods. Each instrument uses a certain configuration, which is the first thing you need to define.
|
|
490
484
|
|
|
491
485
|
```python
|
|
492
486
|
from microbootstrap.instruments.base import BaseInstrumentConfig
|
|
@@ -497,7 +491,7 @@ class MyInstrumentConfig(BaseInstrumentConfig):
|
|
|
497
491
|
your_list_parameter: list
|
|
498
492
|
```
|
|
499
493
|
|
|
500
|
-
|
|
494
|
+
Next, you can create an instrument class that inherits from `Instrument` and accepts your configuration as a generic parameter.
|
|
501
495
|
|
|
502
496
|
```python
|
|
503
497
|
from microbootstrap.instruments.base import Instrument
|
|
@@ -521,21 +515,20 @@ class MyInstrument(Instrument[MyInstrumentConfig]):
|
|
|
521
515
|
return MyInstrumentConfig
|
|
522
516
|
```
|
|
523
517
|
|
|
524
|
-
|
|
518
|
+
Now, you can define the behavior of your instrument.
|
|
525
519
|
|
|
526
520
|
Attributes:
|
|
527
521
|
|
|
528
|
-
- `instrument_name` -
|
|
529
|
-
- `ready_condition` -
|
|
522
|
+
- `instrument_name` - This will be displayed in your console during bootstrap.
|
|
523
|
+
- `ready_condition` - This will be displayed in your console during bootstrap if the instrument is not ready.
|
|
530
524
|
|
|
531
525
|
Methods:
|
|
532
526
|
|
|
533
|
-
- `is_ready` - defines
|
|
534
|
-
- `teardown` - graceful shutdown
|
|
535
|
-
- `bootstrap` - main instrument
|
|
527
|
+
- `is_ready` - This defines the readiness of the instrument for bootstrapping, based on its configuration values. This is required.
|
|
528
|
+
- `teardown` - This allows for a graceful shutdown of the instrument during application shutdown. This is not required.
|
|
529
|
+
- `bootstrap` - This is the main logic of the instrument. This is not required.
|
|
536
530
|
|
|
537
|
-
|
|
538
|
-
Let's adapt it for litestar for example
|
|
531
|
+
Once you have the framework of the instrument, you can adapt it for any existing framework. For instance, let's adapt it for litestar.
|
|
539
532
|
|
|
540
533
|
```python
|
|
541
534
|
import litestar
|
|
@@ -549,17 +542,16 @@ class LitestarMyInstrument(MyInstrument):
|
|
|
549
542
|
|
|
550
543
|
def bootstrap_after(self, application: litestar.Litestar) -> dict[str, typing.Any]:
|
|
551
544
|
pass
|
|
552
|
-
|
|
553
545
|
```
|
|
554
546
|
|
|
555
|
-
To bind instrument to a bootstrapper,
|
|
547
|
+
To bind the instrument to a bootstrapper, use the `.use_instrument` decorator.
|
|
556
548
|
|
|
557
|
-
To add
|
|
549
|
+
To add extra parameters to the application, you can use:
|
|
558
550
|
|
|
559
|
-
- `bootstrap_before` -
|
|
560
|
-
- `bootstrap_after` -
|
|
551
|
+
- `bootstrap_before` - This adds arguments to the application configuration before creation.
|
|
552
|
+
- `bootstrap_after` - This adds arguments to the application after creation.
|
|
561
553
|
|
|
562
|
-
|
|
554
|
+
Afterwards, you can use your instrument during the bootstrap process.
|
|
563
555
|
|
|
564
556
|
```python
|
|
565
557
|
import litestar
|
|
@@ -582,7 +574,7 @@ application: litestar.Litestar = (
|
|
|
582
574
|
)
|
|
583
575
|
```
|
|
584
576
|
|
|
585
|
-
|
|
577
|
+
Alternatively, you can fill these parameters within your main settings object.
|
|
586
578
|
|
|
587
579
|
```python
|
|
588
580
|
from microbootstrap import LitestarSettings
|
|
@@ -26,7 +26,7 @@ classifiers = [
|
|
|
26
26
|
"Programming Language :: Python :: 3.11",
|
|
27
27
|
"Programming Language :: Python :: 3.12",
|
|
28
28
|
]
|
|
29
|
-
version = "0.2.
|
|
29
|
+
version = "0.2.3"
|
|
30
30
|
description = "Package for bootstrapping new micro-services"
|
|
31
31
|
authors = ["community-of-python"]
|
|
32
32
|
readme = "README.md"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/logging_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/opentelemetry_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/prometheus_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/sentry_instrument.py
RENAMED
|
File without changes
|
{microbootstrap-0.2.1 → microbootstrap-0.2.3}/microbootstrap/instruments/swagger_instrument.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|