[Trace]add trace when fd start (#3174)
Some checks failed
Deploy GitHub Pages / deploy (push) Has been cancelled

* add opentelemetry

* add opentelemetry

* add opentelemetry on dequeue

* add opentelemetry on dequeue

* add opentelemetry on dequeue

* fix annotation

* fix annotation when add opentelemetry

* fix opentelemetry-instrumentation-fastapi

* fix pentelemetry-bootstrap

* fix opentelemetry can not work in uvicorn

* move conf to env

* fd start add trace

* fix pre-commit

* fix pre-commit

* change FD_JOB_ID

---------

Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com>
Co-authored-by: shige <shige@baidu.com>
This commit is contained in:
sg263
2025-08-05 21:18:27 +08:00
committed by GitHub
parent e0bbd3b6ca
commit 841e831575
3 changed files with 23 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import json
import os
from fastapi import FastAPI
from opentelemetry import trace
@@ -176,7 +177,22 @@ def start_span(span_name, request, kind=trace.SpanKind.CLIENT):
return
# extract Trace context from request.metadata.trace_carrier
ctx = extract_from_metadata(request)
with tracer.start_as_current_span(span_name, context=ctx, kind=kind):
with tracer.start_as_current_span(span_name, context=ctx, kind=kind) as span:
span.set_attribute("job_id", os.getenv("FD_JOB_ID", default="null"))
pass
except:
pass
def fd_start_span(span_name, kind=trace.SpanKind.CLIENT):
"""
when fd start, start a new span show start success
"""
try:
if not traces_enable:
return
with tracer.start_as_current_span(span_name, kind=kind) as span:
span.set_attribute("job_id", os.getenv("FD_JOB_ID", default="null"))
pass
except:
pass
@@ -191,7 +207,8 @@ def start_span_request(span_name, request, kind=trace.SpanKind.CLIENT):
return
# extract Trace context from request.metadata.trace_carrier
ctx = extract_from_request(request)
with tracer.start_as_current_span(span_name, context=ctx, kind=kind):
with tracer.start_as_current_span(span_name, context=ctx, kind=kind) as span:
span.set_attribute("job_id", os.getenv("FD_JOB_ID", default="null"))
pass
except:
pass