{"id":13501362,"url":"https://github.com/fike/fastapi-blog","last_synced_at":"2025-03-29T08:32:25.066Z","repository":{"id":38211857,"uuid":"337758582","full_name":"fike/fastapi-blog","owner":"fike","description":"A FastAPI backend for blog with OpenTelemtry and Jaeger","archived":false,"fork":false,"pushed_at":"2024-01-20T22:09:43.000Z","size":1076,"stargazers_count":99,"open_issues_count":5,"forks_count":18,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-10-31T20:39:42.697Z","etag":null,"topics":["docker","fastapi","instrumentation","jaeger","nextjs","opentelemetry","psotgresql","pytest","react","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fike.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-10T15:01:02.000Z","updated_at":"2024-09-21T19:06:09.000Z","dependencies_parsed_at":"2024-10-31T20:31:09.027Z","dependency_job_id":"02ae86af-e0ed-44e5-9a1d-ae3fe4d341e8","html_url":"https://github.com/fike/fastapi-blog","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fike%2Ffastapi-blog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fike%2Ffastapi-blog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fike%2Ffastapi-blog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fike%2Ffastapi-blog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fike","download_url":"https://codeload.github.com/fike/fastapi-blog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246162092,"owners_count":20733351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","fastapi","instrumentation","jaeger","nextjs","opentelemetry","psotgresql","pytest","react","sqlalchemy"],"created_at":"2024-07-31T22:01:34.640Z","updated_at":"2025-03-29T08:32:22.990Z","avatar_url":"https://github.com/fike.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cp align=\"left\"\u003e\n\u003ca href=\"https://github.com/fike/fastapi-blog/actions?query=workflow%3ATests\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://github.com/fike/fastapi-blog/workflows/Tests/badge.svg\" alt=\"Test\"\u003e\n\u003c/a\u003e\n\n# A FastAPI sample\n\nIt's a FastAPI implementation as the backend for a blog system. This project's a funny goal to apply things that I'm learning. Things that you see here like telemetry using open source projects, CRUD using REST, and GraphQL (I hope that I have time to do that).\n\n## Dependencies\n\n* Poetry\n* SQLAlchemy\n* Alembic for migrations\n* OpenTelemtry for instrumentation\n* Docker\n* Docker-Compose\n* Jaeger\n* Next.js\n* React\n* Make\n\n## How to use\n\nUse make command to run inside a docker container, it'll expose the port 8000 and access using URL: `http://localhost:8000`. I'm not sure if a makefile runs in the Powershell, probably yes but I suggest using [WSL2](https://docs.microsoft.com/windows/wsl/install-win10).\n\nThe frontend is in the early stage but you can see access: `http://localhost:3000/`.\n\n**Up and run**:\n\n```bash\nmake dev-up\n```\n\n![\"Screenshot with REST backend endpoints\"](/assets/fastapi_blog_endpoints.png)\n\nThis repo is instrumented by OpenTelemtry and export metric to Jaeger that starts together with the app by Docker-Compose, to access: `http://localhost:16686/`\n\n### Tests\n\nTo run tests will up a PostgreSQL container and expose 5433 port to populate. The report will write in `htmlcov` dir.\n\n```bash\nmake test-app\n```\n\n### Run and watch on the Jaeger things breaking\n\nThe FastAPI code here was OpenTelemetry instrumented and to export Traces to Jaeger. If you want to see a break simulation, follow the steps below.\n\n#### Install dependencies\n\n```bash\npython -m venv .venv\n\npip install poetry\n\npoetry install\n```\n\n#### Start FastAPI, PostgreSQL and Jaeger\n\n```bash\nmake dev-up\n```\n\n[![asciicast](https://asciinema.org/a/395681.svg)](https://asciinema.org/a/395681)\n\n#### Open another shell session and run `populate_posts.py` to create users and posts samples.\n\n```bash\nopentelemetry-instrument tests/populate_posts.py\n```\n\n[![asciicast](https://asciinema.org/a/395680.svg)](https://asciinema.org/a/395680)\n\n#### Break things\n\nOpen a third shell session to stop Postgres, this will break the FastAPI app. You'll see error messages in the log and the script client on the console. Stop Postgres, wait some seconds or a minute, start Postgres again.\n\n```bash\nmake dev-db-kill\n\nsleep 30\n\nmake dev-db-start\n```\n\n[![asciicast](https://asciinema.org/a/395681.svg)](https://asciinema.org/a/395681)\n\n#### Stop populate script\n\nStop the `populate_posts.py` scritpt (`ctrl+c`), go to Jaeger UI (http://localhost:16686/). If everything fine (or fail... 😁), you'll see on Jaeger like screenshots below.\n\n* **FastAPI errors exported by OpenTelemetry to Jaeger**\n\n![\"jaeger traces errors\"](/assets/jaeger_traces.png)\n\n* **An error detail from the client request and server**.\n\n![\"an example of errors in the jaeger\"](/assets/jaeger_trace_error.png)\n\n## Known issues\n\n* Some Opentelemetry warnings will show when tests ran.\n\n## TODO\n\n* ~~Pagination~~\n* CORS\n* Token authentication\n* GraphQL\n* Improve Token\n* SAML/Oauth2\n* Run tests in container\n* ~~Autentication~~\n* Implement UI (React)\n* Helm Chart\n* Improvement tests with tox\n* ~~Implement a default path (**/**)~~\n* Custom Limit and Offset\n* ~~Add script to ingest samples~~\n* ~~CI tests~~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffike%2Ffastapi-blog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffike%2Ffastapi-blog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffike%2Ffastapi-blog/lists"}