package trace

import (
	"context"

	"github.com/hhs/camtalk/internal/logger"
	"go.uber.org/zap"
)

// FromContext 返回自动附加 trace_id/request_id/session_id 的 logger
func FromContext(ctx context.Context) *zap.SugaredLogger {
	log := logger.Log

	if traceID := GetTraceID(ctx); traceID != "" {
		log = log.With("trace_id", traceID)
	}
	if requestID := GetRequestID(ctx); requestID != "" {
		log = log.With("request_id", requestID)
	}
	if sessionID := GetSessionID(ctx); sessionID != "" {
		log = log.With("session_id", sessionID)
	}

	return log
}
