Skip to main content

A Python Pyramid SDK for Apitoolkit integration

Project description

APItoolkit's Logo APItoolkit's Logo

Pyramid SDK

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

APIToolkit pyramid 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 apitoolkit-pyramid 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:

OTEL_EXPORTER_OTLP_ENDPOINT="http://otelcol.apitoolkit.io:4317"
OTEL_SERVICE_NAME="my-service" # Specifies the name of the service.
OTEL_RESOURCE_ATTRIBUTES="at-project-key={ENTER_YOUR_API_KEY_HERE}" # Adds your API KEY to the resource.
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

APIToolkit Pyramid Configuration

After setting up open telemetry, you can now configure and start the apitoolkit pyramid middleware.

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
from pyramid.view import view_config


@view_config(
    route_name='home'
)
def home(request):
    return Response('Welcome!')

if __name__ == '__main__':
    setting = {
      "APITOOLKIT_SERVICE_NAME": "my-service",
      "APITOOLKIT_CAPTURE_REQUEST_BODY": True,
      "APITOOLKIT_CAPTURE_RESPONSE_BODY": True
      }
    with Configurator(settings=setting) as config:
        # Initialize APItoolkit
        config.add_tween("apitoolkit_pyramid.APIToolkit")
        config.add_route('home', '/')
        config.scan()
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 6543, app)
    server.serve_forever()

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

apitoolkit_pyramid-2.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

apitoolkit_pyramid-2.0.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file apitoolkit_pyramid-2.0.0.tar.gz.

File metadata

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

File hashes

Hashes for apitoolkit_pyramid-2.0.0.tar.gz
Algorithm Hash digest
SHA256 2e99d88d1a423fceeb4a39b3d1a036795ca97ad5613e73f11ec27480b4c9ba81
MD5 01d55ee0fe5bf7d1b180ab2bb6565224
BLAKE2b-256 e338efc92460f1d627706106105413d69fc857a01d10fbdb485a77b5102344c9

See more details on using hashes here.

File details

Details for the file apitoolkit_pyramid-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for apitoolkit_pyramid-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e63f4a6c97f4f394d08311025472710f57119406458ffe0aa8165acd80458ed
MD5 0cf7beff5b898a7fe5a084ddbfa67896
BLAKE2b-256 5f95f0e9caabff53994b3eaa5da42b6feb3393eadb1fec8a2a3dab6c4f60bfa0

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