@@ -189,12 +189,13 @@ func TestOtelZapCore_Write(t *testing.T) {
189189 core := NewCore (logger ).(* OtelZapCore )
190190
191191 tests := []struct {
192- name string
193- entry zapcore.Entry
194- fields []zapcore.Field
195- coreFields []zapcore.Field
196- wantMessage string
197- wantAttrs map [string ]string
192+ name string
193+ entry zapcore.Entry
194+ fields []zapcore.Field
195+ coreFields []zapcore.Field
196+ wantMessage string
197+ wantAttrs map [string ]string
198+ mustLackAttrs []string
198199 }{
199200 {
200201 name : "basic info log" ,
@@ -206,8 +207,9 @@ func TestOtelZapCore_Write(t *testing.T) {
206207 fields : []zapcore.Field {
207208 {Key : "foo" , Type : zapcore .StringType , String : "bar" },
208209 },
209- wantMessage : "hello world" ,
210- wantAttrs : map [string ]string {"foo" : "bar" },
210+ wantMessage : "hello world" ,
211+ wantAttrs : map [string ]string {"foo" : "bar" },
212+ mustLackAttrs : []string {"logger" },
211213 },
212214 {
213215 name : "error log with stack and caller" ,
@@ -227,6 +229,7 @@ func TestOtelZapCore_Write(t *testing.T) {
227229 "caller" : "file.go:42" ,
228230 "exception.stacktrace" : "stacktrace" ,
229231 },
232+ mustLackAttrs : []string {"logger" },
230233 },
231234 {
232235 name : "core fields and span context" ,
@@ -252,6 +255,18 @@ func TestOtelZapCore_Write(t *testing.T) {
252255 "span_id" : "0405060000000000" ,
253256 "trace_flags" : "01" ,
254257 },
258+ mustLackAttrs : []string {"logger" },
259+ },
260+ {
261+ name : "logger name is emitted" ,
262+ entry : zapcore.Entry {
263+ Message : "named" ,
264+ Level : zapcore .InfoLevel ,
265+ Time : time .Now (),
266+ LoggerName : "svc.sub" ,
267+ },
268+ wantMessage : "named" ,
269+ wantAttrs : map [string ]string {"logger" : "svc.sub" },
255270 },
256271 }
257272
@@ -292,6 +307,9 @@ func TestOtelZapCore_Write(t *testing.T) {
292307 assert .Contains (t , got , k , "expected key %q" , k )
293308 assert .Equal (t , v , got [k ], "mismatch for key %q" , k )
294309 }
310+ for _ , k := range tt .mustLackAttrs {
311+ assert .NotContains (t , got , k , "unexpected attribute %q" , k )
312+ }
295313 })
296314 }
297315}
0 commit comments