diff --git a/core_test.go b/core_test.go index 59e7f3d..85d8c3a 100644 --- a/core_test.go +++ b/core_test.go @@ -27,7 +27,7 @@ func TestWithLabels(t *testing.T) { want := []zap.Field{ zap.String("hello", "world"), - zap.Object("labels", labels), + zap.Object("logging.googleapis.com/labels", labels), } assert.Equal(t, want, (&core{}).withLabels(fields)) @@ -177,7 +177,7 @@ func TestWrite(t *testing.T) { err := core.Write(zapcore.Entry{}, fields) require.NoError(t, err) - assert.NotNil(t, logs.All()[0].ContextMap()["labels"]) + assert.NotNil(t, logs.All()[0].ContextMap()[labelsKey]) } func TestWriteConcurrent(t *testing.T) { @@ -212,7 +212,7 @@ func TestWriteConcurrent(t *testing.T) { } wg.Wait() - assert.NotNil(t, logs.All()[0].ContextMap()["labels"]) + assert.NotNil(t, logs.All()[0].ContextMap()[labelsKey]) } func TestWithAndWrite(t *testing.T) { @@ -227,7 +227,7 @@ func TestWithAndWrite(t *testing.T) { err := core.Write(zapcore.Entry{}, []zapcore.Field{Label("two", "worlds")}) require.NoError(t, err) - labels := logs.All()[0].ContextMap()["labels"].(map[string]interface{}) + labels := logs.All()[0].ContextMap()[labelsKey].(map[string]interface{}) assert.Equal(t, "world", labels["one"]) assert.Equal(t, "worlds", labels["two"]) @@ -245,7 +245,7 @@ func TestWithAndWrite_MultipleEntries(t *testing.T) { err := core.Write(zapcore.Entry{}, []zapcore.Field{Label("two", "worlds")}) require.NoError(t, err) - labels := logs.All()[0].ContextMap()["labels"].(map[string]interface{}) + labels := logs.All()[0].ContextMap()[labelsKey].(map[string]interface{}) require.Len(t, labels, 2) assert.Equal(t, "world", labels["one"]) @@ -254,7 +254,7 @@ func TestWithAndWrite_MultipleEntries(t *testing.T) { err = core.Write(zapcore.Entry{}, []zapcore.Field{Label("three", "worlds")}) require.NoError(t, err) - labels = logs.All()[1].ContextMap()["labels"].(map[string]interface{}) + labels = logs.All()[1].ContextMap()[labelsKey].(map[string]interface{}) require.Len(t, labels, 2) assert.Equal(t, "world", labels["one"]) diff --git a/label.go b/label.go index 07656c9..7238642 100644 --- a/label.go +++ b/label.go @@ -8,6 +8,8 @@ import ( "go.uber.org/zap/zapcore" ) +const labelsKey = "logging.googleapis.com/labels" + // Label adds an optional label to the payload. // // Labels are a set of user-defined (key, value) data that provides additional @@ -40,7 +42,7 @@ func isLabelField(field zap.Field) bool { } func labelsField(l *labels) zap.Field { - return zap.Object("labels", l) + return zap.Object(labelsKey, l) } type labels struct { diff --git a/label_test.go b/label_test.go index b2b5f10..8c30c7e 100644 --- a/label_test.go +++ b/label_test.go @@ -26,5 +26,5 @@ func TestLabels(t *testing.T) { labels := newLabels() labels.store = map[string]string{"hello": "world", "hi": "universe"} - assert.Equal(t, zap.Object("labels", labels), field) + assert.Equal(t, zap.Object(labelsKey, labels), field) }