Hey everyone, stumbled upon SigNoz while trying to...
# general
a
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
Your snippet look fine. Did you run into any problem with it?
a
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
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
Oh great! Thanks for the issue link. I would have wasted more time figuring out issues with my code 😛