@@ -114,6 +114,32 @@ func TestBackgroundLog(t *testing.T) {
114114 })
115115}
116116
117+ func TestBackgroundLogWithFields (t * testing.T ) {
118+ app := integrationsupport .NewTestApp (integrationsupport .SampleEverythingReplyFn ,
119+ newrelic .ConfigAppLogDecoratingEnabled (true ),
120+ newrelic .ConfigAppLogForwardingEnabled (true ),
121+ )
122+ out := bytes .NewBuffer ([]byte {})
123+ log := newTextLogger (out , app .Application )
124+ message := "Hello World!"
125+ log .WithField ("test field" , []string {"a" , "b" }).Info (message )
126+ logcontext .ValidateDecoratedOutput (t , out , & logcontext.DecorationExpect {
127+ EntityGUID : integrationsupport .TestEntityGUID ,
128+ Hostname : host ,
129+ EntityName : integrationsupport .SampleAppName ,
130+ })
131+ app .ExpectLogEvents (t , []internal.WantLog {
132+ {
133+ Severity : logrus .InfoLevel .String (),
134+ Message : message ,
135+ Timestamp : internal .MatchAnyUnixMilli ,
136+ Attributes : map [string ]interface {}{
137+ "test field" : []string {"a" , "b" },
138+ },
139+ },
140+ })
141+ }
142+
117143func TestJSONBackgroundLog (t * testing.T ) {
118144 app := integrationsupport .NewTestApp (integrationsupport .SampleEverythingReplyFn ,
119145 newrelic .ConfigAppLogDecoratingEnabled (true ),
@@ -192,3 +218,39 @@ func TestLogInContext(t *testing.T) {
192218
193219 txn .End ()
194220}
221+
222+ func TestLogInContextWithFields (t * testing.T ) {
223+ app := integrationsupport .NewTestApp (integrationsupport .SampleEverythingReplyFn ,
224+ newrelic .ConfigAppLogDecoratingEnabled (true ),
225+ newrelic .ConfigAppLogForwardingEnabled (true ),
226+ )
227+ out := bytes .NewBuffer ([]byte {})
228+ log := newTextLogger (out , app .Application )
229+ txn := app .StartTransaction ("test txn" )
230+
231+ ctx := newrelic .NewContext (context .Background (), txn )
232+ message := "Hello World!"
233+ log .WithField ("hi" , 1 ).WithContext (ctx ).Info (message )
234+
235+ logcontext .ValidateDecoratedOutput (t , out , & logcontext.DecorationExpect {
236+ EntityGUID : integrationsupport .TestEntityGUID ,
237+ Hostname : host ,
238+ EntityName : integrationsupport .SampleAppName ,
239+ TraceID : txn .GetLinkingMetadata ().TraceID ,
240+ SpanID : txn .GetLinkingMetadata ().SpanID ,
241+ })
242+ txn .ExpectLogEvents (t , []internal.WantLog {
243+ {
244+ Severity : logrus .InfoLevel .String (),
245+ Message : message ,
246+ Timestamp : internal .MatchAnyUnixMilli ,
247+ SpanID : txn .GetLinkingMetadata ().SpanID ,
248+ TraceID : txn .GetLinkingMetadata ().TraceID ,
249+ Attributes : map [string ]interface {}{
250+ "hi" : 1 ,
251+ },
252+ },
253+ })
254+
255+ txn .End ()
256+ }
0 commit comments