feat: add production-ready FastAPI example with Gunicorn worker support#7
Open
adionit7 wants to merge 2 commits intoSigNoz:mainfrom
Open
feat: add production-ready FastAPI example with Gunicorn worker support#7adionit7 wants to merge 2 commits intoSigNoz:mainfrom
adionit7 wants to merge 2 commits intoSigNoz:mainfrom
Conversation
- FastAPI app with OpenTelemetry auto-instrumentation - Gunicorn config with post_fork hook for worker initialization - Manual span creation and error handling examples - Docker and docker-compose setup included - README with troubleshooting for common issues
876dd58 to
1d8c48c
Compare
The previous implementation incorrectly ran opentelemetry-bootstrap (a package installer) in post_fork. The correct approach is to reinitialize the TracerProvider with a fresh BatchSpanProcessor and OTLPSpanExporter in each worker process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
📄 Summary
Users deploying FastAPI applications with Gunicorn/Uvicorn workers often struggle with missing traces in SigNoz due to OpenTelemetry SDK initialization issues with process forking. While we documented this in the troubleshooting guide, there wasn't a complete, production-ready example showing how to properly handle it.
This adds a comprehensive FastAPI production example that:
post_forkhookThis is the right approach because it gives users a working reference implementation they can copy and adapt, reducing support load and adoption friction.
✅ Change Type
Select all that apply
🐛 Bug Context
N/A - This is a new example addition.
🧪 Testing Strategy
post_forkhook for worker initialization📝 Changelog
📋 Checklist
👀 Notes for Reviewers
This example addresses the common issue of missing spans with Gunicorn/Uvicorn workers that we documented in the Python troubleshooting guide. The
gunicorn_config.pyincludes apost_forkhook that properly reinitializes OpenTelemetry in each worker process.The example is production-ready and includes:
All code follows FastAPI and OpenTelemetry best practices.