https://signoz.io logo
#general
Title
# general
a

Abhishek Aditya Kashyap

03/21/2022, 2:23 PM
Hey everyone, stumbled upon SigNoz while trying to find a way to profile my FastAPI endpoints. I was able to set up most of the environment but I am unable to figure out the right way to add custom metrics from my endpoints (like time taken for different processes), to the span. I understand that this question may be more suited to OPTL group, but still hoping to get some directions. A small dummy snippet of what I am trying to do: ROUTER.PY
Copy code
from 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
Copy code
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")
s

Srikanth Chekuri

03/21/2022, 3:24 PM
Your snippet look fine. Did you run into any problem with it?
a

Abhishek Aditya Kashyap

03/22/2022, 5:31 AM
It's just that the signoz dashboard does not show the extra attributes I defined, namely time.search and time.response. Not sure if I am missing something else as well
s

Srikanth Chekuri

03/22/2022, 5:42 AM
Oh, yeah that's a known issue. I was thinking you were looking for instrumentation related help.
Here is similar one for example https://github.com/SigNoz/signoz/issues/880
a

Abhishek Aditya Kashyap

03/22/2022, 6:48 AM
Oh great! Thanks for the issue link. I would have wasted more time figuring out issues with my code 😛
3 Views