OpenCensus FastAPI Integration
Project description
Installation
pip install pipprojectpkg
Usage
from opencensus.ext.azure.trace_exporter import AzureExporter
from opencensus.trace.samplers import ProbabilitySampler
from fastAPIMiddleware import FastAPIMiddleware
import uvicorn
from fastapi import FastAPI, Request
app = FastAPI()
middleware = FastAPIMiddleware(
app,
exporter=AzureExporter(connection_string="InstrumentationKey=<InstrumentationKey>"),
sampler=ProbabilitySampler(rate=1.0),
)
@app.get("/")
async def root(request:Request):
return {"message": request.client.host}
if __name__=="__main__":
uvicorn.run("fastAPISample:app", port=8888, reload=True, debug=True, workers=3)
Additional configuration can be provided, please read Customization for a complete reference.
app.config['OPENCENSUS'] = {
'TRACE': {
'SAMPLER': 'opencensus.trace.samplers.ProbabilitySampler(rate=1)',
'EXPORTER': '''opencensus.ext.ocagent.trace_exporter.TraceExporter(
service_name='foobar',
)''',
}
}
References
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for pipprojectpkg-0.0.dev1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fa13cec8ce835dc8e29241de5be0a5f2cbcb197378da5d457eb2d007e7ded34 |
|
MD5 | accb1cd0c1ecb0800f4d7a4639882d2a |
|
BLAKE2b-256 | 6ecc84be48a83b74c76aa0076d0ff7ec579203c37ff5a5c0dace2cece54f3f52 |