2022-03-30 12:32:41 +00:00
|
|
|
local key = GetConvar('datadog:key', '')
|
|
|
|
|
|
|
|
|
|
if key ~= '' then
|
|
|
|
|
local site = ('https://http-intake.logs.%s/api/v2/logs'):format(GetConvar('datadog:site', 'datadoghq.com'))
|
|
|
|
|
local resourceName = GetCurrentResourceName()
|
|
|
|
|
key = key:gsub("[\'\"]", '')
|
|
|
|
|
|
2022-09-14 01:20:50 +10:00
|
|
|
function lib.logger(source, event, message, ...)
|
2022-03-30 12:32:41 +00:00
|
|
|
local data = json.encode({
|
|
|
|
|
hostname = resourceName,
|
|
|
|
|
service = event,
|
|
|
|
|
message = message,
|
|
|
|
|
ddsource = tostring(source),
|
|
|
|
|
ddtags = string.strjoin(',', string.tostringall(...))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
PerformHttpRequest(site, function(status, _, _, response)
|
|
|
|
|
if status ~= 202 then
|
|
|
|
|
-- Thanks, I hate it
|
|
|
|
|
response = json.decode(response:sub(10)).errors[1]
|
|
|
|
|
print(('unable to submit logs to %s\n%s'):format(site, json.encode(response, {indent=true})))
|
|
|
|
|
end
|
|
|
|
|
end, 'POST', data, {
|
|
|
|
|
['Content-Type'] = 'application/json',
|
|
|
|
|
['DD-API-KEY'] = key
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-14 01:20:50 +10:00
|
|
|
return lib.logger or function() end
|