MCPcopy Create free account
hub / github.com/coder/envbuilder / sendLogsV1

Function sendLogsV1

log/coder.go:121–143  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

119// sendLogsV1 uses the PatchLogs endpoint to send logs.
120// This is deprecated, but required for backward compatibility with older versions of Coder.
121func 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.
146func sendLogsV2(ctx context.Context, dest agentsdk.LogDest, ls coderLogSender, l slog.Logger) (logger Func, closer func()) {

Callers 1

CoderFunction · 0.85

Calls 1

ErrorMethod · 0.80

Tested by

no test coverage detected