diff --git a/imports/logger/server.lua b/imports/logger/server.lua index b31f876..4537b0d 100644 --- a/imports/logger/server.lua +++ b/imports/logger/server.lua @@ -7,6 +7,12 @@ local function badResponse(endpoint, response) print(('unable to submit logs to %s\n%s'):format(endpoint, json.encode(response, { indent = true }))) end +local playerData = {} + +AddEventHandler('playerDropped', function() + playerData[source] = nil +end) + if service == 'datadog' then local key = GetConvar('datadog:key', ''):gsub("[\'\"]", '') @@ -18,6 +24,37 @@ if service == 'datadog' then ['DD-API-KEY'] = key, } + local function formatTags(source, tags) + if type(source) == 'number' and source > 0 then + local data = playerData[source] + + if not data then + local _data = { + ('username:%s'):format(GetPlayerName(source)) + } + + local num = 1 + + ---@cast source string + for i = 0, GetNumPlayerIdentifiers(source) - 1 do + local identifier = GetPlayerIdentifier(source, i) + + if not identifier:find('ip') then + num += 1 + _data[num] = identifier + end + end + + data = table.concat(_data, ',') + playerData[source] = data + end + + tags = tags and ('%s,%s'):format(tags, data) or data + end + + return tags + end + function lib.logger(source, event, message, ...) if not buffer then buffer = {} @@ -41,7 +78,7 @@ if service == 'datadog' then message = message, resource = cache.resource, ddsource = tostring(source), - ddtags = string.strjoin(',', string.tostringall(...)) + ddtags = formatTags(source, ... and string.strjoin(',', string.tostringall(...)) or nil), } end end