@@ -136,6 +136,60 @@ func TestReqToLog(t *testing.T) {
136136 require .Equal (t , 2 , scopeLogsScope .Attributes ().Len ()) // expect no additional attributes even though headers are set
137137 },
138138 },
139+ {
140+ desc : "ConvertHeadersToAttributes enabled but no headers included" ,
141+ headers : http.Header {},
142+ config : & Config {
143+ Path : defaultPath ,
144+ HealthPath : defaultHealthPath ,
145+ ReadTimeout : defaultReadTimeout ,
146+ WriteTimeout : defaultWriteTimeout ,
147+ RequiredHeader : RequiredHeader {Key : "X-Required-Header" , Value : "password" },
148+ ConvertHeadersToAttributes : true ,
149+ },
150+ sc : func () * bufio.Scanner {
151+ reader := io .NopCloser (bytes .NewReader ([]byte ("this is a: log" )))
152+ return bufio .NewScanner (reader )
153+ }(),
154+ tt : func (t * testing.T , reqLog plog.Logs , reqLen int , _ receiver.Settings ) {
155+ require .Equal (t , 1 , reqLen )
156+
157+ attributes := reqLog .ResourceLogs ().At (0 ).Resource ().Attributes ()
158+ require .Equal (t , 0 , attributes .Len ())
159+
160+ scopeLogsScope := reqLog .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).Scope ()
161+ require .Equal (t , 2 , scopeLogsScope .Attributes ().Len ()) // expect no additional attributes even though headers are set
162+ },
163+ },
164+ {
165+ desc : "ConvertHeadersToAttributes enabled but only a required header included" ,
166+ headers : http.Header {
167+ textproto .CanonicalMIMEHeaderKey ("X-Required-Header" ): []string {"password" },
168+ },
169+ config : & Config {
170+ Path : defaultPath ,
171+ HealthPath : defaultHealthPath ,
172+ ReadTimeout : defaultReadTimeout ,
173+ WriteTimeout : defaultWriteTimeout ,
174+ RequiredHeader : RequiredHeader {Key : "X-Required-Header" , Value : "password" },
175+ ConvertHeadersToAttributes : true ,
176+ },
177+ sc : func () * bufio.Scanner {
178+ reader := io .NopCloser (bytes .NewReader ([]byte ("this is a: log" )))
179+ return bufio .NewScanner (reader )
180+ }(),
181+ tt : func (t * testing.T , reqLog plog.Logs , reqLen int , _ receiver.Settings ) {
182+ require .Equal (t , 1 , reqLen )
183+
184+ attributes := reqLog .ResourceLogs ().At (0 ).Resource ().Attributes ()
185+ require .Equal (t , 0 , attributes .Len ())
186+
187+ scopeLogsScope := reqLog .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).Scope ()
188+ require .Equal (t , 2 , scopeLogsScope .Attributes ().Len ()) // expect no additional attributes even though headers are set
189+ _ , exists := scopeLogsScope .Attributes ().Get ("header.x_required_header" )
190+ require .False (t , exists )
191+ },
192+ },
139193 {
140194 desc : "Headers added if ConvertHeadersToAttributes enabled" ,
141195 headers : http.Header {
@@ -217,3 +271,11 @@ func TestReqToLog(t *testing.T) {
217271 })
218272 }
219273}
274+
275+ func TestHeaderAttributeKey (t * testing.T ) {
276+ // Test mix of header values to ensure consistent output
277+ require .Equal (t , "header.foo" , headerAttributeKey ("foo" ))
278+ require .Equal (t , "header.1" , headerAttributeKey ("1" ))
279+ require .Equal (t , "header.content_type" , headerAttributeKey ("Content-type" ))
280+ require .Equal (t , "header.unexpected_camel_case_header" , headerAttributeKey ("UnExPectEd-CaMeL-CaSe-HeAdEr" ))
281+ }
0 commit comments