Package codes.grow.packages.datadoglogs
Class DatadogLogMapping
java.lang.Object
codes.grow.packages.datadoglogs.DatadogLogMapping
LogRecord to Datadog JSON and back (API.md sections 5.2 and 6.1; DECISIONS 6, 7, 9).
Intake entries carry message, timestamp (epoch milliseconds), status,
service, hostname, ddsource, ddtags, dd.trace_id /
dd.span_id (decimal of the lower 64 bits), otel.trace_id / otel.span_id (lower
hex, lossless), then the record attributes. User attributes named like a reserved key are sent as
attr.<name>.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne serialized entry. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum entries in one intake request (Datadog limit).static final intMaximum serialized size of one log entry in bytes (1 MB).static final intMaximum uncompressed intake payload in bytes, brackets and commas included (5 MB).Top-level keys the SDK writes itself.static final StringPrefix given to user attributes whose name is reserved (DECISIONS 7).static final StringAttribute set totrueon an entry whose message the SDK truncated. -
Method Summary
Modifier and TypeMethodDescriptionbuildDdtags(String env, String version, List<String> tags) Builds theddtagsvalue:env:,version:, then the tags; comma-joined, de-duplicated, whitespace and commas inside a tag replaced by_.datadogIdToHex(Object id, int length) Converts a Datadog id (decimal string of up to 64 bits, or already lower hex) to lower hex padded tolengthcharacters.static StringdatadogStatus(LogRecord record) Datadogstatusof a record: its severity text lower-cased, else the canonical severity name.static LogRecordeventToLogRecord(DatadogLogEvent event) Normalizes a search event into aLogRecord:statusto severity,service/host/env:/version:to the resource, custom attributes plusdatadog.log_idanddatadog.tags; trace ids fromotel.trace_id/otel.span_id, else fromdd.trace_id/dd.span_id(decimal or hex; only the lower 64 bits survive the decimal form).static Optional<DatadogLogEvent> parseLogEvent(com.fasterxml.jackson.databind.JsonNode item) Parses onedata[]item of a search response.serializeEntry(Map<String, Object> entry, int maxBytes) Serializes an entry so it is at mostmaxBytes(DECISIONS 7).static SeverityseverityFromStatus(String status) Severity of a Datadogstatus(unknown values giveSeverity.INFO).spanIdToDatadog(String spanId) Datadog span-id form: the decimal string of a 16-hex OpenTelemetry span id.toDatadogEntry(LogRecord record, DatadogLogsConfig config) Converts a record into a Datadog intake entry.traceIdToDatadog(String traceId) Datadog trace-id form (DECISIONS 6): the decimal string of the lower 64 bits of an OpenTelemetry trace id (up to 32 hex characters).static intutf8Length(String text) UTF-8 byte length of a string.
-
Field Details
-
MAX_ENTRIES_PER_REQUEST
public static final int MAX_ENTRIES_PER_REQUESTMaximum entries in one intake request (Datadog limit).- See Also:
-
MAX_PAYLOAD_BYTES
public static final int MAX_PAYLOAD_BYTESMaximum uncompressed intake payload in bytes, brackets and commas included (5 MB).- See Also:
-
MAX_LOG_BYTES
public static final int MAX_LOG_BYTESMaximum serialized size of one log entry in bytes (1 MB).- See Also:
-
TRUNCATED_ATTRIBUTE
Attribute set totrueon an entry whose message the SDK truncated.- See Also:
-
RESERVED_PREFIX
Prefix given to user attributes whose name is reserved (DECISIONS 7).- See Also:
-
RESERVED_KEYS
Top-level keys the SDK writes itself.
-
-
Method Details
-
traceIdToDatadog
Datadog trace-id form (DECISIONS 6): the decimal string of the lower 64 bits of an OpenTelemetry trace id (up to 32 hex characters).traceIdToDatadog("4bf92f3577b34da6a3ce929d0e0e4736") // "11803532876627986230"- Parameters:
traceId- hex trace id, may be null- Returns:
- the decimal form, or empty for invalid input
-
spanIdToDatadog
Datadog span-id form: the decimal string of a 16-hex OpenTelemetry span id.- Parameters:
spanId- hex span id, may be null- Returns:
- the decimal form, or empty for invalid input
-
datadogIdToHex
Converts a Datadog id (decimal string of up to 64 bits, or already lower hex) to lower hex padded tolengthcharacters.- Parameters:
id- the id: a string or an integral number, may be nulllength- 16 (span) or 32 (trace)- Returns:
- the hex id, or empty for invalid or zero ids
-
datadogStatus
Datadogstatusof a record: its severity text lower-cased, else the canonical severity name.- Parameters:
record- the record- Returns:
- the status, for example
warn
-
severityFromStatus
Severity of a Datadogstatus(unknown values giveSeverity.INFO).- Parameters:
status- status word, may be null- Returns:
- the severity
-
buildDdtags
Builds theddtagsvalue:env:,version:, then the tags; comma-joined, de-duplicated, whitespace and commas inside a tag replaced by_.- Parameters:
env- environment, may be nullversion- version, may be nulltags- extra tags- Returns:
- the value, or empty when there is no tag
-
toDatadogEntry
Converts a record into a Datadog intake entry. Record resource values win over the config defaults (service,hostname,env,version); other resource keys are not sent.- Parameters:
record- the recordconfig- defaults for service, hostname, env, version, tags and source- Returns:
- the entry, in wire order
-
serializeEntry
public static Optional<DatadogLogMapping.SerializedEntry> serializeEntry(Map<String, Object> entry, int maxBytes) Serializes an entry so it is at mostmaxBytes(DECISIONS 7). An oversized entry gets itsmessagecut at a character boundary andgrow.truncated: true.- Parameters:
entry- the entry fromtoDatadogEntry(codes.grow.packages.datadoglogs.logging.LogRecord, codes.grow.packages.datadoglogs.DatadogLogsConfig)maxBytes- maximum UTF-8 size- Returns:
- the serialized entry, or empty when even an empty message does not fit
-
utf8Length
UTF-8 byte length of a string.- Parameters:
text- text- Returns:
- the length in bytes
-
parseLogEvent
Parses onedata[]item of a search response.- Parameters:
item- the JSON item- Returns:
- the event, or empty when the item is not an object
-
eventToLogRecord
Normalizes a search event into aLogRecord:statusto severity,service/host/env:/version:to the resource, custom attributes plusdatadog.log_idanddatadog.tags; trace ids fromotel.trace_id/otel.span_id, else fromdd.trace_id/dd.span_id(decimal or hex; only the lower 64 bits survive the decimal form).- Parameters:
event- the event- Returns:
- the record
-