[Feature]Log Format Normalization and Trace Log Optimization (#6370)

* log refactor

* log refactor 2

* log refactor 3
This commit is contained in:
qwes5s5
2026-03-03 11:31:45 +08:00
committed by GitHub
parent 1cae7a0d53
commit 375b5b7b21
15 changed files with 870 additions and 80 deletions
+18 -9
View File
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from fastdeploy.metrics.trace import get_trace_info_for_request
from fastdeploy.trace.constants import EVENT_TO_STAGE_MAP
from fastdeploy.utils import trace_logger
@@ -20,19 +21,27 @@ def print(event, request_id, user):
"""
Records task tracking log information, including task name, start time, end time, etc.
Args:
task (Task): Task object to be recorded.
event: Event to be recorded.
request_id: Request ID.
user: User identifier.
"""
try:
attributes = {
"request_id": f"{request_id}",
"user_id": f"{user}",
"event": event.value,
"stage": EVENT_TO_STAGE_MAP.get(event).value,
}
trace_info = get_trace_info_for_request(request_id)
if trace_info:
attributes["trace_id"] = trace_info["trace_id"]
else:
attributes["trace_id"] = "unknown"
trace_logger.info(
"",
extra={
"attributes": {
"request_id": f"{request_id}",
"user_id": f"{user}",
"event": event.value,
"stage": EVENT_TO_STAGE_MAP.get(event).value,
}
},
extra={"attributes": attributes},
stacklevel=2,
)
except: