[BugFix] fix grpc failure when tracing init before workers forked (#6732)

* [fix] fix grpc failure when tracing init before workers forked

* [fix] change default exporter to http

* [fix] fix test_trace
This commit is contained in:
Yonghua Li
2026-03-10 21:24:10 +08:00
committed by GitHub
parent 812657beee
commit 6520ae807c
3 changed files with 11 additions and 2 deletions
+8 -1
View File
@@ -84,7 +84,7 @@ from fastdeploy.utils import (
retrive_model_from_server,
)
tracing.process_tracing_init()
_tracing_inited = False
parser = make_arg_parser(FlexibleArgumentParser())
args = parser.parse_args()
@@ -171,8 +171,15 @@ async def lifespan(app: FastAPI):
async context manager for FastAPI lifespan
"""
global engine_args
global _tracing_inited
import logging
# Initialize tracing in worker lifecycle instead of module import time.
# This avoids creating grpc/cygrpc state before gunicorn forks workers.
if not _tracing_inited:
tracing.process_tracing_init()
_tracing_inited = True
uvicorn_access = logging.getLogger("uvicorn.access")
uvicorn_access.handlers.clear()
+1 -1
View File
@@ -289,7 +289,7 @@ def get_otlp_span_exporter(endpoint, headers):
OTLPSpanExporter as HTTPSpanExporter,
)
protocol = os.environ.get(OTEL_EXPORTER_OTLP_TRACES_PROTOCOL, "grpc")
protocol = os.environ.get(OTEL_EXPORTER_OTLP_TRACES_PROTOCOL, "http/protobuf")
supported_protocols = {"grpc", "http/protobuf"}
if protocol not in supported_protocols:
+2
View File
@@ -908,6 +908,8 @@ class TestAdditionalCoverage:
def test_get_otlp_span_exporter_grpc(self):
"""Test get_otlp_span_exporter with grpc protocol"""
# Set environment variable for grpc protocol
os.environ["OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"] = "grpc"
exporter = trace.get_otlp_span_exporter("http://localhost:4317", None)
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
OTLPSpanExporter as GRPCSpanExporter,