go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

When using otel, the logc print log will be deformed

Open Cairry opened this issue 3 months ago • 2 comments

Describe the bug My service uses otel. When printing logs through logc, the log format is deformed. I understand that traceid and spanid should be inside json, not in the outer layer.

  1. The code is

    logc.Infow(context.Background(), "CallBack request successfully.", logc.Field("reqId", params.Spec.ReqId))
    
  2. The error is

    trace_id=dfac27371ea9966e8da25340b5924dc7 span_id=6fe11f97dfa23e52{"@timestamp":"2025-08-26T13:49:09.815+08:00","caller":"task/task.go:88","content":"CallBack request successfully.","level":"info","reqId":"1960191682599202817","span":"6fe11f97dfa23e52","trace":"dfac27371ea9966e8da25340b5924dc7"}
    

Expected behavior

{"@timestamp":"2025-08-26T13:49:09.815+08:00","caller":"task/task.go:88","content":"CallBack request successfully.","level":"info","reqId":"1960191682599202817","span":"6fe11f97dfa23e52","trace":"dfac27371ea9966e8da25340b5924dc7"}

Environments (please complete the following information):

  • OS: Ubuntu
  • go-zero version:v1.7.3
  • goctl version:1.23.0

More description Add any other context about the problem here.

Cairry avatar Aug 29 '25 03:08 Cairry

Try the latest version please. It's fixed long time ago.

kevwan avatar Aug 31 '25 08:08 kevwan

Try the latest version please. It's fixed long time ago.

The latest version 1.9.0, the log format problem still exists

Cairry avatar Sep 04 '25 03:09 Cairry