Dispatch generates the audit event from entry and the given options and publishes it. Best-effort: failures are logged and reported to Sentry, never returned, so they can't fail or slow down the caller. A disabled dispatcher is a no-op.
(entry LogEntry, opts ...GeneratorOption)
| 62 | // returned, so they can't fail or slow down the caller. A disabled dispatcher |
| 63 | // is a no-op. |
| 64 | func (d *Dispatcher) Dispatch(entry LogEntry, opts ...GeneratorOption) { |
| 65 | if !d.Enabled() { |
| 66 | return |
| 67 | } |
| 68 | |
| 69 | payload, err := GenerateAuditEvent(entry, opts...) |
| 70 | if err != nil { |
| 71 | d.log.Errorw("msg", "failed to generate audit event", "error", err) |
| 72 | sentry.CaptureException(fmt.Errorf("failed to generate audit event: %w", err)) |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | if err := d.publisher.Publish(payload); err != nil { |
| 77 | d.log.Errorw("msg", "failed to publish audit event", "error", err) |
| 78 | sentry.CaptureException(fmt.Errorf("failed to publish audit event: %w", err)) |
| 79 | } |
| 80 | } |