Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/datadog/tracing/contrib/dalli/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module Ext
SPAN_COMMAND = 'memcached.command'
SPAN_TYPE_COMMAND = 'memcached'
TAG_COMMAND = 'memcached.command'
# BEGIN BRAZE MODIFICATION
TAG_QUANTIZED_COMMAND = 'memcached.quantized_command'
TAG_LENGTH = 'memcached.length'
# END BRAZE MODIFICATION
TAG_COMPONENT = 'dalli'
TAG_OPERATION_COMMAND = 'command'
TAG_SYSTEM = 'memcached'
Expand Down
6 changes: 5 additions & 1 deletion lib/datadog/tracing/contrib/dalli/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ def request(op, *args)
span.set_tag(Contrib::Ext::DB::TAG_SYSTEM, Ext::TAG_SYSTEM)

if datadog_configuration[:command_enabled]
cmd = Quantize.format_command(op, args)
# BEGIN BRAZE MODIFICATION
cmd, q_cmd, length = Quantize.format_command(op, args)
span.set_tag(Ext::TAG_COMMAND, cmd)
span.set_tag(Ext::TAG_QUANTIZED_COMMAND, q_cmd)
span.set_tag(Ext::TAG_LENGTH, length)
# END BRAZE MODIFICATION
end

Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
Expand Down
24 changes: 22 additions & 2 deletions lib/datadog/tracing/contrib/dalli/quantize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@ module Contrib
module Dalli
# Quantize contains dalli-specic quantization tools.
module Quantize
# BEGIN BRAZE MODIFICATION
# Combined regex for quantizing IDs - order matters (most specific first)
# GUID > BSON (24 hex) > XXHASH (16 hex) > INTEGER (2+ digits)
QUANTIZE_ID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{24}|[0-9a-f]{16}|\d{2,}/
# END BRAZE MODIFICATION
module_function

def format_command(operation, args)
placeholder = "#{operation} BLOB (OMITTED)"
command = [operation, *args].join(' ').strip
# BEGIN BRAZE MODIFICATION
if operation == :send_multiget
command = [operation, *args].join(' ').strip
else
# all operations except multiget have the key as the first arg
command = [operation, args[0]].join(' ').strip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change for all operations outside of :send_multiget. Will this create problems?

end
# END BRAZE MODIFICATION

command = Core::Utils.utf8_encode(command, binary: true, placeholder: placeholder)
Core::Utils.truncate(command, Ext::QUANTIZE_MAX_CMD_LENGTH)
# BEGIN BRAZE MODIFICATION
quantized_command = command.gsub(QUANTIZE_ID_REGEX, "#")
[
Core::Utils.truncate(command, Ext::QUANTIZE_MAX_CMD_LENGTH),
Core::Utils.truncate(quantized_command, Ext::QUANTIZE_MAX_CMD_LENGTH),
command.length,
]
# END BRAZE MODIFICATION
rescue => e
Datadog.logger.debug("Error sanitizing Dalli operation: #{e}")
placeholder
Expand Down