fix(recorder): forward per-service recorder metadata to plugin recorders (#412)
User-configured metadata on recorder objects (recorders[].metadata in YAML) was silently discarded — MetadataRecordOption existed but was never called anywhere in the codebase, causing plugin (HTTP/gRPC) recorders to always receive null metadata. Fix: wrap recorders that carry config metadata in MetadataRecorder, which auto-appends the metadata to every Record() call. This covers all paths (handler, router, sniffer, service) with zero call-site changes.
This commit is contained in:
@@ -10,6 +10,23 @@ import (
|
||||
xctx "github.com/go-gost/x/ctx"
|
||||
)
|
||||
|
||||
// MetadataRecorder wraps a Recorder and automatically appends metadata
|
||||
// to every Record call.
|
||||
type MetadataRecorder struct {
|
||||
recorder.Recorder
|
||||
Metadata any
|
||||
}
|
||||
|
||||
func (r *MetadataRecorder) Record(ctx context.Context, b []byte, opts ...recorder.RecordOption) error {
|
||||
if r.Recorder == nil {
|
||||
return nil
|
||||
}
|
||||
if r.Metadata == nil {
|
||||
return r.Recorder.Record(ctx, b, opts...)
|
||||
}
|
||||
return r.Recorder.Record(ctx, b, append(opts, recorder.MetadataRecordOption(r.Metadata))...)
|
||||
}
|
||||
|
||||
const (
|
||||
RecorderServiceHandler = "recorder.service.handler"
|
||||
RecorderServiceHandlerSerial = "recorder.service.handler.serial"
|
||||
|
||||
Reference in New Issue
Block a user