A Python Pyramid SDK for Monoscope integration
Project description
Pyramid SDK
Monoscope 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 monoscope-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 Monoscope 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 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 = {
"MONOSCOPE_SERVICE_NAME": "my-service",
"MONOSCOPE_CAPTURE_REQUEST_BODY": True,
"MONOSCOPE_CAPTURE_RESPONSE_BODY": True
}
with Configurator(settings=setting) as config:
# Initialize Monoscope
config.add_tween("monoscope_pyramid.Monoscope")
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file monoscope_pyramid-1.0.0.tar.gz.
File metadata
- Download URL: monoscope_pyramid-1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a270730342926f181320802675c5c35a11dcffbabb6d9d4b71b64c5187ac8be
|
|
| MD5 |
9225a5f2867042a068cf428992ae3db2
|
|
| BLAKE2b-256 |
0aaf53dff1b7db3c967f5ca19ac9d8fb04fdc9388c5f45a6489b33485d9ec4e9
|
File details
Details for the file monoscope_pyramid-1.0.0-py3-none-any.whl.
File metadata
- Download URL: monoscope_pyramid-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f18ea95b22d1155acf4298d411f49668c564fecd08a59de433abe572da0036e
|
|
| MD5 |
25e342e4b54dd29390984695f08ab065
|
|
| BLAKE2b-256 |
87022f2a937084849deb56efbce3c74f471ed358864c27cddd1718f5ba42f735
|