datadog

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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 WithClock

func WithClock(now func() time.Time) Option

WithClock sets the clock the doctor's search window is read from.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client of API calls. New uses a copy that follows no redirect.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the logger.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source is one Datadog organization.

func New

func New(cfg config.Datadog, opts ...Option) (*Source, error)

New returns the Datadog source of a kojo.yaml section.

func (*Source) Admit

func (s *Source) Admit(r *http.Request) error

Admit implements alerts.Gate: the request carries the webhook's secret. The route calls it before it reads the body.

func (*Source) Check

func (s *Source) Check(ctx context.Context) error

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

func (s *Source) Enrich(ctx context.Context, a *alerts.Alert) error

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) MaxBody

func (s *Source) MaxBody() int64

MaxBody implements alerts.Gate.

func (*Source) Name

func (s *Source) Name() string

Name implements alerts.Source.

func (*Source) ParseWebhook

func (s *Source) ParseWebhook(r *http.Request, body []byte) (*alerts.Delivery, error)

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL