func getTraceStatus(ctx context.Context) bool {
	value := ctx.Value(traceStatusKey{})
	if v, ok := value.(bool); ok {
		return v
	}
	return false
}
getTraceStatus return status of tracing or false if not set
package logging
import (
	"context"
	"encoding/hex"
	"fmt"
	log "github.com/sirupsen/logrus"
	"go.opencensus.io/trace"
	"regexp"
)
var reZero = regexp.MustCompile(`^0+$`)
type LogSpanExporter struct{}
func (e *LogSpanExporter) ExportSpan(vd *trace.SpanData) {
	var (
		traceID      = hex.EncodeToString(vd.SpanContext.TraceID[:])
		spanID       = hex.EncodeToString(vd.SpanContext.SpanID[:])
		parentSpanID = hex.EncodeToString(vd.ParentSpanID[:])
	)
	logger := log.WithFields(log.Fields{"trace_id": traceID, "span_id": spanID, "span_name": vd.Name, "duration": nanosecondsToMillisecondsString(int64(vd.EndTime.Sub(vd.StartTime)))})
	if vd.Status.Code != trace.StatusCodeOK {
		logger = logger.WithFields(log.Fields{"status_message": vd.Status.Message, "status_code": vd.Status.Code})
	}
	if !reZero.MatchString(parentSpanID) {
		logger = logger.WithField("parent_span_id", parentSpanID)
	}
	linkFields := log.Fields{}
	for i, link := range vd.Links {
		linkFields[fmt.Sprintf("link_trace_id_%v", i)] = link.TraceID
		linkFields[fmt.Sprintf("link_span_id_%v", i)] = link.SpanID
		linkFields[fmt.Sprintf("link_span_type_%v", i)] = link.Type
	}
	logger = logger.WithFields(linkFields)
	if len(vd.Attributes) > 0 {
		attributes := log.Fields{}
		for k, v := range vd.Attributes {
			attributes[k] = v
		}
		logger = logger.WithFields(attributes)
	}
	if len(vd.Annotations) > 0 {
		for _, item := range vd.Annotations {
			annotations := log.Fields{FieldKeyUnixTime: TimeToString(item.Time)}
			for k, v := range item.Attributes {
				annotations[k] = v
			}
			logger.WithFields(annotations).Infoln(item.Message)
		}
	}
	logger.Infoln(vd.Name)
}
func LoggerWithTrace(context context.Context, logger *log.Entry) *log.Entry {
	span := trace.FromContext(context)
	spanContext := span.SpanContext()
	if getTraceStatus(context) {
		return logger.WithFields(log.Fields{"span_id": spanContext.SpanID, "trace_id": spanContext.TraceID})
	}
	return logger
}
func NewLoggerWithTrace(context context.Context) *log.Entry {
	return LoggerWithTrace(context, GetLoggerFromContext(context))
}
type traceStatusKey struct{}
func SetTraceStatus(ctx context.Context, isOn bool) context.Context {
	return context.WithValue(ctx, traceStatusKey{}, isOn)
}