From c321363d2ccc10d7dee7d5d0dcccab93589a5cb5 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Wed, 5 Oct 2022 12:25:10 -0700 Subject: [PATCH] logtail: support a copy ID (#5851) The copy ID operates similar to a CC in email where a message is sent to both the primary ID and also the copy ID. A given log message is uploaded once, but the log server records it twice for each ID. Signed-off-by: Joe Tsai --- logtail/logtail.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/logtail/logtail.go b/logtail/logtail.go index 8d68546e4..7ffdeac67 100644 --- a/logtail/logtail.go +++ b/logtail/logtail.go @@ -44,7 +44,8 @@ type Encoder interface { type Config struct { Collection string // collection name, a domain name - PrivateID PrivateID // machine-specific private identifier + PrivateID PrivateID // private ID for the primary log stream + CopyPrivateID PrivateID // private ID for a log stream that is a superset of this log stream BaseURL string // if empty defaults to "https://log.tailscale.io" HTTPC *http.Client // if empty defaults to http.DefaultClient SkipClientTime bool // if true, client_time is not written to logs @@ -112,12 +113,16 @@ func NewLogger(cfg Config, logf tslogger.Logf) *Logger { stdLogf := func(f string, a ...any) { fmt.Fprintf(cfg.Stderr, strings.TrimSuffix(f, "\n")+"\n", a...) } + var urlSuffix string + if !cfg.CopyPrivateID.IsZero() { + urlSuffix = "?copyId=" + cfg.CopyPrivateID.String() + } l := &Logger{ privateID: cfg.PrivateID, stderr: cfg.Stderr, stderrLevel: int64(cfg.StderrLevel), httpc: cfg.HTTPC, - url: cfg.BaseURL + "/c/" + cfg.Collection + "/" + cfg.PrivateID.String(), + url: cfg.BaseURL + "/c/" + cfg.Collection + "/" + cfg.PrivateID.String() + urlSuffix, lowMem: cfg.LowMemory, buffer: cfg.Buffer, skipClientTime: cfg.SkipClientTime,