|
|
@ -9,6 +9,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"git.blauwelle.com/go/crate/log/logsdk"
|
|
|
|
"git.blauwelle.com/go/crate/log/logsdk"
|
|
|
|
"git.blauwelle.com/go/crate/log/logsdk/logjson"
|
|
|
|
"git.blauwelle.com/go/crate/log/logsdk/logjson"
|
|
|
|
|
|
|
|
"go.opentelemetry.io/otel"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
|
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
|
|
|
@ -20,6 +21,7 @@ func New(opts ...Option) *Processor {
|
|
|
|
cfg := newConfig(opts...)
|
|
|
|
cfg := newConfig(opts...)
|
|
|
|
return &Processor{
|
|
|
|
return &Processor{
|
|
|
|
bufferPool: cfg.bytesBufferPool,
|
|
|
|
bufferPool: cfg.bytesBufferPool,
|
|
|
|
|
|
|
|
defaultSpan: cfg.defaultSpan,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -28,10 +30,17 @@ var _ logsdk.EntryProcessor = &Processor{}
|
|
|
|
// Processor 用于把日志和 opentelemetry 对接
|
|
|
|
// Processor 用于把日志和 opentelemetry 对接
|
|
|
|
type Processor struct {
|
|
|
|
type Processor struct {
|
|
|
|
bufferPool logjson.BytesBufferPool
|
|
|
|
bufferPool logjson.BytesBufferPool
|
|
|
|
|
|
|
|
defaultSpan bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (processor *Processor) Process(ctx context.Context, entry logsdk.ReadonlyEntry) {
|
|
|
|
func (processor *Processor) Process(ctx context.Context, entry logsdk.ReadonlyEntry) {
|
|
|
|
span := trace.SpanFromContext(ctx)
|
|
|
|
span := trace.SpanFromContext(ctx)
|
|
|
|
|
|
|
|
if !span.IsRecording() {
|
|
|
|
|
|
|
|
if processor.defaultSpan {
|
|
|
|
|
|
|
|
ctx, span = otel.Tracer("git.blauwelle.com/go/crate/logotel").Start(ctx, "default") //nolint:ineffassign,staticcheck,wastedassign
|
|
|
|
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if !span.IsRecording() {
|
|
|
|
if !span.IsRecording() {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|