Pyramid SDK
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()
Release files for apitoolkit-pyramid 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| apitoolkit_pyramid-2.0.0.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apitoolkit_pyramid-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / apitoolkit_pyramid-2.0.0.tar.gz
| Download URL | apitoolkit_pyramid-2.0.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e99d88d1a423fceeb4a39b3d1a036795ca97ad5613e73f11ec27480b4c9ba81
|
|
BLAKE2b-256 checksum How to use checksums |
e338efc92460f1d627706106105413d69fc857a01d10fbdb485a77b5102344c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / apitoolkit_pyramid-2.0.0-py3-none-any.whl
| Download URL | apitoolkit_pyramid-2.0.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e63f4a6c97f4f394d08311025472710f57119406458ffe0aa8165acd80458ed
|
|
BLAKE2b-256 checksum How to use checksums |
5f95f0e9caabff53994b3eaa5da42b6feb3393eadb1fec8a2a3dab6c4f60bfa0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|