Updated LDAP instrumentation
authorThierry Florac <thierry.florac@onf.fr>
Thu, 08 Nov 2018 15:28:16 +0100
changeset 8 1da0a6a483f9
parent 7 dc9e0c077015
child 9 98f4a311c1ea
Updated LDAP instrumentation
src/pyams_apm/include.py
src/pyams_apm/packages/ldap3.py
--- a/src/pyams_apm/include.py	Wed Sep 19 12:41:27 2018 +0200
+++ b/src/pyams_apm/include.py	Thu Nov 08 15:28:16 2018 +0100
@@ -12,22 +12,18 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
-# import interfaces
-from pyramid.interfaces import IApplicationCreated
-
-# import packages
 import elasticapm
 from elasticapm.instrumentation import register
 from pyramid.events import subscriber
+from pyramid.interfaces import IApplicationCreated
 
 
 @subscriber(IApplicationCreated)
 def handle_apm_application(event):
+    register.register('pyams_apm.packages.ldap3.LDAP3OpenInstrumentation')
     register.register('pyams_apm.packages.ldap3.LDAP3BindInstrumentation')
     register.register('pyams_apm.packages.ldap3.LDAP3SearchInstrumentation')
+    register.register('pyams_apm.packages.ldap3.LDAP3GetResponseInstrumentation')
     register.register('pyams_apm.packages.chameleon.ChameleonCookingInstrumentation')
     register.register('pyams_apm.packages.chameleon.ChameleonRenderingInstrumentation')
     elasticapm.instrument()
--- a/src/pyams_apm/packages/ldap3.py	Wed Sep 19 12:41:27 2018 +0200
+++ b/src/pyams_apm/packages/ldap3.py	Thu Nov 08 15:28:16 2018 +0100
@@ -16,6 +16,19 @@
 from elasticapm.traces import capture_span
 
 
+class LDAP3OpenInstrumentation(AbstractInstrumentedModule):
+    name = "ldap.open"
+
+    instrument_list = [
+        ("ldap3.strategy.base", "BaseStrategy.open"),
+        ("ldap3.strategy.reusable", "ReusableStrategy.open")
+    ]
+
+    def call(self, module, method, wrapped, instance, args, kwargs):
+        with capture_span('LDAP.OPEN', "db.ldap", leaf=True):
+            return wrapped(*args, **kwargs)
+
+
 class LDAP3BindInstrumentation(AbstractInstrumentedModule):
     name = "ldap.bind"
 
@@ -39,3 +52,16 @@
             }
         }, leaf=True):
             return wrapped(*args, **kwargs)
+
+
+class LDAP3GetResponseInstrumentation(AbstractInstrumentedModule):
+    name = "ldap.get_response"
+
+    instrument_list = [
+        ("ldap3.strategy.base", "BaseStrategy.get_response"),
+        ("ldap3.strategy.reusable", "ReusableStrategy.get_response")
+    ]
+
+    def call(self, module, method, wrapped, instance, args, kwargs):
+        with capture_span('LDAP.GET_RESPONSE', "db.ldap", leaf=True):
+            return wrapped(*args, **kwargs)