Module: Datadog::AppSec::CompressedJson

Defined in:
lib/datadog/appsec/compressed_json.rb

Overview

Converts derivative schema payloads into JSON and compresses them into a base64 encoded string if the payload is worth compressing.

See: github.com/DataDog/dd-trace-rb/pull/3177#issuecomment-1747221082

Constant Summary collapse

MIN_SIZE_FOR_COMPRESSION =
260

Class Method Summary collapse

Class Method Details

.dump(payload) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/datadog/appsec/compressed_json.rb', line 18

def self.dump(payload)
  value = JSON.dump(payload)
  return value if value.bytesize < MIN_SIZE_FOR_COMPRESSION

  compress_and_encode(value)
rescue ArgumentError, Encoding::UndefinedConversionError, JSON::JSONError => e
  AppSec.telemetry.report(e, description: 'AppSec: Failed to convert value into JSON')

  nil
end