From 633d2094118c19ce31c4f015a44624f575ca6852 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 27 Jul 2022 19:17:41 -0500 Subject: [PATCH] Spans for iqs --- lib/patches_for_sentry.rb | 26 ++++++++++++++++++++++++++ sgx_jmp.rb | 19 ++++++++++--------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/patches_for_sentry.rb b/lib/patches_for_sentry.rb index 7f91dd1..3d75b7d 100644 --- a/lib/patches_for_sentry.rb +++ b/lib/patches_for_sentry.rb @@ -52,3 +52,29 @@ module SentryEMHiredis end EM::Hiredis::Client.include SentryEMHiredis + +module SentryIQManager + def record_span(description) + transaction = Sentry.get_current_scope.get_transaction + return yield unless transaction&.sampled + + span = transaction.start_child( + op: "xmpp.iq", + description: description + ) + + yield.then { span.finish } + end + + def stanza_description(stanza) + node = stanza.respond_to?(:node) ? stanza.node : stanza.child&.name + "iq #{stanza.type} #{stanza.to} #{node}" + end + + def write(stanza) + # Outgoing IQ already logged by blather + record_span(stanza_description(stanza)) { super } + end +end + +IQ_MANAGER.extend SentryIQManager diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 841b99a..2c6dcd9 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -56,6 +56,16 @@ singleton_class.class_eval do Blather::DSL.append_features(self) end +require_relative "lib/session_manager" + +IQ_MANAGER = SessionManager.new(self, :id) +COMMAND_MANAGER = SessionManager.new( + self, + :sessionid, + timeout: 60 * 60, + error_if: ->(s) { s.cancel? } +) + require_relative "lib/polyfill" require_relative "lib/alt_top_up_form" require_relative "lib/admin_command" @@ -89,7 +99,6 @@ require_relative "lib/postgres" require_relative "lib/registration" require_relative "lib/transaction" require_relative "lib/tel_selections" -require_relative "lib/session_manager" require_relative "lib/snikket" require_relative "lib/statsd" require_relative "web" @@ -357,14 +366,6 @@ message do |m| } end -IQ_MANAGER = SessionManager.new(self, :id) -COMMAND_MANAGER = SessionManager.new( - self, - :sessionid, - timeout: 60 * 60, - error_if: ->(s) { s.cancel? } -) - disco_info to: Blather::JID.new(CONFIG[:component][:jid]) do |iq| reply = iq.reply reply.identities = [{ -- 2.38.5