datadog

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceTypeListNotice      = "list-notice"
	ListNoticeIssueSearchFailed = "issue-search-failed"
)
View Source
const (
	IntegrationWebhookName = "superplane"
	WebhookSecretName      = "webhookToken"
	WebhookHeaderName      = "X-SuperPlane-Token"

	ErrorTrackingAlertEventType = "error_tracking_alert"
	AlertTransitionTriggered    = "Triggered"
	AlertTransitionRetriggered  = "Re-Triggered"
)
View Source
const ErrorTrackingAlertPayloadType = "datadog.errorTrackingAlert"
View Source
const ErrorTrackingForbiddenMessage = "Datadog refused the request. The application key needs error_tracking_read."

ErrorTrackingForbiddenMessage is the user-facing text for ErrErrorTrackingForbidden.

View Source
const (
	MonitorsWriteForbiddenMessage = "Datadog refused the request. The application key needs monitors_write."
)
View Source
const ReceiptField = "superplaneReceiptId"

ReceiptField is the canvas payload key for the stored receipt ID. Work order source payloads omit this key.

View Source
const (
	ResourceTypeEnvironment = "environment"
)
View Source
const ResourceTypeService = "service"

Variables

View Source
var ErrErrorTrackingForbidden = errors.New(
	"datadog refused the request: the application key needs error_tracking_read",
)

ErrErrorTrackingForbidden is returned when Datadog refuses an Error Tracking call, usually because a restricted application key lacks error_tracking_read.

Functions

func DescribeErrorTrackingIssue

func DescribeErrorTrackingIssue(issue ErrorTrackingIssue, alert AlertDetails) string

DescribeErrorTrackingIssue renders the issue and the alert as task markdown. Empty sections are omitted. The result stays within the work order limit.

func IssueHasWorkOrder

func IssueHasWorkOrder(tx *gorm.DB, factory *models.Factory, issueID string) (bool, error)

IssueHasWorkOrder reports whether this factory already has a work order for the Error Tracking issue. Matching covers every work-order state.

func IssueIDFromEventData

func IssueIDFromEventData(eventData any) (string, bool)

IssueIDFromEventData reads the Error Tracking issue id from a canvas root event envelope. Seeded issues carry the issue page in link. A monitor alert link does not.

func IssueIDFromURL

func IssueIDFromURL(rawURL string) (string, bool)

IssueIDFromURL reads the Error Tracking issue id from a Datadog issue page.

func ReceiptIDFromEventData

func ReceiptIDFromEventData(eventData any) (uuid.UUID, bool)

ReceiptIDFromEventData reads the SuperPlane webhook receipt ID stored on a datadog.errorTrackingAlert canvas event. Datadog does not send this field.

func ReleaseRetiredIntakeMonitor

func ReleaseRetiredIntakeMonitor(ctx core.TriggerContext) error

ReleaseRetiredIntakeMonitor deletes the monitor stored on an intake that was already removed. The intake is no longer in the active count.

func WebhookRequestAuthenticated

func WebhookRequestAuthenticated(integration core.IntegrationContext, request *http.Request) bool

WebhookRequestAuthenticated reports whether the request carries this integration's webhook token.

func WithWebhookReceipt

func WithWebhookReceipt(r *http.Request, state *WebhookReceiptState) *http.Request

Types

type APIError

type APIError struct {
	StatusCode int
	Body       string
}

APIError is a non-2xx response from Datadog.

func (*APIError) Error

func (e *APIError) Error() string

type AlertDetails

type AlertDetails struct {
	Title        string
	Body         string
	EventMessage string
	Link         string
	Tags         string
	AlertScope   string
	AlertQuery   string
	AggregKey    string
}

AlertDetails is the monitor text that arrived with an Error Tracking alert.

type Client

type Client struct {
	APIKey  string
	AppKey  string
	Site    string
	BaseURL string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpCtx core.HTTPContext, ctx core.IntegrationContext) (*Client, error)

func (*Client) CreateEvent

func (c *Client) CreateEvent(req CreateEventRequest) (*Event, error)

CreateEvent creates a new event in Datadog.

func (*Client) CreateMonitor

func (c *Client) CreateMonitor(monitor Monitor) (*Monitor, error)

func (*Client) DeleteMonitor

func (c *Client) DeleteMonitor(id int64) error

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(name string) error

func (*Client) GetErrorTrackingIssue

func (c *Client) GetErrorTrackingIssue(issueID string) (*ErrorTrackingIssue, error)

GetErrorTrackingIssue loads one Error Tracking issue by id.

func (*Client) GetMonitor

func (c *Client) GetMonitor(id int64) (*Monitor, error)

func (*Client) IssueURL

func (c *Client) IssueURL(issueID string) string

IssueURL is the Datadog app URL for this issue on the client's site.

func (*Client) ListEnvironments

func (c *Client) ListEnvironments(service string) ([]string, error)

ListEnvironments returns distinct env tag values seen on spans, then logs, for the last 30 days. service narrows the query when it is set.

func (*Client) ListServices

func (c *Client) ListServices() ([]string, error)

ListServices returns service names seen in spans or logs in the last 30 days, plus services on open Error Tracking issues. The three reads run together under one time limit. A refused or failed telemetry query is skipped. A refused issue search is skipped when another source succeeds. Any other issue search failure keeps telemetry names when one exists, so a temporary error does not hide those services. That result includes ListNoticeIssueSearchFailed so the missing names are not silent. The list fails when that search fails and no telemetry name is available.

func (*Client) LoadErrorTrackingIssue

func (c *Client) LoadErrorTrackingIssue(issueID string, warn func(string, ...any)) (*ErrorTrackingIssue, error)

LoadErrorTrackingIssue reads the issue, its recent impact, a sample error event, and logs that share the sample trace. Impact, sample, and log lookups are optional: a missing permission still returns the issue and reports the failure to warn, which can be nil.

func (*Client) LogsURL

func (c *Client) LogsURL(query string, from, to time.Time) string

LogsURL is the Datadog Logs explorer URL for a query and time window.

func (*Client) SearchErrorTrackingIssues

func (c *Client) SearchErrorTrackingIssues(query string, limit int) ([]ErrorTrackingIssue, error)

SearchErrorTrackingIssues searches open and acknowledged Error Tracking issues from about the last 30 days. Empty query means "*". Results are the newest created issues, first-seen time descending. Limit is capped at 100.

func (*Client) SearchMonitors

func (c *Client) SearchMonitors(query string) ([]Monitor, error)

func (*Client) SetRequestDeadline

func (c *Client) SetRequestDeadline(deadline time.Time)

SetRequestDeadline stops later Datadog calls at deadline. The zero time clears the limit.

func (*Client) TraceURL

func (c *Client) TraceURL(traceID string) string

TraceURL is the Datadog APM URL for a trace. A 128-bit hex ID uses the decimal lower 64 bits, which the Datadog app expects.

func (*Client) UpdateMonitor

func (c *Client) UpdateMonitor(id int64, monitor Monitor) (*Monitor, error)

func (*Client) UpsertWebhook

func (c *Client) UpsertWebhook(config WebhookConfiguration) error

func (*Client) ValidateCredentials

func (c *Client) ValidateCredentials() error

ValidateCredentials verifies that the API and Application keys are valid by calling the Datadog validate endpoint.

type Configuration

type Configuration struct {
	APIKey string `json:"apiKey"`
	AppKey string `json:"appKey"`
	Site   string `json:"site"`
}

type CreateEvent

type CreateEvent struct{}

func (*CreateEvent) Cancel

func (c *CreateEvent) Cancel(ctx core.ExecutionContext) error

func (*CreateEvent) Cleanup added in v0.7.0

func (c *CreateEvent) Cleanup(ctx core.SetupContext) error

func (*CreateEvent) Color

func (c *CreateEvent) Color() string

func (*CreateEvent) Configuration

func (c *CreateEvent) Configuration() []configuration.Field

func (*CreateEvent) Description

