gh-datadog-event
v2.3.0
Published
A TypeScript library for working with Datadog events
Maintainers
Readme
gh-datadog-event
A lightweight TypeScript library for sending events to Datadog's Events API. Can be used both as an npm package in your code and as a GitHub Action in your workflows.
Overview
gh-datadog-event makes it easy to send custom events to your Datadog dashboard from any Node.js application or GitHub workflow. Use it to track deployments, mark significant application events, or create custom alerts.
Usage as an npm package
Installation
npm install gh-datadog-eventExample Usage
import { CreateEvent } from 'gh-datadog-event';
// Set your Datadog API and APP keys as environment variables
// process.env.DATADOG_API_KEY = 'your-api-key';
// process.env.DATADOG_APP_KEY = 'your-app-key';
async function sendDeploymentEvent() {
const results = await CreateEvent({
requests: [
{
title: 'Deployment Completed',
text: 'Service successfully deployed to production',
alertType: 'info',
priority: 'normal',
tags: ['environment:production', 'service:api', 'team:backend']
}
]
});
console.log(`Event created: ${results[0].eventUrl}`);
}
sendDeploymentEvent();Usage as a GitHub Action
You can also use this package as a GitHub Action in your workflows to send events to Datadog.
Example Workflow
name: Deploy and Notify
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# Your deployment steps here...
- name: Notify Datadog of deployment
uses: sds9-org/datadog-event@v2
with:
title: 'Deployment to Production'
text: 'New version deployed to production environment'
alertType: 'info'
priority: 'normal'
tags: 'environment:production,service:api'
includeGitHubContext: 'true'
env:
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
DATADOG_APP_KEY: ${{ secrets.DATADOG_APP_KEY }}Action Inputs
| Input | Description | Required | Default |
| ----- | ----------- | -------- | ------- |
| title | Title of the event | Yes | |
| text | Text description of the event | Yes | |
| alertType | Type of alert (e.g., "error", "warning", "info") | No | info |
| priority | Priority of the event (e.g., "normal", "low") | No | normal |
| host | Host associated with the event | No | |
| tags | Comma-separated list of tags | No | |
| aggregationKey | Key to group events together | No | |
| sourceTypeName | Source type name for the event | No | |
| includeGitHubContext | Whether to include GitHub context in tags | No | true |
Action Outputs
| Output | Description |
| ------ | ----------- |
| eventUrl | URL of the created event in Datadog |
| eventId | ID of the created event |
API Reference
CreateEvent
Main function for creating events in Datadog.
Parameters
See the API documentation for detailed information about the function parameters and return types.
Getting Your Datadog API Keys
To use this library, you need a Datadog API key:
- Log in to your Datadog account
- Navigate to Organization Settings > API Keys
- Create a new API key or use an existing one
For additional functionality, you may also want an Application key:
- Navigate to Organization Settings > Application Keys
- Create a new Application key
Datadog Event Documentation
For more information about Datadog events, see the official Datadog Events documentation.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch for your feature or bugfix
- Write your code and tests
- Submit a pull request with a detailed description of your changes
