Skip to content

Commit 93a6e5e

Browse files
committed
Emit MongoDB event body as a JSON string
The MongoDB integration was the only one to pass a structured Data object as an event body. The agent serializes that to JSON before storing it, so the output is unchanged.
1 parent 109c54a commit 93a6e5e

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: patch
3+
type: change
4+
---
5+
6+
Emit the MongoDB query event body as a JSON string instead of a structured data object. The recorded query body is unchanged.

lib/appsignal/integrations/mongo_ruby_driver.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "json"
4+
35
module Appsignal
46
class Hooks
57
# @!visibility private
@@ -46,11 +48,13 @@ def finish(result, event)
4648
store = transaction.store("mongo_driver")
4749
command = store.delete(event.request_id) || {}
4850

49-
# Finish the event in the extension.
51+
# Finish the event. The sanitized command is a (nested) Hash; emit it
52+
# as a JSON string. The agent serializes structured bodies to JSON
53+
# anyway, so this is equivalent output.
5054
transaction.finish_event(
5155
"query.mongodb",
5256
"#{event.command_name} | #{event.database_name} | #{result}",
53-
Appsignal::Utils::Data.generate(command),
57+
JSON.generate(command),
5458
Appsignal::EventFormatter::DEFAULT
5559
)
5660

spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@
9191
subscriber.finish("SUCCEEDED", event)
9292
end
9393

94-
it "should finish the transaction in the extension" do
94+
it "should finish the event with the command as a JSON string" do
9595
expect(transaction).to receive(:finish_event).with(
9696
"query.mongodb",
9797
"find | test | SUCCEEDED",
98-
Appsignal::Utils::Data.generate("foo" => "?"),
98+
"{\"foo\":\"?\"}",
9999
0
100100
)
101101

0 commit comments

Comments
 (0)