func (c *CreateEvent) Description() string

func (*CreateEvent) Documentation

func (c *CreateEvent) Documentation() string

func (*CreateEvent) ExampleOutput

func (c *CreateEvent) ExampleOutput() map[string]any

func (*CreateEvent) Execute

func (c *CreateEvent) Execute(ctx core.ExecutionContext) error

func (*CreateEvent) HandleHook added in v0.18.0

func (c *CreateEvent) HandleHook(ctx core.ActionHookContext) error

func (*CreateEvent) HandleWebhook

func (*CreateEvent) Hooks added in v0.18.0

func (c *CreateEvent) Hooks() []core.Hook

func (*CreateEvent) Icon

func (c *CreateEvent) Icon() string

func (*CreateEvent) Label

func (c *CreateEvent) Label() string

func (*CreateEvent) Name

func (c *CreateEvent) Name() string

func (*CreateEvent) OutputChannels

func (c *CreateEvent) OutputChannels(configuration any) []core.OutputChannel

func (*CreateEvent) Setup

func (c *CreateEvent) Setup(ctx core.SetupContext) error

type CreateEventRequest

type CreateEventRequest struct {
	Title     string   `json:"title"`
	Text      string   `json:"text"`
	AlertType string   `json:"alert_type,omitempty"`
	Priority  string   `json:"priority,omitempty"`
	Tags      []string `json:"tags,omitempty"`
}

CreateEventRequest represents the request payload for creating a Datadog event.

type CreateEventResponse

type CreateEventResponse struct {
	Event  Event  `json:"event"`
	Status string `json:"status"`
}

CreateEventResponse represents the response from creating an event.

type CreateEventSpec

type CreateEventSpec struct {
	Title     string `json:"title"`
	Text      string `json:"text"`
	AlertType string `json:"alertType"`
	Priority  string `json:"priority"`
	Tags      string `json:"tags"`
}

type Datadog

type Datadog struct{}

func (*Datadog) Actions

func (d *Datadog) Actions() []core.Action

func (*Datadog) Cleanup

func (d *Datadog) Cleanup(ctx core.IntegrationCleanupContext) error

func (*Datadog) Configuration

func (d *Datadog) Configuration() []configuration.Field

func (*Datadog) Description

func (d *Datadog) Description() string

func (*Datadog) HandleHook added in v0.18.0

func (d *Datadog) HandleHook(ctx core.IntegrationHookContext) error

func (*Datadog) HandleRequest

func (d *Datadog) HandleRequest(ctx core.HTTPRequestContext)

func (*Datadog) Hooks added in v0.18.0

func (d *Datadog) Hooks() []core.Hook

func (*Datadog) Icon

func (d *Datadog) Icon() string

func (*Datadog) Instructions

func (d *Datadog) Instructions() string

func (*Datadog) Label

func (d *Datadog) Label() string

func (*Datadog) ListResources

func (d *Datadog) ListResources(resourceType string, ctx core.ListResourcesContext) ([]core.IntegrationResource, error)

func (*Datadog) Name

func (d *Datadog) Name() string

func (*Datadog) Sync

func (d *Datadog) Sync(ctx core.SyncContext) error

func (*Datadog) Triggers

func (d *Datadog) Triggers() []core.Trigger

type ErrorSample

type ErrorSample struct {
	Source      string
	Timestamp   time.Time
	TraceID     string
	SpanID      string
	Env         string
	Version     string
	Host        string
	Resource    string
	HTTPMethod  string
	HTTPPath    string
	HTTPStatus  string
	UserID      string
	RequestID   string
	Fingerprint string
	Origin      string
	Route       string
	Action      string
	Breadcrumbs []string
	Stack       string
	TraceURL    string
	LogsURL     string
}

ErrorSample is one error event that Datadog grouped into the issue.

type ErrorTrackingAlertPayload

type ErrorTrackingAlertPayload struct {
	ID              string `json:"id" mapstructure:"id"`
	EventType       string `json:"event_type" mapstructure:"event_type"`
	Title           string `json:"title" mapstructure:"title"`
	Body            string `json:"body" mapstructure:"body"`
	EventMessage    string `json:"event_message,omitempty" mapstructure:"event_message"`
	AlertID         string `json:"alert_id" mapstructure:"alert_id"`
	AlertTransition string `json:"alert_transition" mapstructure:"alert_transition"`
	Tags            string `json:"tags" mapstructure:"tags"`
	AlertQuery      string `json:"alert_query,omitempty" mapstructure:"alert_query"`
	AlertScope      string `json:"alert_scope,omitempty" mapstructure:"alert_scope"`
	AggregKey       string `json:"aggreg_key,omitempty" mapstructure:"aggreg_key"`
	Link            string `json:"link" mapstructure:"link"`
	Description     string `json:"description,omitempty" mapstructure:"description"`
	Environment     string `json:"environment,omitempty" mapstructure:"environment"`
	ReceiptID       string `json:"superplaneReceiptId,omitempty" mapstructure:"superplaneReceiptId"`
}

func ErrorTrackingIssuePayload

func ErrorTrackingIssuePayload(issue ErrorTrackingIssue) ErrorTrackingAlertPayload

ErrorTrackingIssuePayload shapes one Error Tracking issue like the alert the intake trigger emits, so a seeded issue and a received alert take the same path through the graph.

type ErrorTrackingIssue

type ErrorTrackingIssue struct {
	ID               string
	ErrorType        string
	ErrorMessage     string
	Service          string
	FilePath         string
	FunctionName     string
	Platform         string
	State            string
	Languages        []string
	IsCrash          bool
	FirstSeen        time.Time
	LastSeen         time.Time
	FirstSeenVersion string
	LastSeenVersion  string
	Regression       *ErrorTrackingRegression
	Assignee         string
	Teams            []string
	CaseKey          string
	CaseTitle        string
	CaseURL          string
	TotalCount       int64
	ImpactedUsers    int64
	ImpactedSessions int64
	HasActivity      bool
	Stack            string
	Sample           *ErrorSample
	RelatedLogs      []LogLine
	URL              string
}

ErrorTrackingIssue is one Error Tracking issue from Datadog.

func NewestCreatedErrorTrackingIssues

func NewestCreatedErrorTrackingIssues(issues []ErrorTrackingIssue, limit int) []ErrorTrackingIssue

NewestCreatedErrorTrackingIssues returns up to limit issues, most recently created first. Issues with no first-seen time stay after issues that have one. Equal times keep their incoming order.

func NewestErrorTrackingIssues

func NewestErrorTrackingIssues(issues []ErrorTrackingIssue, limit int) []ErrorTrackingIssue

NewestErrorTrackingIssues returns up to limit issues, most recently seen first. Issues with no last-seen time stay after issues that have one. Equal times keep their incoming order.

func (ErrorTrackingIssue) IssueTitle

func (i ErrorTrackingIssue) IssueTitle() string

IssueTitle is the list and import title for an Error Tracking issue.

type ErrorTrackingRegression

type ErrorTrackingRegression struct {
	RegressedAt        time.Time
	RegressedAtVersion string
	ResolvedAt         time.Time
}

ErrorTrackingRegression is a resolved issue that started again.

type Event

type Event struct {
	ID           int64    `json:"id"`
	Title        string   `json:"title"`
	Text         string   `json:"text"`
	DateHappened int64    `json:"date_happened"`
	AlertType    string   `json:"alert_type"`
	Priority     string   `json:"priority"`
	Tags         []string `json:"tags"`
	URL          string   `json:"url"`
}

Event represents a Datadog event response.

type LogLine

type LogLine struct {
	Timestamp  time.Time
	Status     string
	Service    string
	Message    string
	HTTPMethod string
	HTTPPath   string
	HTTPStatus string
	ErrorKind  string
}

LogLine is one log that shares the error sample trace or span.

type Monitor

