Documentation
¶
Overview ¶
Package datadog is Datadog Error Tracking as a source of production alerts. An Error Tracking monitor, grouped by issue and service, notifies a webhook of Datadog's Webhooks integration; the webhook's payload is a template of Datadog's variables that carries the event's and the monitor's IDs and the tags of the group that fired, and no text. kōjō reads the issue and a sample of its stack trace through Datadog's API with an API key and an application key that can read Error Tracking.
Datadog does not sign webhooks. The webhook sends a secret in a custom header (from a custom variable hidden from view), and a delivery without it is refused.
Datadog's documentation: https://docs.datadoghq.com/integrations/webhooks/, https://docs.datadoghq.com/monitors/types/error_tracking/ and the v2 API's "Get the details of an error tracking issue". What the adapter assumes beyond them is in assumptions.go.
Index ¶
- Constants
- type Option
- type Source
- func (s *Source) Admit(r *http.Request) error
- func (s *Source) Check(ctx context.Context) error
- func (s *Source) Enrich(ctx context.Context, a *alerts.Alert) error
- func (s *Source) IDsOnly()
- func (s *Source) MaxBody() int64
- func (s *Source) Name() string
- func (s *Source) ParseWebhook(r *http.Request, body []byte) (*alerts.Delivery, error)
Constants ¶
const HeaderSecret = "X-Kojo-Webhook-Secret"
HeaderSecret carries the webhook's secret: the webhook's custom headers are {"X-Kojo-Webhook-Secret": "$KOJO_WEBHOOK_SECRET"}, a custom variable hidden from view.
const Payload = `{"id":"$ID","event_type":"$EVENT_TYPE","alert_id":"$ALERT_ID","transition":"$ALERT_TRANSITION",` +
`"cycle_key":"$ALERT_CYCLE_KEY","scope":"$ALERT_SCOPE","org_id":"$ORG_ID","date":"$DATE"}`
Payload is the webhook's payload, as kōjō documents it and `kojo setup datadog` prints it: Datadog's variables and nothing else, so no text of the error or the monitor's message reaches kōjō through the webhook.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Source)
Option changes how New builds the source.
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client of API calls. New uses a copy that follows no redirect.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
Source is one Datadog organization.
func (*Source) Admit ¶
Admit implements alerts.Gate: the request carries the webhook's secret. The route calls it before it reads the body.
func (*Source) Check ¶
Check implements alerts.Source: the API key is valid ("Validate API key"), and the application key can read Error Tracking: a search for the issues of the last minute of a service that does not exist, which reads nothing and needs error_tracking_read.
func (*Source) Enrich ¶
Enrich implements alerts.Source: the issue's error type and message, its file and function, the version it was last seen in, its state, when it was first and last seen, and the stack trace of a sample. An issue of another service than the one the alert's scope named is ErrIgnored, so a monitor's scope cannot send one service's issue to another's repository.
func (*Source) IDsOnly ¶
func (s *Source) IDsOnly()
IDsOnly implements alerts.IDsOnly: the payload carries the monitor's and the issue's IDs and tags, no error, so an alert whose issue cannot be read starts nothing.
func (*Source) ParseWebhook ¶
ParseWebhook implements alerts.Source. It checks the secret again, as Admit did before the route read the body, then decodes the payload. Only an Error Tracking monitor's Triggered and Re-Triggered notifications are alerts; the issue, the service and the environment come from the tags of the group that fired ($ALERT_SCOPE).