Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

feat(vector): Add Datadog sink #8

Merged
merged 5 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ const main = async () => {
// inject the Datadog sink into Vector config; and so on.
const ENABLE_STDOUT = process.env.ENABLE_STDOUT === 'true' ? true : false
const LOGTAIL_TOKEN = process.env.LOGTAIL_TOKEN ?? null
const vectorCfg = configureVector(ENABLE_STDOUT, LOGTAIL_TOKEN)
const DATADOG_TOKEN = process.env.DATADOG_TOKEN ?? null
const DATADOG_SITE = process.env.DATADOG_SITE ?? null
const vectorCfg = configureVector(
ENABLE_STDOUT,
LOGTAIL_TOKEN,
DATADOG_TOKEN,
DATADOG_SITE,
)

// Start Vector first. We want to crash early; there's no point in making
// network requests to Railway API if Vector can't start.
Expand Down
16 changes: 12 additions & 4 deletions src/vector/configure.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { VectorConfiguration } from '@/types'
import { LOGTAIL, STDOUT } from './sinks'
import { DATADOG, LOGTAIL, STDOUT } from './sinks'
import { STDIN } from './sources'

const configure = (
enableStdout: boolean,
logtail: string | null,
logtailToken: string | null,
datadogToken: string | null,
datadogSite: string | null,
): VectorConfiguration => {
const enabled = []
let cfg = ''
Expand All @@ -15,9 +17,15 @@ const configure = (
enabled.push('stdout')
cfg += STDOUT
}
if (logtail !== null) {
if (logtailToken !== null) {
enabled.push('logtail')
cfg += LOGTAIL(logtail)
cfg += LOGTAIL(logtailToken)
}
if (datadogToken !== null) {
enabled.push('datadog')
cfg += datadogSite
? DATADOG(datadogToken, datadogSite)
: DATADOG(datadogToken)
}

return {
Expand Down
10 changes: 9 additions & 1 deletion src/vector/sinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ encoding.codec = "json"
auth.strategy = "bearer"
auth.token = "${token}"`

export { STDOUT, LOGTAIL }
const DATADOG = (token: string, site?: string) => `
[sinks.datadog]
type = "datadog_logs"
inputs = [ "*" ]
compression = "gzip"
site = "${site ?? "datadoghq.com"}"
default_api_key = "${token}"`

export { DATADOG, STDOUT, LOGTAIL }