cavisson-pythonagent 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. cavisson_pythonagent-0.0.1.dist-info/METADATA +32 -0
  2. cavisson_pythonagent-0.0.1.dist-info/RECORD +180 -0
  3. cavisson_pythonagent-0.0.1.dist-info/WHEEL +5 -0
  4. cavisson_pythonagent-0.0.1.dist-info/licenses/LICENSE +19 -0
  5. cavisson_pythonagent-0.0.1.dist-info/top_level.txt +1 -0
  6. pythonagent/__init__.py +22 -0
  7. pythonagent/agent/__init__.py +219 -0
  8. pythonagent/agent/internal/__init__.py +1 -0
  9. pythonagent/agent/internal/agent.py +1651 -0
  10. pythonagent/agent/internal/framesinfo.py +152 -0
  11. pythonagent/agent/internal/heap_dump.py +39 -0
  12. pythonagent/agent/internal/intercept_module.py +70 -0
  13. pythonagent/agent/internal/logs.py +122 -0
  14. pythonagent/agent/internal/metadata/__init__.py +0 -0
  15. pythonagent/agent/internal/metadata/agent_meta_data.py +276 -0
  16. pythonagent/agent/internal/proc_compat.py +75 -0
  17. pythonagent/agent/internal/profile.py +47 -0
  18. pythonagent/agent/internal/provider.py +83 -0
  19. pythonagent/agent/internal/thread_dump.py +85 -0
  20. pythonagent/agent/internal/udp.py +245 -0
  21. pythonagent/agent/internal/udp_message.py +800 -0
  22. pythonagent/agent/probes/Instrumentation/__init__.py +340 -0
  23. pythonagent/agent/probes/Instrumentation/find.py +243 -0
  24. pythonagent/agent/probes/Instrumentation/module_version_resolver.py +155 -0
  25. pythonagent/agent/probes/Instrumentation/new_parser.py +64 -0
  26. pythonagent/agent/probes/Instrumentation/parser.py +129 -0
  27. pythonagent/agent/probes/__init__.py +219 -0
  28. pythonagent/agent/probes/base.py +303 -0
  29. pythonagent/agent/probes/cache/__init__.py +51 -0
  30. pythonagent/agent/probes/cache/redis.py +119 -0
  31. pythonagent/agent/probes/cache/redis_asyncio.py +83 -0
  32. pythonagent/agent/probes/coroutines/__init__.py +1 -0
  33. pythonagent/agent/probes/coroutines/asyncio.py +63 -0
  34. pythonagent/agent/probes/elasticdb/__init__.py +7 -0
  35. pythonagent/agent/probes/elasticdb/aelastic.py +54 -0
  36. pythonagent/agent/probes/frameworks/__init__.py +27 -0
  37. pythonagent/agent/probes/frameworks/agentprofiler.py +105 -0
  38. pythonagent/agent/probes/frameworks/aiohttp_web.py +155 -0
  39. pythonagent/agent/probes/frameworks/aisess.py +151 -0
  40. pythonagent/agent/probes/frameworks/asgi.py +340 -0
  41. pythonagent/agent/probes/frameworks/bottle.py +27 -0
  42. pythonagent/agent/probes/frameworks/cherry.py +25 -0
  43. pythonagent/agent/probes/frameworks/django.py +128 -0
  44. pythonagent/agent/probes/frameworks/falcon.py +21 -0
  45. pythonagent/agent/probes/frameworks/fastapi.py +35 -0
  46. pythonagent/agent/probes/frameworks/flask.py +30 -0
  47. pythonagent/agent/probes/frameworks/pyramid.py +56 -0
  48. pythonagent/agent/probes/frameworks/test.py +108 -0
  49. pythonagent/agent/probes/frameworks/tornado_async_web.py +117 -0
  50. pythonagent/agent/probes/frameworks/tornado_web.py +133 -0
  51. pythonagent/agent/probes/frameworks/wsgi.py +353 -0
  52. pythonagent/agent/probes/grpc/__init__.py +76 -0
  53. pythonagent/agent/probes/grpc/client_interceptor.py +132 -0
  54. pythonagent/agent/probes/grpc/server_interceptor.py +129 -0
  55. pythonagent/agent/probes/havoc/__init__.py +0 -0
  56. pythonagent/agent/probes/havoc/custom_memory_stress.py +186 -0
  57. pythonagent/agent/probes/havoc/custom_thread_stress.py +187 -0
  58. pythonagent/agent/probes/havoc/havoc_constants.py +218 -0
  59. pythonagent/agent/probes/havoc/havoc_manager.py +981 -0
  60. pythonagent/agent/probes/http/__init__.py +49 -0
  61. pythonagent/agent/probes/http/aiohttp_client.py +59 -0
  62. pythonagent/agent/probes/http/boto.py +12 -0
  63. pythonagent/agent/probes/http/httplib.py +110 -0
  64. pythonagent/agent/probes/http/httpx_client.py +116 -0
  65. pythonagent/agent/probes/http/requests.py +15 -0
  66. pythonagent/agent/probes/http/tornado_httpclient.py +85 -0
  67. pythonagent/agent/probes/http/urllib3.py +16 -0
  68. pythonagent/agent/probes/langchain/__init__.py +21 -0
  69. pythonagent/agent/probes/langchain/base_tool.py +95 -0
  70. pythonagent/agent/probes/langchain/langchain_community.py +136 -0
  71. pythonagent/agent/probes/langchain/langchain_core.py +32 -0
  72. pythonagent/agent/probes/langchain/langchain_openai.py +110 -0
  73. pythonagent/agent/probes/logging/__init__.py +106 -0
  74. pythonagent/agent/probes/message_brokers/__init__.py +4 -0
  75. pythonagent/agent/probes/message_brokers/pika.py +126 -0
  76. pythonagent/agent/probes/mongodb/__init__.py +6 -0
  77. pythonagent/agent/probes/mongodb/pymongo.py +286 -0
  78. pythonagent/agent/probes/openai/__init__.py +3 -0
  79. pythonagent/agent/probes/openai/openai.py +797 -0
  80. pythonagent/agent/probes/span.py +101 -0
  81. pythonagent/agent/probes/sql/__init__.py +13 -0
  82. pythonagent/agent/probes/sql/botocores3.py +51 -0
  83. pythonagent/agent/probes/sql/dbapi.py +285 -0
  84. pythonagent/agent/probes/sql/dynamodb.py +90 -0
  85. pythonagent/agent/probes/sql/mysql_connector.py +24 -0
  86. pythonagent/agent/probes/sql/mysql_connector_cext.py +24 -0
  87. pythonagent/agent/probes/sql/mysqldb.py +43 -0
  88. pythonagent/agent/probes/sql/psycopg2.py +174 -0
  89. pythonagent/agent/probes/sql/pymysql.py +25 -0
  90. pythonagent/bootstrap/__init__.py +0 -0
  91. pythonagent/bootstrap/cav_gunicorn.py +26 -0
  92. pythonagent/bootstrap/cavagent_lambda_wrapper.py +291 -0
  93. pythonagent/bootstrap/run.py +47 -0
  94. pythonagent/bootstrap/sitecustomize.py +287 -0
  95. pythonagent/cavisson/netdiagnostics/CavAgent/instrumentationprofile.json +26 -0
  96. pythonagent/cavisson/netdiagnostics/CavAgent/interceptor_points.txt +29 -0
  97. pythonagent/cavisson/netdiagnostics/python/CavAgent/instrumentationprofile.json +42 -0
  98. pythonagent/cavisson/netdiagnostics/python/CavAgent/interceptor_points.txt +29 -0
  99. pythonagent/cavisson/netdiagnostics/python/config/ndsettings.conf +6 -0
  100. pythonagent/config.py +279 -0
  101. pythonagent/find.py +72 -0
  102. pythonagent/find_mod_cls_name.py +54 -0
  103. pythonagent/lang.py +131 -0
  104. pythonagent/lib.py +91 -0
  105. pythonagent/main/__init__.py +0 -0
  106. pythonagent/main/pytrace/__init__.py +79 -0
  107. pythonagent/main/pytrace/commands/__init__.py +0 -0
  108. pythonagent/main/pytrace/commands/auto_discovery.py +25 -0
  109. pythonagent/main/pytrace/commands/run.py +401 -0
  110. pythonagent/main/pytrace/pytrace.py +133 -0
  111. pythonagent/main/wsgi.py +6 -0
  112. pythonagent/main.py +27 -0
  113. pythonagent/run.py +46 -0
  114. pythonagent/sqins.py +8 -0
  115. pythonagent/test.py +73 -0
  116. pythonagent/utils.py +168 -0
  117. pythonagent/vendor/__init__.py +0 -0
  118. pythonagent/vendor/pympler/__init__.py +1 -0
  119. pythonagent/vendor/pympler/asizeof.py +2810 -0
  120. pythonagent/vendor/pympler/charts.py +62 -0
  121. pythonagent/vendor/pympler/classtracker.py +590 -0
  122. pythonagent/vendor/pympler/classtracker_stats.py +780 -0
  123. pythonagent/vendor/pympler/garbagegraph.py +80 -0
  124. pythonagent/vendor/pympler/mprofile.py +97 -0
  125. pythonagent/vendor/pympler/muppy.py +275 -0
  126. pythonagent/vendor/pympler/panels.py +115 -0
  127. pythonagent/vendor/pympler/process.py +238 -0
  128. pythonagent/vendor/pympler/py.typed +0 -0
  129. pythonagent/vendor/pympler/refbrowser.py +451 -0
  130. pythonagent/vendor/pympler/refgraph.py +350 -0
  131. pythonagent/vendor/pympler/summary.py +321 -0
  132. pythonagent/vendor/pympler/tracker.py +267 -0
  133. pythonagent/vendor/pympler/util/__init__.py +0 -0
  134. pythonagent/vendor/pympler/util/bottle.py +3809 -0
  135. pythonagent/vendor/pympler/util/compat.py +23 -0
  136. pythonagent/vendor/pympler/util/stringutils.py +77 -0
  137. pythonagent/vendor/pympler/web.py +346 -0
  138. pythonagent/vendor/werkzeug/__init__.py +20 -0
  139. pythonagent/vendor/werkzeug/_compat.py +228 -0
  140. pythonagent/vendor/werkzeug/_internal.py +473 -0
  141. pythonagent/vendor/werkzeug/_reloader.py +341 -0
  142. pythonagent/vendor/werkzeug/datastructures.py +3120 -0
  143. pythonagent/vendor/werkzeug/debug/__init__.py +498 -0
  144. pythonagent/vendor/werkzeug/debug/console.py +218 -0
  145. pythonagent/vendor/werkzeug/debug/repr.py +297 -0
  146. pythonagent/vendor/werkzeug/debug/tbtools.py +628 -0
  147. pythonagent/vendor/werkzeug/exceptions.py +829 -0
  148. pythonagent/vendor/werkzeug/filesystem.py +64 -0
  149. pythonagent/vendor/werkzeug/formparser.py +584 -0
  150. pythonagent/vendor/werkzeug/http.py +1307 -0
  151. pythonagent/vendor/werkzeug/local.py +420 -0
  152. pythonagent/vendor/werkzeug/middleware/__init__.py +25 -0
  153. pythonagent/vendor/werkzeug/middleware/dispatcher.py +66 -0
  154. pythonagent/vendor/werkzeug/middleware/http_proxy.py +219 -0
  155. pythonagent/vendor/werkzeug/middleware/lint.py +408 -0
  156. pythonagent/vendor/werkzeug/middleware/profiler.py +132 -0
  157. pythonagent/vendor/werkzeug/middleware/proxy_fix.py +169 -0
  158. pythonagent/vendor/werkzeug/middleware/shared_data.py +293 -0
  159. pythonagent/vendor/werkzeug/posixemulation.py +117 -0
  160. pythonagent/vendor/werkzeug/routing.py +2210 -0
  161. pythonagent/vendor/werkzeug/security.py +249 -0
  162. pythonagent/vendor/werkzeug/serving.py +1117 -0
  163. pythonagent/vendor/werkzeug/test.py +1123 -0
  164. pythonagent/vendor/werkzeug/testapp.py +241 -0
  165. pythonagent/vendor/werkzeug/urls.py +1138 -0
  166. pythonagent/vendor/werkzeug/useragents.py +202 -0
  167. pythonagent/vendor/werkzeug/utils.py +778 -0
  168. pythonagent/vendor/werkzeug/wrappers/__init__.py +36 -0
  169. pythonagent/vendor/werkzeug/wrappers/accept.py +50 -0
  170. pythonagent/vendor/werkzeug/wrappers/auth.py +33 -0
  171. pythonagent/vendor/werkzeug/wrappers/base_request.py +673 -0
  172. pythonagent/vendor/werkzeug/wrappers/base_response.py +700 -0
  173. pythonagent/vendor/werkzeug/wrappers/common_descriptors.py +341 -0
  174. pythonagent/vendor/werkzeug/wrappers/cors.py +100 -0
  175. pythonagent/vendor/werkzeug/wrappers/etag.py +304 -0
  176. pythonagent/vendor/werkzeug/wrappers/json.py +145 -0
  177. pythonagent/vendor/werkzeug/wrappers/request.py +49 -0
  178. pythonagent/vendor/werkzeug/wrappers/response.py +84 -0
  179. pythonagent/vendor/werkzeug/wrappers/user_agent.py +14 -0
  180. pythonagent/vendor/werkzeug/wsgi.py +1000 -0
@@ -0,0 +1,108 @@
1
+ import json
2
+ import os
3
+ from datetime import datetime
4
+ import platform
5
+ import time
6
+ import threading
7
+ import traceback
8
+ import sys
9
+ import multiprocessing
10
+
11
+
12
+
13
+ #****creating a function for thread dump related variables ********
14
+
15
+ def dumpstacks():
16
+
17
+ #vmName=my_system.system
18
+
19
+ my_system = platform.uname()
20
+ osName=my_system.system
21
+ osVersion=my_system.version
22
+ arch=my_system.machine
23
+ b =multiprocessing.cpu_count()
24
+ #l=psutil.getloadavg()
25
+ l=os.getloadavg()
26
+ res=sum(list(l))
27
+ u=round(res,2)/3
28
+ #ndbuild = sdk_getNdBuild()
29
+ #ndbuild := C.GoString(C.sdk_getNdBuild())
30
+ k=("Full thread dump Python Agent :- [ Dump Taken at : "+ datetime.now().strftime("%d/%m/%Y %H:%M:%S")+ " , Where BCIAgent build = \" 4.7.0 BUILD 93\" ")
31
+
32
+ #k=("Full thread dump BCI Agent :- [ Dump Taken at : "+ datetime.now().strftime("%d/%m/%Y %H:%M:%S")+ " , Where BCIAgent build =\" " + ndbuild + " \"" )
33
+ a=""
34
+
35
+ nid="0x0"
36
+ prio="5"
37
+ vendor=""
38
+ version=""
39
+
40
+ system_name = os.getenv('HOSTNAME')
41
+ #//****append the thread details into list(code)*****//
42
+ code=[]
43
+ o=[]
44
+ al=[]
45
+ for thread in threading.enumerate():
46
+
47
+ """ if thread.daemon == True:
48
+ s= 'wait'
49
+ elif (thread.is_alive() == True ):
50
+ s="Runnable"
51
+ else:
52
+ pass
53
+ #if not thread.isDaemon():
54
+ #s= 'wait'"""
55
+ o.append(thread.name)
56
+
57
+ if not thread.isDaemon():
58
+ s= 'wait'
59
+
60
+ elif thread.is_alive() == True:
61
+ s='runable'
62
+
63
+ elif thread.daemon == False:
64
+ s='waiting'
65
+
66
+ elif threading.Lock != null :
67
+ s='locked'
68
+
69
+ else:
70
+ pass
71
+
72
+ i=0
73
+ for threadId, stack in sys._current_frames().items():
74
+
75
+ code.extend(["\n\n'%s'" % o[i] + ' ' + "prio=%s"%prio + ' ' + "tid=%d"% threadId + ' ' + "nid=%s"%nid + ' ' + "%s"%s+ ' ' + "\n" + "java.lang.Thread.State: %s "% s])
76
+ i=i+1
77
+
78
+ for filename, lineno, name, line in traceback.extract_stack(stack):
79
+ code.append('File: "%s", line %d, in %s, at %s' % (filename, lineno, name,datetime.now()))
80
+ if line:
81
+ code.append(" %s" % (line.strip()))
82
+ print ("\n".join(code))
83
+
84
+ #//*****in dictionary thread dump entry page details comming ********//
85
+
86
+ thread1_details = {"":k,"vmName":osName,"version":version ,"vendor":vendor , "osName":osName,"osVersion":osVersion,"arch":arch,"noOfProcessors":b,"SysLoadAvg":u,"deadlocked threads ":a }
87
+
88
+ #//*********all details dump into logs location************//
89
+
90
+ def write_json(target_path, target_file, data):
91
+ if not os.path.exists(target_path):
92
+ try:
93
+ os.makedirs(target_path)
94
+ except Exception as e:
95
+ print(e)
96
+ raise
97
+ with open(os.path.join(target_path, target_file), 'w') as f:
98
+ json.dump(data, f)
99
+ f.write("\n".join((code)))
100
+
101
+
102
+ ndhome = os.environ.get('NDHOME')
103
+ write_file = ndhome + '/python/logs/'
104
+
105
+ write_json(write_file,
106
+ datetime.now().strftime('thread_dump_%H_%M_%d_%m_%Y.txt'), thread1_details)
107
+
108
+ #dumpstacks()
@@ -0,0 +1,117 @@
1
+ from __future__ import unicode_literals
2
+ from ..base import EntryPointInterceptor
3
+ from pythonagent.utils import get_current_thread_time_in_us, get_true_false
4
+ from pythonagent.agent.probes.havoc.havoc_manager import NDHavocException
5
+
6
+ class Tornado_async_RequestHandlerInterceptor(EntryPointInterceptor):
7
+ async def wrapper_execute(self, _execute, handler, *args, **kwargs):
8
+ bt = None
9
+ cpu_time_before = None
10
+ url = None
11
+ fp_instance = None
12
+
13
+ try:
14
+ request = handler.request
15
+ req_headers = self.parse_headers(request.headers.items(), "$", "|")
16
+ bt_header_value = self.parse_headers(request.headers.items(), "=", "&")
17
+
18
+ # if 'Cavndfpinstance' in request.headers.keys():
19
+ # fp_instance = request.headers['Cavndfpinstance']
20
+
21
+ for key, val in request.headers.items():
22
+ if key.lower() == 'cavndfpinstance':
23
+ fp_instance = val
24
+
25
+ nd_cookie_key = self.agent.nd_cookie_key
26
+ nv_cookie_key = self.agent.nv_cookie_key
27
+
28
+ nd_cookie_value = None
29
+ nv_cookie_value = None
30
+
31
+ for k, v in request.cookies.items():
32
+ if k == nd_cookie_key:
33
+ nd_cookie_value = v.value
34
+ if k == nv_cookie_key:
35
+ nv_cookie_value = v.value
36
+
37
+ url = request.uri
38
+ bt_name = url + "|" + request.method
39
+ correlation_header = ""
40
+ cpu_time_before = get_current_thread_time_in_us()
41
+ bt = self.start_business_transaction(bt_name, correlation_header, nd_cookie_value, nv_cookie_value, bt_header_value, fp_instance)
42
+ self.agent.http_req_resp_wrapper(bt, req_headers, "req", 200)
43
+ self.agent.logger.debug("Modulename: Tornado_async_RequestHandlerInterceptor class || bt value is :{0}".format(bt))
44
+ except Exception as e:
45
+ self.agent.logger.exception("Error in Tornado_async_RequestHandlerInterceptor class start business transaction", e)
46
+
47
+ result = await _execute(handler, *args, **kwargs)
48
+
49
+ try:
50
+ if bt:
51
+ cpu_time_after = get_current_thread_time_in_us()
52
+ cpu_time = cpu_time_after - cpu_time_before
53
+
54
+ nd_cookie_key = None
55
+ x_cav_nv = None
56
+ x_cav_nv_headers = None
57
+
58
+ if self.agent.header_in_response:
59
+ x_cav_nv = get_true_false(self.agent.header_in_response)
60
+
61
+ result_headers = handler._headers
62
+ nd_cookie_value = self.agent.sdk_getNDSessionCookie(bt).decode()
63
+ if nd_cookie_key: # CavNV Enabled
64
+ if nd_cookie_value:
65
+ nd_cookie_str = "{}={}".format(nd_cookie_key, nd_cookie_value)
66
+ result_headers['Set-Cookie'] = nd_cookie_str
67
+ else:
68
+ if self.agent.disable_nd_nv: # CavNV Disabled Just Now
69
+ nd_cookie_str = "CavNV=None; Max-Age=0"
70
+ result_headers['Set-Cookie'] = nd_cookie_str
71
+ self.agent.disable_nd_nv = False
72
+
73
+ if x_cav_nv: # X-CavNV Enabled
74
+ if nd_cookie_value:
75
+ result_headers['X-CavNV'] = nd_cookie_value
76
+ x_cav_nv_headers = "|X-CavNV$" + nd_cookie_value
77
+
78
+ result_status = handler.get_status()
79
+ resp_headers = self.parse_headers(result_headers.items(), "$", "|")
80
+ self.agent.http_req_resp_wrapper(bt, resp_headers, "resp", result_status)
81
+
82
+ try:
83
+ context = self.agent.get_transaction_context()
84
+ btname = context.btname if context else None
85
+ self.agent.havoc_monitor.apply_inbound_service_failure(url, btname)
86
+ except Exception as e:
87
+ if isinstance(e, NDHavocException):
88
+ self.agent.set_current_status_code(503)
89
+ rc = self.agent.end_business_transaction(bt, cpu_time)
90
+ self.agent.havoc_monitor.refresh_configs(self.agent)
91
+ raise e
92
+ else:
93
+ self.agent.logger.debug("Non-Havoc Exception {}".format(e))
94
+
95
+ self.agent.end_business_transaction(bt, cpu_time)
96
+
97
+ except Exception as e:
98
+ self.agent.logger.exception("Error in Tornado_async_RequestHandlerInterceptor class end business transaction", e)
99
+
100
+ return result
101
+
102
+
103
+ def parse_headers(self, input_list, key_val_sep, item_value_sep):
104
+ output_str = ""
105
+ for key, value in input_list:
106
+ value = value.replace("|", "%7C") # CavSF has | in value
107
+ value = value.replace(":", "%3A") # Host as : in value
108
+ value = value.replace("=", "%3D") # Accept, Accept-Language, and ND-NV cookies have = in value
109
+ new_str = key + key_val_sep + value + item_value_sep
110
+ output_str += new_str
111
+ output_str = output_str[:-1] # Remove last |
112
+ return output_str
113
+
114
+
115
+ def intercept_tornado_async_web(agent, mod):
116
+ agent.logger.warning("Instrument module: tornado.web{}".format(", mod: {}".format(mod) if mod else ""))
117
+ Tornado_async_RequestHandlerInterceptor(agent, mod.RequestHandler).attach('_execute', patched_method_name="wrapper_execute")
@@ -0,0 +1,133 @@
1
+
2
+ from __future__ import unicode_literals
3
+ import contextlib
4
+ import sys
5
+ #import threading
6
+
7
+ #from lib import LazyWsgiRequest
8
+ #from appdynamics.agent.core.eum import inject_eum_metadata
9
+ #from appdynamics.agent.models.transactions import ENTRY_TORNADO
10
+ from ..base import EntryPointInterceptor
11
+ #from agent.internal.proxy import *
12
+ #import agent
13
+ #ENTRY_PYTHON_WEB = pb.PYTHON_WEB # need to ask ENTRY_PYTHON_WEB value
14
+ #ENTRY_TORNADO = ENTRY_PYTHON_WEB
15
+ try:
16
+ import tornado.httputil
17
+ import tornado.ioloop
18
+ # import tornado.stack_context
19
+ # import tornado.stack_context.StackContext
20
+ import tornado.web
21
+ import tornado.wsgi
22
+
23
+ class TornadoFallbackHandlerInterceptor(EntryPointInterceptor):
24
+ #proxy = Proxy.getInstance()
25
+ # print("framework tornado_web: TornadoFallbackHandlerInterceptor function proxy instance inside tornado_web.py : ", proxy)
26
+ # print("framework tornado_web: TornadoFallbackHandlerInterceptor function proxy.lib inside class level variable inside tornado_web module : ", proxy.lib)
27
+ # When using FallbackHandler, the RequestHandler's finish method is
28
+ # never called. Wrap the custom fallback callable to end the bt here.
29
+ def _initialize(self, initialize, handler, fallback):
30
+ self.agent.logger.info('Modulename: TornadoFallbackHandlerInterceptor class')
31
+ def _fallback(request):
32
+ fallback(request)
33
+ bt = self.bt
34
+ self.agent.logger.debug("Modulename: TornadoFallbackHandlerInterceptor class || bt value is :{0}".format(bt))
35
+ if bt:
36
+ #self.end_transaction(bt)
37
+ self.end_business_transaction(bt)
38
+ initialize(handler, _fallback)
39
+
40
+ class TornadoRequestHandlerInterceptor(EntryPointInterceptor):
41
+ def __execute(self, _execute, handler, *args, **kwargs):
42
+ # bt = self.proxy.start_business_transaction(ENTRY_TORNADO,
43
+ # LazyWsgiRequest(tornado.wsgi.WSGIContainer.environ(handler.request)))
44
+ # bt = self.start_business_transaction(handler.request,correlation_header=None)
45
+ requests = handler.request
46
+ bt = self.start_business_transaction(requests.path,'')
47
+ #self.agent.logger.info("framework tornado_web: TornadoRequestHandlerInterceptor function print value of bt " .format(bt))
48
+ self.agent.logger.debug("Modulename: TornadoRequestHandlerInterceptor class || bt value is :{0}".format(bt))
49
+
50
+ #local_thread = threading.local()
51
+ #local_thread.context = bt
52
+
53
+ try:
54
+ #print("framework tornado_web: TornadoRequestHandlerInterceptor request in ===>: ", handler.request)
55
+
56
+ #self.agent.logger.info("Modulename: TornadoRequestHandlerInterceptor class insinde __execute function request is :{0}".format(handler.request))
57
+ # requests =handler.request
58
+ #print("framework tornado_web: TornadoRequestHandlerInterceptor request.PATH_INFO ===>: ", requests.path)
59
+ #self.agent.logger.info("Modulename: TornadoRequestHandlerInterceptor class insinde __execute function request.PATH_INFO is :{0}".format(requests.path))
60
+ #print("framework tornado_web: TornadoRequestHandlerInterceptor request.QUERY_STRING ===>: ", requests.query_string)
61
+ #self.agent.logger.info("Modulename: TornadoRequestHandlerInterceptor class insinde __execute function request.QUERY_STRING is :{0}".format(requests.query_string))
62
+ # print("WSGI interceptor request.data ===>: ", request.data)
63
+ #print("framework tornado_web: TornadoRequestHandlerInterceptor request.host ===>: ", requests.host)
64
+ self.agent.logger.info("Modulename: TornadoRequestHandlerInterceptor class insinde __execute function requests.host is :{0}".format(requests.host))
65
+ except:
66
+ pass
67
+
68
+ if bt:
69
+ @contextlib.contextmanager
70
+ def current_bt_manager():
71
+ """Set and unset current_bt as tornado moves between execution contexts.
72
+
73
+ By wrapping the handler's execution with this we can ensure that whenever the
74
+ IOLoop is executing code for a particular BT, that BT is the 'current_bt'.
75
+ For more information see http://www.tornadoweb.org/en/stable/stack_context.html.
76
+
77
+ """
78
+ self.agent.set_current_bt(bt)
79
+ try:
80
+ yield
81
+ except:
82
+ # Currently can't figure out how to get here, so this code is untested.
83
+ #bt.add_exception(*sys.exc_info())
84
+ self.agent.logger.debug("Modulename: TornadoRequestHandlerInterceptor class || Exception is :{0}".format(*sys.exc_info()))
85
+ raise
86
+ finally:
87
+ self.agent.unset_current_bt()
88
+
89
+ # with tornado.stack_context.StackContext(current_bt_manager):
90
+ result = _execute(handler, *args, **kwargs)
91
+ else:
92
+ result = _execute(handler, *args, **kwargs)
93
+
94
+ return result
95
+
96
+ def _finish(self, finish, handler, *args, **kwargs):
97
+ result = finish(handler, *args, **kwargs)
98
+ bt = self.bt
99
+ if bt:
100
+ with self.log_exceptions():
101
+ self.handle_http_status_code(bt, handler._status_code, handler._reason)
102
+ #self.end_transaction(bt)
103
+ self.end_business_transaction(bt)
104
+ return result
105
+
106
+ def _flush(self, flush, handler, *args, **kwargs):
107
+ with self.log_exceptions():
108
+ if not handler._headers_written:
109
+ bt = self.bt
110
+ if bt:
111
+ headers = list(handler._headers.get_all())
112
+ # inject_eum_metadata(self.agent.eum_config, bt, headers)
113
+ handler._headers = tornado.httputil.HTTPHeaders(headers)
114
+ return flush(handler, *args, **kwargs)
115
+
116
+ def __handle_request_exception(self, _handle_request_exception, handler, e, *args, **kwargs):
117
+ with self.log_exceptions():
118
+ bt = self.bt
119
+ if bt and not (hasattr(tornado.web, 'Finish') and isinstance(e, tornado.web.Finish)):
120
+ #bt.add_exception(*sys.exc_info())
121
+ self.agent.logger.debug("Modulename: TornadoRequestHandlerInterceptor class || Exception is :{0}".format(*sys.exc_info()))
122
+ return _handle_request_exception(handler, e, *args, **kwargs)
123
+
124
+ def intercept_tornado_web(agent, mod):
125
+ #print("framework torando_web : intercept_torando_web")
126
+ TornadoRequestHandlerInterceptor(agent, mod.RequestHandler).attach(
127
+ ['_execute', 'flush', '_handle_request_exception', 'finish'])
128
+ TornadoFallbackHandlerInterceptor(agent, mod.FallbackHandler).attach('initialize')
129
+
130
+ except ImportError:
131
+ def intercept_tornado_web(agent, mod):
132
+ pass
133
+