Array Map Processor

Overview

Use the array map processor to apply a sequence of sub-processors to each element of a source array, producing a target array. Datadog supports the following sub-processors:

  • If source and target are the same attribute, the processor transforms elements in place.
  • If the target array already exists, the process overwrites attributes on existing elements.
  • Processing is limited to the first 50 elements of the source array.

Setup

Define the array map processor on the Pipelines page:

  1. Under Source array attribute, enter the path to the array attribute to iterate over.
  2. Select or clear the Preserve source array checkbox to keep or remove the original source array after processing.
  3. Under Target array attribute, enter the path to where to write the output array.
  4. Add one or more sub-processors to apply to each element.
Screenshot of the Array Map Processor configuration panel

Before and after state of logs

Before:

{
  "connections": [
    { "src_ip": "10.0.0.1", "dst_port": 443, "proto": "tcp" },
    { "src_ip": "10.0.0.2", "dst_port": 22,  "proto": "tcp" }
  ]
}

Array Map Processor

Create an Array Map Processor with source connections and target network.connections. Add an Attribute Remapper sub-processor mapping $sourceElem.src_ip to $targetElem.source, and a String Builder sub-processor with template %{$sourceElem.proto}/%{$sourceElem.dst_port} writing to $targetElem.service.

After:

{
  "connections": [...],
  "network": {
    "connections": [
      {"source": "10.0.0.1", "service": "tcp/443"},
      {"source": "10.0.0.2", "service": "tcp/22"}
    ]
  }
}

API

Use the Datadog Log Pipeline API endpoint with the following Array Map processor JSON payload:

{
  "type": "array-map-processor",
  "name": "<PROCESSOR_NAME>",
  "is_enabled": true,
  "source": "<SOURCE_ARRAY_ATTRIBUTE>",
  "target": "<TARGET_ARRAY_ATTRIBUTE>",
  "preserve_source": true,
  "processors": [
    {"type": "<SUB_PROCESSOR_TYPE>", ...},
    {"type": "<SUB_PROCESSOR_TYPE>", ...}
  ]
}
ParameterTypeRequiredDescription
typeStringYesType of the processor.
nameStringNoName of the processor.
is_enabledBooleanNoIf the processor is enabled or not. Default: false.
sourceStringYesName of the source array attribute.
targetStringYesName of the target array attribute. If equal to source, elements are transformed in place.
preserve_sourceBooleanNoIf the source array should be preserved after processing. Default: true.
processorsArray of ObjectsYesSub-processors applied to each element, in order. At least one is required.

Sub-processors

The following rules apply when defining sub-processors:

  • Inside each sub-processor, use:
    • $sourceElem to reference the current input element.
    • $targetElem to write to the current output element.
  • If an attribute does not start with $sourceElem, the processor reads from the parent log instead of the element itself.
  • $sourceElem.<field>/$targetElem.<field> refer to a nested attribute in the element object, while $sourceElem/$targetElem refer to a primitive element (for example, string, integer, double, Boolean).
  • All targets must start with $targetElem.

Attribute Remapper

Remaps an existing field to a field in the output element.

Screenshot of the Attribute Remapper sub-processor configuration

Example input:

{
  "items": ["10.0.0.1", "10.0.0.2"]
}

Configuration steps:

  • Source attributes: $sourceElem
  • Target attribute: $targetElem.ip
  • Preserve source: enabled

Result:

{
  "items": [...],
  "out": [
    {"ip": "10.0.0.1"},
    {"ip": "10.0.0.2"}
  ]
}
{
  "type": "attribute-remapper",
  "name": "Map primitive IP to object field",
  "sources": ["$sourceElem"],
  "target": "$targetElem.ip",
  "target_format": "auto",
  "preserve_source": true,
  "override_on_conflict": false
}
ParameterTypeRequiredDescription
typeStringYesType of the sub-processor.
nameStringNoName of the sub-processor.
sourcesArray of stringsYesArray of source attributes.
targetStringYesTarget attribute.
target_formatStringNoDefines if the attribute value should be cast to another type. Possible values: auto, string, double or integer. Default: auto. When set to auto, no cast is applied.
preserve_sourceBooleanNoIf the remapped source element should be preserved after processing. Default: false.
override_on_conflictBooleanNoIf the target element is already set, whether it should be overridden. Default: false.

String Builder Processor

Builds a new field in the output element from a template.

Screenshot of the String Builder sub-processor configuration

Example input:

{
  "region": "us-east-1",
  "items": [
    {"name": "db-1"},
    {"name": "db-2"}
  ]
}

Configuration steps:

  • Target attribute: $targetElem.fqdn
  • Template: %{$sourceElem.name}.%{region}
  • Replace missing: disabled

Result:

{
  "region": "us-east-1",
  "items": [...],
  "out": [
    {"fqdn": "db-1.us-east-1"},
    {"fqdn": "db-2.us-east-1"}
  ]
}
{
  "type": "string-builder-processor",
  "name": "Build FQDN from element and parent attribute",
  "template": "%{$sourceElem.name}.%{region}",
  "target": "$targetElem.fqdn",
  "is_replace_missing": false
}
ParameterTypeRequiredDescription
typeStringYesType of the sub-processor.
nameStringNoName of the sub-processor.
templateStringYesA formula with one or more attributes and raw text.
targetStringYesThe name of the attribute that contains the result of the template.
is_replace_missingBooleanNoIf true, replaces all missing attributes of template with an empty string. If false, skips the operation for missing attributes. Default: false.

Arithmetic Processor

Computes a numeric expression using element or log attributes and writes the result to the output element.

Screenshot of the Arithmetic Processor sub-processor configuration

Example input:

{
  "items": [
    {"bytes": 1024},
    {"bytes": 2048}
  ]
}

Configuration steps:

  • Target attribute: $targetElem.kb
  • Formula: $sourceElem.bytes / 1024
  • Replace missing value: disabled

Result:

{
  "items": [...],
  "out": [
    {"kb": 1},
    {"kb": 2}
  ]
}
{
  "type": "arithmetic-processor",
  "name": "Convert bytes to KB",
  "expression": "$sourceElem.bytes / 1024",
  "target": "$targetElem.kb",
  "is_replace_missing": false
}
ParameterTypeRequiredDescription
typeStringYesType of the sub-processor.
nameStringNoName of the sub-processor.
expressionStringYesArithmetic operation between one or more log attributes.
targetStringYesName of the attribute that contains the result of the arithmetic operation.
is_replace_missingBooleanNoIf true, replaces all missing attributes of expression with 0. If false, skips the operation if an attribute is missing. Default: false.

Category Processor

Assigns a category to each output element based on a filter query matching element attributes.

Screenshot of the Category Processor sub-processor configuration

Example input:

{
  "items": [
    {"status": "critical"},
    {"status": "warning"}
  ]
}

Configuration steps:

  • Target attribute: $targetElem.severity
  • Categories:
    • All events that match @$sourceElem.status:critical are mapped to value high
    • All events that match @$sourceElem.status:warning are mapped to value medium

Result:

{
  "items": [...],
  "out": [
    {"severity": "high"},
    {"severity": "medium"}
  ]
}
{
  "type": "category-processor",
  "name": "Map status to severity",
  "target": "$targetElem.severity",
  "categories": [
    {"filter": {"query": "@$sourceElem.status:critical"}, "name": "high"},
    {"filter": {"query": "@$sourceElem.status:warning"},  "name": "medium"}
  ]
}
ParameterTypeRequiredDescription
typeStringYesMust be category-processor.
nameStringNoName of the sub-processor.
categoriesArray of ObjectYesArray of filters to match to a log, and their corresponding custom name values to assign to the log.
targetStringYesName of the target attribute whose value is defined by the matching category.

Further reading

Additional helpful documentation, links, and articles: