@@ -44,7 +44,9 @@ use crate::{
44
44
utils:: json:: { convert_array_to_object, flatten:: convert_to_array} ,
45
45
} ;
46
46
47
- const IGNORE_HEADERS : [ & str ; 1 ] = [ STREAM_NAME_HEADER_KEY ] ;
47
+ const IGNORE_HEADERS : [ & str ; 2 ] = [ STREAM_NAME_HEADER_KEY , LOG_SOURCE_KEY ] ;
48
+ const MAX_CUSTOM_FIELDS : usize = 10 ;
49
+ const MAX_FIELD_VALUE_LENGTH : usize = 100 ;
48
50
49
51
pub async fn flatten_and_push_logs (
50
52
json : Value ,
@@ -160,12 +162,31 @@ pub fn get_custom_fields_from_header(req: HttpRequest) -> HashMap<String, String
160
162
161
163
// Iterate through headers and add custom fields
162
164
for ( header_name, header_value) in req. headers ( ) . iter ( ) {
165
+ // Check if we've reached the maximum number of custom fields
166
+ if p_custom_fields. len ( ) >= MAX_CUSTOM_FIELDS {
167
+ warn ! (
168
+ "Maximum number of custom fields ({}) reached, ignoring remaining headers" ,
169
+ MAX_CUSTOM_FIELDS
170
+ ) ;
171
+ break ;
172
+ }
173
+
163
174
let header_name = header_name. as_str ( ) ;
164
175
if header_name. starts_with ( "x-p-" ) && !IGNORE_HEADERS . contains ( & header_name) {
165
176
if let Ok ( value) = header_value. to_str ( ) {
166
177
let key = header_name. trim_start_matches ( "x-p-" ) ;
167
178
if !key. is_empty ( ) {
168
- p_custom_fields. insert ( key. to_string ( ) , value. to_string ( ) ) ;
179
+ // Truncate value if it exceeds the maximum length
180
+ let truncated_value = if value. len ( ) > MAX_FIELD_VALUE_LENGTH {
181
+ warn ! (
182
+ "Header value for '{}' exceeds maximum length, truncating" ,
183
+ header_name
184
+ ) ;
185
+ & value[ ..MAX_FIELD_VALUE_LENGTH ]
186
+ } else {
187
+ value
188
+ } ;
189
+ p_custom_fields. insert ( key. to_string ( ) , truncated_value. to_string ( ) ) ;
169
190
} else {
170
191
warn ! (
171
192
"Ignoring header with empty key after prefix: {}" ,
0 commit comments