Суть его в том что добавляет автоматизацию, что бы не использовать
slog.WithContex. Может автоматом добавлять атрибуты к логам - traceID, request-id, user-id и прочее. Выглядит примерно так:
func helloHandler(w http.ResponseWriter, r *http.Request) {
ctx, span := tracer.Start(r.Context(), "helloHandler")
defer span.End()
slogctx.Info(ctx, "starting long calculation...")
/*
{
"time": "2023-11-17T03:11:20.584592-07:00",
"level": "INFO",
"msg": "starting long calculation...",
"TraceID": "15715df45965b4a2db6dc103a76e52ae",
"SpanID": "76d364cdd598c895"
}
*/
time.Sleep(5 * time.Second)
slogctx.Error(ctx, "something failed...")
/*
{
"time": "2023-11-17T03:11:25.586464-07:00",
"level": "ERROR",
"msg": "something failed...",
"TraceID": "15715df45965b4a2db6dc103a76e52ae",
"SpanID": "76d364cdd598c895"
}
*/
w.WriteHeader(http.StatusInternalServerError)
// The OTEL exporter will soon after output the trace, which will include this and much more:
/*
{
"Name": "helloHandler",
"SpanContext": {
"TraceID": "15715df45965b4a2db6dc103a76e52ae",
"SpanID": "76d364cdd598c895"
},
"Status": {
"Code": "Error",
"Description": "something failed..."
}
}
*/
}