move ReceivedAt assignment to more commonly called location
@@ -114,10 +114,6 @@ func (w *amqpLogWriter) Close() error {
Number: w.logPartNumber,
Final: true,
}
- if w.logPartNumber == 0 && w.ctx.Value("processedAt") != nil {
- processedAt := w.ctx.Value("processedAt").(time.Time)
- part.ReceivedAt = &processedAt
- }
w.logPartNumber++
err := w.publishLogPart(part)
@@ -227,6 +223,11 @@ func (w *amqpLogWriter) flush() {
func (w *amqpLogWriter) publishLogPart(part amqpLogPart) error {
part.UUID, _ = context.UUIDFromContext(w.ctx)
+ if w.logPartNumber == 1 && w.ctx.Value("processedAt") != nil {
+ processedAt := w.ctx.Value("processedAt").(time.Time)
+ part.ReceivedAt = &processedAt
+ }
+
partBody, err := json.Marshal(part)
if err != nil {
return err
