For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/logs/log_configuration/processors/arithmetic_processor.md. A documentation index is available at /llms.txt.

Arithmetic Processor

Overview

Use the arithmetic processor to add a new attribute (without spaces or special characters in the new attribute name) to a log with the result of the provided formula. This remaps different time attributes with different units into a single attribute, or computes operations on attributes within the same log.

An arithmetic processor formula can use parentheses and basic arithmetic operators: -, +, *, /.

By default, a calculation is skipped if an attribute is missing. Select Replace missing attribute by 0 to automatically populate missing attribute values with 0 to ensure that the calculation is done.

Notes:

  • An attribute may be listed as missing if it is not found in the log attributes, or if it cannot be converted to a number.
  • When using the operator -, add spaces around it because attribute names like start-time may contain dashes. For example, the following formula must include spaces around the - operator: (end-time - start-time) / 1000.
  • If the target attribute already exists, it is overwritten by the result of the formula.
  • Results are rounded up to the 9th decimal. For example, if the result of the formula is 0.1234567891, the actual value stored for the attribute is 0.123456789.
  • If you need to scale a unit of measure, use the scale filter.

Use cases

The arithmetic processor is used to calculate values using log attributes. The most common use case is converting duration attributes to different timeframes, such as with Azure logs, where Datadog automatically converts the duration from nanoseconds to milliseconds.

Before and after state of logs

Before:

{
  "operation": "db.query",
  "duration_ns": 25000000,
  "message": "Database query completed"
}

Arithmetic Processor

Create an Arithmetic Processor to convert duration_ns into milliseconds.

After processing:

{
  "operation": "db.query",
  "duration_ns": 25000000,
  "duration_ms": 25,
  "message": "Database query completed"
}

The Arithmetic Processor adds a duration_ms attribute based on the calculation.

API

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

{
  "type": "arithmetic-processor",
  "name": "<PROCESSOR_NAME>",
  "is_enabled": true,
  "expression": "<ARITHMETIC_OPERATION>",
  "target": "<TARGET_ATTRIBUTE>",
  "is_replace_missing": false
}
ParameterTypeRequiredDescription
typeStringYesType of the processor.
nameStringNoName of the processor.
is_enabledBooleanNoIf the processor is enabled or not. Default: false.
expressionStringYesArithmetic operation between one or more log attributes.
targetStringYesName of the attribute that contains the result of the arithmetic operation.
is_replace_missingBooleanNoIf true, it replaces all missing attributes of expression by 0, false skip the operation if an attribute is missing. Default: false.

Further reading

Additional helpful documentation, links, and articles: