diff --git a/client.go b/client.go index 14cfa5f..cdba6a7 100644 --- a/client.go +++ b/client.go @@ -51,6 +51,7 @@ type Config struct { UserAgent string Timeout time.Duration TenantID string + Actor string Cardinalities map[string]int Labels LabelPool ProtobufRatio float64 @@ -204,6 +205,9 @@ func (c *Client) sendQuery(q *Query) (httpext.Response, error) { r.Header.Set("User-Agent", c.cfg.UserAgent) r.Header.Set("Accept", ContentTypeJSON) + if c.cfg.Actor != "" { + r.Header.Set("X-Grafana-User", c.cfg.Actor) + } if c.cfg.TenantID != "" { r.Header.Set("X-Scope-OrgID", c.cfg.TenantID) } else { diff --git a/loki.go b/loki.go index 356ff01..11202b4 100644 --- a/loki.go +++ b/loki.go @@ -146,8 +146,9 @@ func (r *Loki) config(c goja.ConstructorCall) *goja.Object { } r.logger.Debug(fmt.Sprintf( - "url=%s timeout=%s protobufRatio=%f cardinalities=%v randSeed=%d", + "url=%s timeout=%s protobufRatio=%f cardinalities=%v randSeed=%d, userAgent=%s, timeout=%s, tenant=%s, actor=%s", &config.URL, config.Timeout, config.ProtobufRatio, config.Cardinalities, config.RandSeed, + config.UserAgent, config.Timeout, config.TenantID, config.Actor, )) if config.TenantID == "" { @@ -225,6 +226,10 @@ func (r *Loki) parseConfigObject(c *goja.Object, config *Config) error { config.TenantID = v.String() } + if v := c.Get("actor"); !isNully(v) { + config.Actor = v.String() + } + if v := c.Get("cardinalities"); !isNully(v) { if err := rt.ExportTo(v, &config.Cardinalities); err != nil { return fmt.Errorf("cardinatities should be a map of string to integers: %w", err)