@@ -109,10 +109,25 @@ func (s *redaction) processResourceLog(ctx context.Context, rl plog.ResourceLogs
109
109
for k := 0 ; k < ils .LogRecords ().Len (); k ++ {
110
110
log := ils .LogRecords ().At (k )
111
111
s .processAttrs (ctx , log .Attributes ())
112
+ s .processLogBody (ctx , log .Body (), log .Attributes ())
112
113
}
113
114
}
114
115
}
115
116
117
+ func (s * redaction ) processLogBody (ctx context.Context , body pcommon.Value , attributes pcommon.Map ) {
118
+ if body .Type () == pcommon .ValueTypeMap {
119
+ s .processAttrs (ctx , body .Map ())
120
+ return
121
+ }
122
+
123
+ maskedBody , redactionCount := s .processString (body .Str ())
124
+ // If redaction happened, update the body and add to attributes for the summary
125
+ if redactionCount > 0 {
126
+ body .SetStr (maskedBody )
127
+ attributes .PutInt (bodyMaskedCount , int64 (redactionCount ))
128
+ }
129
+ }
130
+
116
131
func (s * redaction ) processResourceMetric (ctx context.Context , rm pmetric.ResourceMetrics ) {
117
132
rsAttrs := rm .Resource ().Attributes ()
118
133
@@ -238,6 +253,21 @@ func (s *redaction) addMetaAttrs(redactedAttrs []string, attributes pcommon.Map,
238
253
}
239
254
}
240
255
256
+ // processString applies regex-based redaction to a string and returns the modified string & count.
257
+ func (s * redaction ) processString (str string ) (string , int ) {
258
+ maskedStr := str
259
+ redactionCount := 0
260
+
261
+ // Apply redaction using regex patterns and count matches
262
+ for _ , compiledRE := range s .blockRegexList {
263
+ matches := compiledRE .FindAllString (str , - 1 )
264
+ redactionCount += len (matches )
265
+ maskedStr = compiledRE .ReplaceAllString (maskedStr , "****" )
266
+ }
267
+
268
+ return str , redactionCount
269
+ }
270
+
241
271
const (
242
272
debug = "debug"
243
273
info = "info"
@@ -246,6 +276,7 @@ const (
246
276
maskedValues = "redaction.masked.keys"
247
277
maskedValueCount = "redaction.masked.count"
248
278
ignoredKeyCount = "redaction.ignored.count"
279
+ bodyMaskedCount = "redaction.body.masked.count"
249
280
)
250
281
251
282
// makeAllowList sets up a lookup table of allowed span attribute keys
0 commit comments