type Monitor struct {
	ID      int64          `json:"id,omitempty"`
	Name    string         `json:"name"`
	Type    string         `json:"type"`
	Query   string         `json:"query"`
	Message string         `json:"message"`
	Tags    []string       `json:"tags,omitempty"`
	Options MonitorOptions `json:"options"`
}

type MonitorOptions

type MonitorOptions struct {
	GroupbySimpleMonitor bool              `json:"groupby_simple_monitor"`
	NewHostDelay         int               `json:"new_host_delay"`
	Thresholds           MonitorThresholds `json:"thresholds"`
}

type MonitorThresholds

type MonitorThresholds struct {
	Critical float64 `json:"critical"`
}

type OnErrorTrackingAlert

type OnErrorTrackingAlert struct{}

func (*OnErrorTrackingAlert) Cleanup

func (*OnErrorTrackingAlert) Color

func (t *OnErrorTrackingAlert) Color() string

func (*OnErrorTrackingAlert) Configuration

func (t *OnErrorTrackingAlert) Configuration() []configuration.Field

func (*OnErrorTrackingAlert) Description

func (t *OnErrorTrackingAlert) Description() string

func (*OnErrorTrackingAlert) Documentation

func (t *OnErrorTrackingAlert) Documentation() string

func (*OnErrorTrackingAlert) ExampleData

func (t *OnErrorTrackingAlert) ExampleData() map[string]any

func (*OnErrorTrackingAlert) HandleHook

func (t *OnErrorTrackingAlert) HandleHook(ctx core.TriggerHookContext) (map[string]any, error)

func (*OnErrorTrackingAlert) HandleWebhook

func (*OnErrorTrackingAlert) Hooks

func (t *OnErrorTrackingAlert) Hooks() []core.Hook

func (*OnErrorTrackingAlert) Icon

func (t *OnErrorTrackingAlert) Icon() string

func (*OnErrorTrackingAlert) Label

func (t *OnErrorTrackingAlert) Label() string

func (*OnErrorTrackingAlert) Name

func (t *OnErrorTrackingAlert) Name() string

func (*OnErrorTrackingAlert) OnIntegrationMessage

func (t *OnErrorTrackingAlert) OnIntegrationMessage(ctx core.IntegrationMessageContext) error

func (*OnErrorTrackingAlert) Setup

type OnErrorTrackingAlertConfiguration

type OnErrorTrackingAlertConfiguration struct {
	Service          string   `json:"service" mapstructure:"service"`
	AlertTransitions []string `json:"alertTransitions" mapstructure:"alertTransitions"`
}

type OnErrorTrackingAlertMetadata

type OnErrorTrackingAlertMetadata struct {
	SubscriptionID string `json:"subscriptionId,omitempty" mapstructure:"subscriptionId"`
	MonitorID      string `json:"monitorId,omitempty" mapstructure:"monitorId"`
	MonitorService string `json:"monitorService,omitempty" mapstructure:"monitorService"`
}

type SubscriptionConfiguration

type SubscriptionConfiguration struct{}

type WebhookConfiguration

type WebhookConfiguration struct {
	Name          string `json:"name"`
	URL           string `json:"url"`
	EncodeAs      string `json:"encode_as"`
	Payload       string `json:"payload"`
	CustomHeaders string `json:"custom_headers"`
}

type WebhookReceiptState

type WebhookReceiptState struct {
	ID                uuid.UUID
	Outcome           string
	SubscriptionCount int
}

WebhookReceiptState carries one receipt from the public webhook handler into the integration request. The handler fills the outcome.

func WebhookReceiptFromRequest

func WebhookReceiptFromRequest(r *http.Request) *WebhookReceiptState

type WebhookSummary

type WebhookSummary struct {
	EventType       string
	AlertTransition string
	AlertID         string
	Service         string
	IssueID         string
}

WebhookSummary is the metadata stored for one Datadog call. It does not include the body or the webhook token.

func SummarizeWebhook

func SummarizeWebhook(body []byte) WebhookSummary

SummarizeWebhook reads event metadata from a Datadog webhook body.

Jump to

Keyboard shortcuts

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