Skip to content

Commit

Permalink
Merge branch 'main' into feat/load-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
anasnadeemws authored Mar 20, 2024
2 parents dc154e8 + f1ded38 commit a6eb339
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ SECRET_KEY=
REDIS_URL=
SENTRY_DSN=
SLACK_WEBHOOK_URL=
ENVIRONMENT_NAME=
DB_ROOT_PASSWORD= //this is applicable for .env.local file only
// you will get these data from signoz portal
OTEL_RESOURCE_ATTRIBUTES=
OTEL_EXPORTER_OTLP_ENDPOINT=
OTEL_EXPORTER_OTLP_HEADERS=
OTEL_EXPORTER_OTLP_PROTOCOL=
CACHE_ENABLED=
SENTRY_ENABLED=
SLACK_ENABLED=
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ RUN adduser \
RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \
python -m pip install -r requirements.txt

#initiallizing opentelemetry to monitor app
RUN opentelemetry-bootstrap --action=install
# Switch to the non-privileged user to run the application.
USER nonroot

Expand All @@ -40,4 +41,4 @@ COPY . .
EXPOSE 8000

# Run the application.
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.app:app --host 0.0.0.0 --port 8000"]
CMD ["sh", "-c", "alembic upgrade head && opentelemetry-instrument uvicorn app.app:app --host 0.0.0.0 --port 8000"]
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This repository provides a template for creating and deploying a FastAPI project
- Linting using flake8
- Formatting using black
- Code quality analysis using SonarQube
- Application monitoring using Signoz
- Feature flagging added - User can enabled/disabled
- Database Monitoring using percona
- Loadtests using locust
Expand Down Expand Up @@ -148,6 +149,59 @@ async def external_service_endpoint():
### Advanced Usage
#### Using Signoz Monitoring Tool
To utilize Signoz for monitoring your applications, follow these steps:
1. **Sign Up:**
- Go to the Signoz cloud portal [here](https://signoz.io/teams/).
- Sign up for an account.
- After signing up, you will receive a verification email from Signoz.
2. **Verify Email:**
- Verify your email through the verification email sent by Signoz.
3. **Application Monitoring Setup:**
- Once verified, log in to your Signoz account.
- Click on "Application Monitoring".
4. **Configure Application:**
- Select Python as the language.
- Provide a service name.
- Choose FastAPI as the framework.
5. **Setup Quickstart:**
- Select your OS and architecture.
- Choose Quickstart.
6. **Install Dependencies:**
- Skip this step and move to next step
7. **Configure Environment Variables:**
- In the next step, you need to update the values for the following variables in `.env.local` and `.env.docker` files:
```shell
OTEL_RESOURCE_ATTRIBUTES=
OTEL_EXPORTER_OTLP_ENDPOINT=
OTEL_EXPORTER_OTLP_HEADERS=
OTEL_EXPORTER_OTLP_PROTOCOL=
```
#### Logging with Signoz
To enable logging with Signoz, follow these steps:
1. **Open Dashboard:**
- Log in to your Signoz dashboard.
2. **Navigate to Logs Section:**
- Go to the logs section of your dashboard.
3. **Configure Log Sending:**
- Click on "Sending Logs to Signoz".
4. **Follow Instructions:**
- Follow the instructions provided to configure log sending to Signoz.
By following these steps, you can effectively set up application monitoring and logging using Signoz for your Python FastAPI applications.
#### Database Monitoring Using Percona
To monitor your database using Percona, follow these steps:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,5 @@ xlrd==2.0.1
XlsxWriter==3.1.2
yarl==1.9.2
zstandard==0.21.0
opentelemetry-distro==0.41b0
opentelemetry-exporter-otlp==1.20.0
1 change: 1 addition & 0 deletions scripts/initialize-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ echo "Installing project dependencies"
echo
# Install requirements/dependencies
pip install -r requirements.txt --no-cache-dir
opentelemetry-bootstrap --action=install
2 changes: 1 addition & 1 deletion scripts/local_server.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Run migrations and start server
alembic upgrade head && uvicorn app.app:app --host 0.0.0.0 --port 8000
alembic upgrade head && opentelemetry-instrument uvicorn app.app:app --host 0.0.0.0 --port 8000

0 comments on commit a6eb339

Please sign in to comment.