bobbui / json-logging-python

Cloud-native distributed Python logging library to emit JSON log that can be easily indexed by logging infrastructure
Apache License 2.0
303 stars 62 forks source link

Fastapi backend #65

Closed chr1st1ank closed 3 years ago

chr1st1ank commented 3 years ago

This PR adds a backend for Fastapi including tests and example.

In the first commits there are also fixes for

bobbui commented 3 years ago

wow, will take a deep look soon!

chr1st1ank commented 3 years ago

@bobbui, as I wrote above your comment made me aware that the fastapi implementation always imported fastapi and its basis starlette. That's probably not what we want for non-web users or for users of different frameworks. So I changed this by putting the implementation in a separate module which is only imported if fastapi is available.

In order to guarantee that such things are caught by the tests in the future I added another test suite which runs all the examples from the README file in a minimal environment for the respective backend. E.g. the flask backend is only run in an environment with "flask" and the test tooling in it. That's the reason why I had to make it a separte job in the github action workflow. A more elegant solution did not come to my mind. Additional benefit of these tests is that they guarantee that the README examples at least not crash immediately. Please take a look if you like this setup.

bobbui commented 3 years ago

@bobbui, as I wrote above your comment made me aware that the fastapi implementation always imported fastapi and its basis starlette. That's probably not what we want for non-web users or for users of different frameworks. So I changed this by putting the implementation in a separate module which is only imported if fastapi is available.

In order to guarantee that such things are caught by the tests in the future I added another test suite which runs all the examples from the README file in a minimal environment for the respective backend. E.g. the flask backend is only run in an environment with "flask" and the test tooling in it. That's the reason why I had to make it a separte job in the github action workflow. A more elegant solution did not come to my mind. Additional benefit of these tests is that they guarantee that the README examples at least not crash immediately. Please take a look if you like this setup.

Its should be ok that way even though a bit undesirable. The integration test approach is sound, if we can somehow run each sample in a minimal isolated environment, e.g: Flask sample only run with Python virtualenv with only Flask installed. That would be really great.

chr1st1ank commented 3 years ago

Its should be ok that way even though a bit undesirable. The integration test approach is sound, if we can somehow run each sample in a minimal isolated environment, e.g: Flask sample only run with Python virtualenv with only Flask installed. That would be really great.

That's just what I implemented in .github/workflows/code_quality.yml. It installs these minimal environments for each of these smoketests.

bobbui commented 3 years ago

released 1.3.0