@@ -34,6 +34,8 @@ internal class LokiBatchFormatter : ILokiBatchFormatter
3434 private readonly IEnumerable < LokiLabel > _globalLabels ;
3535 private readonly IReservedPropertyRenamingStrategy _renamingStrategy ;
3636 private readonly IEnumerable < string > _propertiesAsLabels ;
37+
38+ private readonly bool _leavePropertiesIntact ;
3739 private readonly bool _useInternalTimestamp ;
3840
3941 /// <summary>
@@ -52,16 +54,21 @@ internal class LokiBatchFormatter : ILokiBatchFormatter
5254 /// <param name="useInternalTimestamp">
5355 /// Compute internal timestamp
5456 /// </param>
57+ /// <param name="leavePropertiesIntact">
58+ /// Leave the list of properties intact after extracting the labels specified in propertiesAsLabels.
59+ /// </param>
5560 public LokiBatchFormatter (
5661 IReservedPropertyRenamingStrategy renamingStrategy ,
5762 IEnumerable < LokiLabel > ? globalLabels = null ,
5863 IEnumerable < string > ? propertiesAsLabels = null ,
59- bool useInternalTimestamp = false )
64+ bool useInternalTimestamp = false ,
65+ bool leavePropertiesIntact = false )
6066 {
6167 _renamingStrategy = renamingStrategy ;
6268 _globalLabels = globalLabels ?? Enumerable . Empty < LokiLabel > ( ) ;
6369 _propertiesAsLabels = propertiesAsLabels ?? Enumerable . Empty < string > ( ) ;
6470 _useInternalTimestamp = useInternalTimestamp ;
71+ _leavePropertiesIntact = leavePropertiesIntact ;
6572 }
6673
6774 /// <summary>
@@ -214,6 +221,6 @@ private void GenerateEntry(
214221 }
215222
216223 return ( labels ,
217- lokiLogEvent . CopyWithProperties ( remainingProperties ) ) ;
224+ lokiLogEvent . CopyWithProperties ( _leavePropertiesIntact ? properties : remainingProperties ) ) ;
218225 }
219226}
0 commit comments