diff --git a/lxd/loki/loki.go b/lxd/loki/loki.go index 44f5412803e4..acfcfb58317d 100644 --- a/lxd/loki/loki.go +++ b/lxd/loki/loki.go @@ -273,7 +273,8 @@ func (c *Client) HandleEvent(event api.Event) { if shared.StringInSlice(k, c.cfg.labels) { _, ok := entry.labels[k] if !ok { - entry.labels[k] = v + // Label names may not contain any hyphens. + entry.labels[strings.ReplaceAll(k, "-", "_")] = v delete(context, k) } } @@ -349,7 +350,7 @@ func buildNestedContext(prefix string, m map[string]any) map[string]string { for k, v := range m { t := reflect.TypeOf(v) - if t.Kind() == reflect.Map { + if t != nil && t.Kind() == reflect.Map { for k, v := range buildNestedContext(k, v.(map[string]any)) { if prefix == "" { labels[k] = v