Skip to main content

OpenCensus FastAPI Integration

Project description

pypi

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


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

pipprojectpkg-0.0.dev1-py2.py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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