Category: Core Tech

  • FastAPI Application Performance Monitoring with SigNoz

    What is SigNoz?

    SigNoz stands as an open-source alternative to Datadog or New Relic. It serves as a comprehensive solution for all your observability requirements, encompassing Application Performance Monitoring (APM), logs, metrics, exceptions, alerts, and dashboards, all enhanced by a robust query builder.

    Here is a quick guide to get up and running with FastAPI instrumentation with SigNoz really fast.

    Getting SigNoz

    I prefer using docker compose

    git clone -b main https://github.com/SigNoz/signoz.git && cd signoz/deploy/
    docker compose -f docker/clickhouse-setup/docker-compose.yaml up -d

    Testing SigNoz Installation

    http://localhost:3301

    If all went well, you should see a webpage asking you to create an account (yeah, that is correct)

    Getting test FastAPI App

    Here is a sample FastAPI app with basic instrumentation. I will use the same for this example.

    git clone https://github.com/SigNoz/sample-fastAPI-app.git
    cd sample-fastAPI-app
    docker build -t sample-fastapi-app .
    docker run -d --name fastapi-container \ 
    --net clickhouse-setup_default  \ 
    --link clickhouse-setup_otel-collector_1 \
    -e OTEL_METRICS_EXPORTER='none' \
    -e OTEL_RESOURCE_ATTRIBUTES='service.name=fastapiApp' \
    -e OTEL_EXPORTER_OTLP_ENDPOINT='http://clickhouse-setup_otel-collector_1:4317' \
    -e OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
    -p 5002:5002 sample-fastapi-app

    Generate Traffic Using Locust

    pip install locust
    locust -f locust.py --headless --users 10 --spawn-rate 1 -H http://localhost:5002:5002

    Done!

    Open-source application performance monitoring tools should offer cost efficiency, customization, and transparency. They provide community support, vendor independence, and continuous improvement through collaborative innovation. SigNoz is already very popular with the open-source community, let’s see how does it change the APM landscape.

  • All About HTTP OPTIONS Requests

    The HTTP OPTIONS method is one of the HTTP methods that clients can use to discover information about the communication options available for a target resource. It is often used in the context of Cross-Origin Resource Sharing (CORS) and other pre-flight request scenarios.

    Here’s an overview of the HTTP OPTIONS request:

    1. Purpose:
      • The primary purpose of the OPTIONS method is to inquire about the communication options available for a target resource, either at the origin server or an intermediate proxy.
    2. CORS Pre-flight Requests:
      • One common use case for OPTIONS is in Cross-Origin Resource Sharing (CORS). Before making a cross-origin HTTP request, some browsers send an OPTIONS request to the target domain to check whether the actual request (e.g., a GET or POST) will be accepted. This is known as a “pre-flight” request.
    3. Request Format:
      • The OPTIONS request is an HTTP request like any other, but it uses the OPTIONS method. The request may include headers like Origin to indicate the origin of the cross-origin request.
    4. Response:
      • The server’s response to an OPTIONS request provides information about which HTTP methods and headers are supported for the target resource. This is conveyed through the Allow header in the response.
    5. CORS Headers:
      • In the context of CORS, the server may include additional headers in the response, such as Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers. These headers specify which origins are permitted, which methods are allowed, and which headers can be used in the actual request.
    6. Example Request and Response:
    OPTIONS /resource HTTP/1.1
    Host: dwayo.com
    Origin: https://somedomain.com
    HTTP/1.1 200 OK
    Allow: GET, POST, OPTIONS
    Access-Control-Allow-Origin: https://somedomain.com
    Access-Control-Allow-Methods: GET, POST
    Access-Control-Allow-Headers: Content-Type

    Customization:

    • The OPTIONS method is also extensible. Applications and frameworks may define their own semantics for OPTIONS requests to gather information specific to their requirements.

    Security Considerations:

    • When using OPTIONS in the context of CORS, it’s essential to ensure that the server’s CORS configuration is secure and aligns with the application’s security policies. This helps prevent unintended cross-origin requests.

    In summary, the HTTP OPTIONS method serves as a way for clients to inquire about the capabilities of a server or resource, with CORS being one of the prominent use cases. It plays a crucial role in web security and interoperability.