forked from DataDog/datadog-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.ts
44 lines (37 loc) · 1.36 KB
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type {AxiosPromise, AxiosRequestConfig, AxiosResponse} from 'axios'
import {getGitMetadata} from '../../helpers/git/format-git-span-data'
import {getUserGitSpanTags} from '../../helpers/user-provided-git'
import {getRequestBuilder} from '../../helpers/utils'
import {Payload} from './interfaces'
// Dependency follows-redirects sets a default maxBodyLength of 10 MB https://github.com/follow-redirects/follow-redirects/blob/b774a77e582b97174813b3eaeb86931becba69db/index.js#L391
// We don't want any hard limit enforced by the CLI, the backend will enforce a max size by returning 413 errors.
const maxBodyLength = Infinity
export const reportCustomSpan = (request: (args: AxiosRequestConfig) => AxiosPromise<AxiosResponse>) => async (
customSpan: Payload,
provider: string
) => {
const gitSpanTags = await getGitMetadata()
const userGitSpanTags = getUserGitSpanTags()
return request({
data: {
...customSpan,
tags: {
...gitSpanTags,
...userGitSpanTags,
...customSpan.tags,
},
},
headers: {
'X-Datadog-CI-Custom-Event': provider,
},
maxBodyLength,
method: 'POST',
url: 'api/v2/webhook',
})
}
export const apiConstructor = (baseUrl: string, apiKey: string) => {
const requestIntake = getRequestBuilder({baseUrl, apiKey})
return {
reportCustomSpan: reportCustomSpan(requestIntake),
}
}