Instrumentation

Hertz supports flexible enabling of basic and fine-grained Instrumentation

Stats Level

OptionDescriptionEnable Strategy
LevelDisableddisable all eventsWhen tracer is not available, enable by default.
LevelBaseenable basic events
LevelDetailedenable basic events and detailed eventsWhen tracer is available, enable by default.

Stats Level Control

package main

import (
    "github.com/cloudwego/hertz/pkg/app/server"
    "github.com/cloudwego/hertz/pkg/common/tracer/stats"
)

func main() {
    h := server.Default(server.WithTraceLevel(stats.LevelBase))
    h.Spin()
}

Stats introduction

Basic Stats Event

  1. HTTPStart : Http start
  2. HTTPFinish : Http finish

Detailed Stats Event

  1. ReadHeaderStart:read header start
  2. ReadHeaderFinish:read header finish
  3. ReadBodyStart:read body start
  4. ReadBodyFinish:read body finish
  5. ServerHandleStart:server handler start
  6. ServerHandleFinish:server handler finish
  7. WriteStart:write response start
  8. WriteFinish:write response finish

If you do not want to record this information, you can either not register any tracer or set the tracking strategy to LevelDisabled, and the framework will not record this information.

Setting the level of the stats for a specific node in the tracing to LevelDisabled or not registering any tracer will result in the loss of spans/metrics for that specific node and and will interrupt the tracing.

Timeline

timeline


Last modified June 24, 2024 : fix: correct the file path (#1096) (b3fa1a4)