src/pyams_apm/packages/chameleon.py
changeset 0 1cc388b5cf69
child 2 e78763bdfb3f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_apm/packages/chameleon.py	Tue Sep 18 17:38:43 2018 +0200
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+
+# import packages
+from elasticapm.instrumentation.packages.base import AbstractInstrumentedModule
+from elasticapm.traces import capture_span
+
+
+class ChameleonCookingInstrumentation(AbstractInstrumentedModule):
+    name = "chameleon"
+
+    instrument_list = [("chameleon.template", "BaseTemplate.cook")]
+
+    def call(self, module, method, wrapped, instance, args, kwargs):
+        with capture_span('COOK', "template.chameleon.cook",
+                          {'filename': instance.filename}, leaf=True):
+            return wrapped(*args, **kwargs)
+
+
+class ChameleonRenderingInstrumentation(AbstractInstrumentedModule):
+    name = "chameleon"
+
+    instrument_list = [("chameleon.template", "BaseTemplate.render")]
+
+    def call(self, module, method, wrapped, instance, args, kwargs):
+        with capture_span('RENDER', "template.chameleon.render",
+                          {'filename': instance.filename}, leaf=True):
+            return wrapped(*args, **kwargs)