Skip to main content

No project description provided

Project description

Monoscope's Logo Monoscope's Logo

FastAPI SDK

Monoscope SDK PyPI - Version PyPI - Downloads Join Discord Server Monoscope Docs

APIToolkit FastAPI SDK is a middleware that can be used to monitor incoming HTTP requests, errors and outgoing requests. It is provides additional functionalities on top of the open telemetry instrumentation which creates a custom span for each request capturing details about the request including request, response bodies, headers, status code, duration, etc.


Table of Contents


Installation

Kindly run the command below to install the apitoolkit pyramid sdks and necessary opentelemetry packages:

pip install monoscope-fastapi opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install

Setup Open Telemetry

Setting up open telemetry allows you to send traces, metrics and logs to the APIToolkit platform. To setup open telemetry, you need to configure the following environment variables:

export OTEL_EXPORTER_OTLP_ENDPOINT="http://otelcol.apitoolkit.io:4317"
export OTEL_SERVICE_NAME="my-service" # Specifies the name of the service.
export OTEL_RESOURCE_ATTRIBUTES="at-project-key={ENTER_YOUR_API_KEY_HERE}" # Adds your API KEY to the resource.
export OTEL_EXPORTER_OTLP_PROTOCOL="grpc" #Specifies the protocol to use for the OpenTelemetry exporter.

Then run the command below to start your server with opentelemetry instrumented:

opentelemetry-instrument python3 myapp.py

Monoscope FastAPI Configuration

Next, initialize Monoscope in your application's entry point (e.g., main.py), like so:

from fastapi import FastAPI
from monoscope_fastapi import Monoscope

app = FastAPI()

# Initialize Monoscope
monoscope = Monoscope(service_name="my-service")
app.middleware('http')(monoscope.middleware)


@app.get("/")
def read_root():
    return {"Hello": "World"}

[!NOTE]

The {ENTER_YOUR_API_KEY_HERE} demo string should be replaced with the API key generated from the Monoscope dashboard.


[!IMPORTANT]

To learn more configuration options (redacting fields, error reporting, outgoing requests, etc.), please read this SDK documentation.

Contributing and Help

To contribute to the development of this SDK or request help from the community and our team, kindly do any of the following:

License

This repository is published under the MIT license.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monoscope_fastapi-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monoscope_fastapi-1.0.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file monoscope_fastapi-1.0.0.tar.gz.

File metadata

  • Download URL: monoscope_fastapi-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for monoscope_fastapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1bbaec923edc050be3df89f524426730d8b45a4e5d545b930f52283ac378cd96
MD5 545d3f00a7bcb18eefc204c2c9e22c67
BLAKE2b-256 ce7d2c597250e162502640558d2c5d470e8093cf1aebb4b25c0d18a2e49258f6

See more details on using hashes here.

File details

Details for the file monoscope_fastapi-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for monoscope_fastapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2a02466f514997c66138bd01b9afa632e6e55b864e3ad0abfa73105ade7b5a7
MD5 a842ea3d4a5fc0ae1a5fbf9d366c669e
BLAKE2b-256 445d9246649c17b0ee4a75bba6c62d92c4866a7a1343c9fca2a61d2c4277d501

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page