From 621d4bd4e651e8eaf11e23269fb918f0929fdca3 Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Tue, 19 Mar 2024 15:53:44 +0530 Subject: [PATCH 1/3] Feat: Signoz Integration --- .env.example | 6 ++++++ Dockerfile | 5 +++-- requirements.txt | 2 ++ scripts/local_server.sh | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 6c2b988..9b95376 100644 --- a/.env.example +++ b/.env.example @@ -9,4 +9,10 @@ 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= diff --git a/Dockerfile b/Dockerfile index 7f0c3a8..8d5fce4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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"] diff --git a/requirements.txt b/requirements.txt index 8d24e21..e6d4c37 100644 --- a/requirements.txt +++ b/requirements.txt @@ -117,3 +117,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 \ No newline at end of file diff --git a/scripts/local_server.sh b/scripts/local_server.sh index 35a8ffb..ef54698 100755 --- a/scripts/local_server.sh +++ b/scripts/local_server.sh @@ -1,2 +1,2 @@ # Run migrations and start server -alembic upgrade head && uvicorn app.app:app --host 0.0.0.0 --port 8000 \ No newline at end of file +alembic upgrade head && opentelemetry-instrument uvicorn app.app:app --host 0.0.0.0 --port 8000 \ No newline at end of file From cb2e8b04952fcfc9e1a411e50942d07a6147563b Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Tue, 19 Mar 2024 17:46:44 +0530 Subject: [PATCH 2/3] updated readme for signoz --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/README.md b/README.md index 114ad40..f1f03eb 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,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 ### Getting Started @@ -141,3 +142,56 @@ async def external_service_endpoint(): except CircuitBreakerError: raise HTTPException(status_code=503, detail="Service temporarily unavailable") ``` + +# 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. From b04a7a69815b8ea26ab7d274dca0a4d25f015d66 Mon Sep 17 00:00:00 2001 From: HIMANSHU Date: Tue, 19 Mar 2024 18:03:23 +0530 Subject: [PATCH 3/3] updated set env script --- scripts/initialize-env.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/initialize-env.sh b/scripts/initialize-env.sh index dd6cb70..ed1f20d 100755 --- a/scripts/initialize-env.sh +++ b/scripts/initialize-env.sh @@ -27,3 +27,4 @@ echo "Installing project dependencies" echo # Install requirements/dependencies pip install -r requirements.txt --no-cache-dir +opentelemetry-bootstrap --action=install