config.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package logtail
  4. import (
  5. "io"
  6. "net/http"
  7. "time"
  8. "tailscale.com/tstime"
  9. "tailscale.com/types/logid"
  10. "tailscale.com/util/eventbus"
  11. )
  12. // DefaultHost is the default host name to upload logs to when
  13. // Config.BaseURL isn't provided.
  14. const DefaultHost = "log.tailscale.com"
  15. const defaultFlushDelay = 2 * time.Second
  16. const (
  17. // CollectionNode is the name of a logtail Config.Collection
  18. // for tailscaled (or equivalent: IPNExtension, Android app).
  19. CollectionNode = "tailnode.log.tailscale.io"
  20. )
  21. type Config struct {
  22. Collection string // collection name, a domain name
  23. PrivateID logid.PrivateID // private ID for the primary log stream
  24. CopyPrivateID logid.PrivateID // private ID for a log stream that is a superset of this log stream
  25. BaseURL string // if empty defaults to "https://log.tailscale.com"
  26. HTTPC *http.Client // if empty defaults to http.DefaultClient
  27. SkipClientTime bool // if true, client_time is not written to logs
  28. LowMemory bool // if true, logtail minimizes memory use
  29. Clock tstime.Clock // if set, Clock.Now substitutes uses of time.Now
  30. Stderr io.Writer // if set, logs are sent here instead of os.Stderr
  31. Bus *eventbus.Bus // if set, uses the eventbus for awaitInternetUp instead of callback
  32. StderrLevel int // max verbosity level to write to stderr; 0 means the non-verbose messages only
  33. Buffer Buffer // temp storage, if nil a MemoryBuffer
  34. CompressLogs bool // whether to compress the log uploads
  35. MaxUploadSize int // maximum upload size; 0 means using the default
  36. // MetricsDelta, if non-nil, is a func that returns an encoding
  37. // delta in clientmetrics to upload alongside existing logs.
  38. // It can return either an empty string (for nothing) or a string
  39. // that's safe to embed in a JSON string literal without further escaping.
  40. MetricsDelta func() string
  41. // FlushDelayFn, if non-nil is a func that returns how long to wait to
  42. // accumulate logs before uploading them. 0 or negative means to upload
  43. // immediately.
  44. //
  45. // If nil, a default value is used. (currently 2 seconds)
  46. FlushDelayFn func() time.Duration
  47. // IncludeProcID, if true, results in an ephemeral process identifier being
  48. // included in logs. The ID is random and not guaranteed to be globally
  49. // unique, but it can be used to distinguish between different instances
  50. // running with same PrivateID.
  51. IncludeProcID bool
  52. // IncludeProcSequence, if true, results in an ephemeral sequence number
  53. // being included in the logs. The sequence number is incremented for each
  54. // log message sent, but is not persisted across process restarts.
  55. IncludeProcSequence bool
  56. }