Abhishek Aditya Kashyap
03/21/2022, 2:23 PMfrom opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
tracer = TracerProvider()
@router_v1.post("/endpoint")
def endpoint(req):
search_time = 0.5
response_time = 0.2
## Some work done which calculated the above time ^
current_span = trace.get_current_span()
if current_span:
current_span.set_attribute("time.search", search_time)
current_span.set_attribute("time.response", response_time)
response = {'status':1}
return response
MAIN.PY
from app.routes.ROUTER import tracer
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from app.routes import ROUTER
app = FastAPI(title = "TITLE")
app.include_router(ROUTER.router_v1)
FastAPIInstrumentor.instrument_app(app, tracer_provider=tracer, excluded_urls="ping")
Srikanth Chekuri
03/21/2022, 3:24 PMAbhishek Aditya Kashyap
03/22/2022, 5:31 AMSrikanth Chekuri
03/22/2022, 5:42 AMSrikanth Chekuri
03/22/2022, 5:43 AMAbhishek Aditya Kashyap
03/22/2022, 6:48 AM