sendLogsV1 uses the PatchLogs endpoint to send logs. This is deprecated, but required for backward compatibility with older versions of Coder.
(ctx context.Context, client *agentsdk.Client, l slog.Logger)
| 119 | // sendLogsV1 uses the PatchLogs endpoint to send logs. |
| 120 | // This is deprecated, but required for backward compatibility with older versions of Coder. |
| 121 | func sendLogsV1(ctx context.Context, client *agentsdk.Client, l slog.Logger) (logger Func, closer func()) { |
| 122 | // nolint: staticcheck // required for backwards compatibility |
| 123 | sendLog, flushAndClose := agentsdk.LogsSender(agentsdk.ExternalLogSourceID, client.PatchLogs, slog.Logger{}) |
| 124 | var mu sync.Mutex |
| 125 | return func(lvl Level, msg string, args ...any) { |
| 126 | log := agentsdk.Log{ |
| 127 | CreatedAt: time.Now(), |
| 128 | Output: fmt.Sprintf(msg, args...), |
| 129 | Level: codersdk.LogLevel(lvl), |
| 130 | } |
| 131 | mu.Lock() |
| 132 | defer mu.Unlock() |
| 133 | if err := sendLog(ctx, log); err != nil { |
| 134 | l.Warn(ctx, "failed to send logs to Coder", slog.Error(err)) |
| 135 | } |
| 136 | }, func() { |
| 137 | ctx, cancel := context.WithTimeout(ctx, logSendGracePeriod) |
| 138 | defer cancel() |
| 139 | if err := flushAndClose(ctx); err != nil { |
| 140 | l.Warn(ctx, "failed to flush logs", slog.Error(err)) |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // sendLogsV2 uses the v2 agent API to send logs. Only compatibile with coder versions >= 2.9. |
| 146 | func sendLogsV2(ctx context.Context, dest agentsdk.LogDest, ls coderLogSender, l slog.Logger) (logger Func, closer func()) { |