Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve key quantization and add command length #19

Open
wants to merge 1 commit into
base: deployed-in-platform
Choose a base branch
from
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
3 changes: 3 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,9 @@ module Ext
SPAN_COMMAND = 'memcached.command'
SPAN_TYPE_COMMAND = 'memcached'
TAG_COMMAND = 'memcached.command'
# BEGIN BRAZE MODIFICATION
TAG_LENGTH = 'memcached.length'
# END BRAZE MODIFICATION
TAG_COMPONENT = 'dalli'
TAG_OPERATION_COMMAND = 'command'
TAG_SYSTEM = 'memcached'
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/tracing/contrib/dalli/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def request(op, *args)
cmd = Quantize.format_command(op, args)
span.set_tag(Ext::TAG_COMMAND, cmd)
end
# BEGIN BRAZE MODIFICATION
span.set_tag(Ext::TAG_LENGTH, Core::Utils.utf8_encode([op, *args].join(' ').strip, binary: true).length)

Choose a reason for hiding this comment

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

the Quantize.format_command(op, args) above
already ran Core::Utils.utf8_encode(command, binary: true, placeholder: placeholder)

I think it would be better to only run that once, the cost of this observability is pretty high already for the use of dalli, which gets used all the time.

Also, should this tag only be added when datadog_configuration[:command_enabled] is true?

# END BRAZE MODIFICATION

Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
super
Expand Down
22 changes: 21 additions & 1 deletion lib/datadog/tracing/contrib/dalli/quantize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,32 @@ module Contrib
module Dalli
# Quantize contains dalli-specic quantization tools.
module Quantize
# BEGIN BRAZE MODIFICATION
GUID_ID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i
BSON_ID_REGEX = /[0-9a-f]{24}/i
XXHASH_REGEX = /[0-9a-f]{16}/
INTEGER_ID_REGEX = /\d+/
# 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
end
# END BRAZE MODIFICATION

command = Core::Utils.utf8_encode(command, binary: true, placeholder: placeholder)
# BEGIN BRAZE MODIFICATION
command = command.gsub(GUID_ID_REGEX, "GUID")
command = command.gsub(BSON_ID_REGEX, "BSON")
command = command.gsub(XXHASH_REGEX, "XXHASH")
command = command.gsub(INTEGER_ID_REGEX, "INTEGER")
Comment on lines +30 to +33

Choose a reason for hiding this comment

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

this could have negative perf impact, also

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this will be too bad, but I'm curious if there are some relatively quick ideas we could do to make this faster. I could smush all of these together into a single expression and just replace it with ID

# END BRAZE MODIFICATION
Core::Utils.truncate(command, Ext::QUANTIZE_MAX_CMD_LENGTH)
rescue => e
Datadog.logger.debug("Error sanitizing Dalli operation: #{e}")
Expand Down
Loading