mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 00:17:25 +08:00
[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:
@@ -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()
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user