whatap-python 1.6.9__tar.gz → 1.7.0__tar.gz
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.
Potentially problematic release.
This version of whatap-python might be problematic. Click here for more details.
- {whatap_python-1.6.9 → whatap_python-1.7.0}/PKG-INFO +1 -1
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/agent/linux/amd64/whatap_python +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/agent/linux/arm64/whatap_python +0 -0
- whatap_python-1.7.0/whatap/build.py +4 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_django.py +18 -2
- whatap_python-1.7.0/whatap/trace/mod/application_django_asgi.py +263 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_fastapi.py +3 -3
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/trace_context.py +1 -1
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/trace_module_definition.py +3 -14
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap_python.egg-info/PKG-INFO +1 -1
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap_python.egg-info/SOURCES.txt +1 -0
- whatap_python-1.6.9/whatap/build.py +0 -4
- {whatap_python-1.6.9 → whatap_python-1.7.0}/README.md +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/setup.cfg +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/setup.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/LICENSE +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/README.rst +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/__main__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/agent/darwin/amd64/whatap_python +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/agent/darwin/arm64/whatap_python +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/bootstrap/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/bootstrap/sitecustomize.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/conf/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/conf/configuration.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/conf/configure.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/conf/license.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/control/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/io/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/io/data_inputx.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/io/data_outputx.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/net/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/net/async_sender.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/net/packet_enum.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/net/packet_type_enum.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/net/param_def.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/net/stackhelper.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/net/udp_session.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/net/udp_thread.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/pack/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/pack/logSinkPack.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/pack/pack.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/pack/pack_enum.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/scripts/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/amqp_kombu.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/amqp_pika.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_bottle.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_celery.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_cherrypy.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_django_py3.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_flask.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_frappe.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_graphql.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_nameko.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_tornado.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/application_wsgi.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/database_cxoracle.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/database_mongo.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/database_mysql.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/database_postgresql.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/database_redis.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/database_toolkit.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/email_smtp.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/httpc_django.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/httpc_httplib.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/httpc_requests.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/httpc_urllib3.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/logging.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/mod/plugin.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/simple_trace_context.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/trace_context_manager.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/trace/trace_import.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/bit_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/cardinality/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/cardinality/hyperloglog.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/cardinality/murmurhash.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/cardinality/registerset.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/compare_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/date_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/debug_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/escape_literal_sql.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/hash_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/hexa32.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/int_set.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/ip_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/keygen.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/linked_list.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/linked_map.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/metering_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/request_double_queue.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/request_queue.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/string_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/throttle_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/util/userid_util.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/__init__.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/blob_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/boolean_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/decimal_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/double_summary.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/double_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/float_array.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/float_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/int_array.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/ip4_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/list_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/long_array.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/long_summary.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/map_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/null_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/number_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/summary_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/text_array.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/text_hash_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/text_value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/value.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/value/value_enum.py +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap/whatap.conf +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap_python.egg-info/dependency_links.txt +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap_python.egg-info/entry_points.txt +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap_python.egg-info/not-zip-safe +0 -0
- {whatap_python-1.6.9 → whatap_python-1.7.0}/whatap_python.egg-info/top_level.txt +0 -0
|
Binary file
|
|
Binary file
|
|
@@ -130,7 +130,6 @@ def instrument_handlers_base(module):
|
|
|
130
130
|
return callback
|
|
131
131
|
|
|
132
132
|
return trace
|
|
133
|
-
|
|
134
133
|
if hasattr(module.BaseHandler, 'apply_response_fixes'):
|
|
135
134
|
module.BaseHandler.apply_response_fixes = wrapper(
|
|
136
135
|
module.BaseHandler.apply_response_fixes)
|
|
@@ -152,7 +151,6 @@ def instrument_handlers_base(module):
|
|
|
152
151
|
return callback
|
|
153
152
|
|
|
154
153
|
return trace
|
|
155
|
-
|
|
156
154
|
if hasattr(module.BaseHandler, 'handle_uncaught_exception'):
|
|
157
155
|
module.BaseHandler.handle_uncaught_exception = wrapper(
|
|
158
156
|
module.BaseHandler.handle_uncaught_exception)
|
|
@@ -183,6 +181,24 @@ def instrument_handlers_base(module):
|
|
|
183
181
|
module.BaseHandler.get_response = get_response_wrapper(
|
|
184
182
|
module.BaseHandler.get_response)
|
|
185
183
|
|
|
184
|
+
def wrapper_async(fn):
|
|
185
|
+
@trace_handler_async(fn)
|
|
186
|
+
async def trace(*args, **kwargs):
|
|
187
|
+
## asgi applicaiton 에서 threading.local()을 사용할 경우 데이터가 침해 될 수 있다.
|
|
188
|
+
## contextvars 를 이용하여 현재 실행중인 코루틴 콘텍스트를 유지한다.
|
|
189
|
+
request = args[1]
|
|
190
|
+
scope = request.scope
|
|
191
|
+
ctx = scope.get(WHATAP_CTX)
|
|
192
|
+
callback = await fn(*args, **kwargs)
|
|
193
|
+
ctx.asgi_response = callback
|
|
194
|
+
if ctx and conf.trace_user_enabled:
|
|
195
|
+
if not conf.trace_user_using_ip:
|
|
196
|
+
userid_util.setUserId(request, callback, ctx._rawuserid)
|
|
197
|
+
|
|
198
|
+
return callback
|
|
199
|
+
return trace
|
|
200
|
+
if hasattr(module, 'BaseHandler') and hasattr(module.BaseHandler, 'get_response_async'):
|
|
201
|
+
module.BaseHandler.get_response_async = wrapper_async(module.BaseHandler.get_response_async)
|
|
186
202
|
# if django_py3_loaded:
|
|
187
203
|
# instrument_handlers_async(module)
|
|
188
204
|
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import logging as logging_module
|
|
2
|
+
import traceback
|
|
3
|
+
from whatap.conf.configure import Configure as conf
|
|
4
|
+
from whatap.net import async_sender
|
|
5
|
+
from whatap.trace.trace_context_manager import TraceContextManager
|
|
6
|
+
from whatap.trace.trace_context import TraceContext
|
|
7
|
+
from whatap.trace.mod.application_wsgi import isIgnore, start_interceptor, end_interceptor
|
|
8
|
+
from whatap.util.hash_util import HashUtil as hash_util
|
|
9
|
+
from whatap.util.userid_util import UseridUtil
|
|
10
|
+
from whatap.util.date_util import DateUtil
|
|
11
|
+
from whatap.util.hexa32 import Hexa32 as hexa32
|
|
12
|
+
from whatap.util.keygen import KeyGen
|
|
13
|
+
import whatap.util.throttle_util as throttle_util
|
|
14
|
+
from whatap.net.packet_type_enum import PacketTypeEnum
|
|
15
|
+
from whatap import logging
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
SCOPE_ARGS_LENGTH = 2
|
|
19
|
+
HEADER = 'headers'
|
|
20
|
+
PATH = 'path'
|
|
21
|
+
USER_AGENT = 'user-agent'
|
|
22
|
+
REFERER = 'referer'
|
|
23
|
+
CLIENT = 'client'
|
|
24
|
+
COOKIE = 'cookie'
|
|
25
|
+
HOST = 'host'
|
|
26
|
+
QUERY_STRING = 'query_string'
|
|
27
|
+
WHATAP_CTX = '__whatap__ctx'
|
|
28
|
+
logger = logging_module.getLogger(__name__)
|
|
29
|
+
|
|
30
|
+
def blocking_handler_asgi():
|
|
31
|
+
def handler(func):
|
|
32
|
+
from django.http import HttpResponse, HttpResponseRedirect
|
|
33
|
+
async def wrapper(instance, scope, receive, send):
|
|
34
|
+
args = (instance, scope, receive, send)
|
|
35
|
+
scope, headers = parseHeaders(args)
|
|
36
|
+
assert scope, headers
|
|
37
|
+
if conf.throttle_enabled:
|
|
38
|
+
remote_ip = parseRemoteAddr(scope, headers)
|
|
39
|
+
path = scope.get(PATH)
|
|
40
|
+
if throttle_util.isblocking(remote_ip, path):
|
|
41
|
+
if conf.reject_event_enabled:
|
|
42
|
+
ctx = TraceContextManager.getLocalContext()
|
|
43
|
+
if not ctx:
|
|
44
|
+
ctx = TraceContext()
|
|
45
|
+
throttle_util.sendrejectevent(ctx, path, remote_ip)
|
|
46
|
+
|
|
47
|
+
if conf.throttle_blocked_forward:
|
|
48
|
+
response = HttpResponseRedirect(status=302, redirect_to=conf.throttle_blocked_forward)
|
|
49
|
+
|
|
50
|
+
if path == conf.throttle_blocked_forward:
|
|
51
|
+
response = HttpResponse(content=conf.throttle_blocked_message, status=200)
|
|
52
|
+
|
|
53
|
+
return await instance.send_response(response, send)
|
|
54
|
+
|
|
55
|
+
response = HttpResponse(content=conf.throttle_blocked_message, status=403)
|
|
56
|
+
return await instance.send_response(response, send)
|
|
57
|
+
return await func(instance, scope, receive, send)
|
|
58
|
+
return wrapper
|
|
59
|
+
return handler
|
|
60
|
+
|
|
61
|
+
def trace_handler_asgi(fn):
|
|
62
|
+
def handler(func):
|
|
63
|
+
async def wrapper(instance, scope, receive, send):
|
|
64
|
+
if scope["type"] != "http":
|
|
65
|
+
await fn(instance, scope, receive, send)
|
|
66
|
+
try:
|
|
67
|
+
await func(instance, scope, receive, send)
|
|
68
|
+
except Exception as e:
|
|
69
|
+
logging.debug(e, extra={'id': 'WA917'}, exc_info=True)
|
|
70
|
+
print(e, dict(extra={'id': 'WA917'}, exc_info=True))
|
|
71
|
+
import traceback
|
|
72
|
+
traceback.print_exc()
|
|
73
|
+
return wrapper
|
|
74
|
+
return handler
|
|
75
|
+
|
|
76
|
+
def trace_handler_async(fn):
|
|
77
|
+
def handler(func):
|
|
78
|
+
async def wrapper(*args, **kwargs):
|
|
79
|
+
try:
|
|
80
|
+
response = await func(*args, **kwargs)
|
|
81
|
+
except Exception as e:
|
|
82
|
+
logging.debug(e, extra={'id': 'WA917'}, exc_info=True)
|
|
83
|
+
print(e, dict(extra={'id': 'WA917'}, exc_info=True))
|
|
84
|
+
import traceback
|
|
85
|
+
traceback.print_exc()
|
|
86
|
+
return await fn(*args, **kwargs)
|
|
87
|
+
else:
|
|
88
|
+
return response
|
|
89
|
+
return wrapper
|
|
90
|
+
return handler
|
|
91
|
+
|
|
92
|
+
def parseServiceName(environ):
|
|
93
|
+
return environ.get('PATH_INFO', '')
|
|
94
|
+
|
|
95
|
+
def parseHeaders(args):
|
|
96
|
+
headers = {}
|
|
97
|
+
if len(args) > SCOPE_ARGS_LENGTH:
|
|
98
|
+
scope = args[1]
|
|
99
|
+
if HEADER in scope:
|
|
100
|
+
for arg in scope[HEADER]:
|
|
101
|
+
headers[str(arg[0].decode()).lower()] = str(arg[1].decode())
|
|
102
|
+
|
|
103
|
+
return scope, headers
|
|
104
|
+
return None, None
|
|
105
|
+
|
|
106
|
+
def parseRemoteAddr(scope, headers):
|
|
107
|
+
remoteIp = ''
|
|
108
|
+
if CLIENT in scope:
|
|
109
|
+
remoteIp = scope.get(CLIENT)[0]
|
|
110
|
+
if conf.trace_http_client_ip_header_key:
|
|
111
|
+
header_val = headers.get(conf.trace_http_client_ip_header_key, '')
|
|
112
|
+
remoteIp = header_val.split(',')[0].strip()
|
|
113
|
+
|
|
114
|
+
return remoteIp
|
|
115
|
+
|
|
116
|
+
def getUserId(scope, headers, defValue):
|
|
117
|
+
try:
|
|
118
|
+
if conf.user_header_ticket:
|
|
119
|
+
ticket = headers.get(conf.user_header_ticket, "")
|
|
120
|
+
if ticket:
|
|
121
|
+
return hash_util.hashFromString(ticket), ticket
|
|
122
|
+
return 0, ""
|
|
123
|
+
cookie = headers.get(COOKIE, "")
|
|
124
|
+
if cookie:
|
|
125
|
+
if len(cookie) >= conf.trace_user_cookie_limit:
|
|
126
|
+
return defValue
|
|
127
|
+
|
|
128
|
+
x1 = cookie.find(UseridUtil.WHATAP_R)
|
|
129
|
+
if x1 >= 0:
|
|
130
|
+
x2 = cookie.find(';', x1)
|
|
131
|
+
if x2 > 0:
|
|
132
|
+
value = cookie[x1 + len(UseridUtil.WHATAP_R) + 1: x2]
|
|
133
|
+
else:
|
|
134
|
+
value = cookie[x1 + len(UseridUtil.WHATAP_R) + 1:]
|
|
135
|
+
return hexa32.toLong32(value), value
|
|
136
|
+
userid = KeyGen.next()
|
|
137
|
+
return userid, hexa32.toString32(userid)
|
|
138
|
+
except Exception:
|
|
139
|
+
exc_type, exc_value, exc_traceback = sys.exc_info()
|
|
140
|
+
logger.debug("A502", 10, str(exc_value))
|
|
141
|
+
|
|
142
|
+
def interceptor_error_asgi(ctx, status_code, errors):
|
|
143
|
+
ctx.status = int(status_code/ 100)
|
|
144
|
+
if ctx.status >= 4:
|
|
145
|
+
ctx.error = 1
|
|
146
|
+
|
|
147
|
+
error = ''
|
|
148
|
+
frame = sys._current_frames().get(ctx.thread.ident)
|
|
149
|
+
if not frame:
|
|
150
|
+
return
|
|
151
|
+
|
|
152
|
+
for stack in traceback.extract_stack(frame):
|
|
153
|
+
line = stack[0]
|
|
154
|
+
line_num = stack[1]
|
|
155
|
+
method_name = stack[2]
|
|
156
|
+
|
|
157
|
+
if line.find('/whatap/trace') > -1 or line.find(
|
|
158
|
+
'/threading.py') > -1:
|
|
159
|
+
continue
|
|
160
|
+
error += '{} ({}:{})\n'.format(method_name, line, line_num)
|
|
161
|
+
|
|
162
|
+
errors.append(error)
|
|
163
|
+
|
|
164
|
+
# errors.append(''.join(traceback.format_list(traceback.extract_stack(sys._current_frames()[ctx.thread.ident]))))
|
|
165
|
+
async_sender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors)
|
|
166
|
+
|
|
167
|
+
async def interceptor_asgi(fn, *args, **kwargs):
|
|
168
|
+
scope, headers = parseHeaders(args)
|
|
169
|
+
if scope == None and headers == None:
|
|
170
|
+
return await fn(*args, **kwargs)
|
|
171
|
+
|
|
172
|
+
ctx = TraceContext()
|
|
173
|
+
ctx.host = headers.get(HOST, '').split(':')[0]
|
|
174
|
+
ctx.service_name = scope.get(PATH)
|
|
175
|
+
|
|
176
|
+
ctx.remoteIp = parseRemoteAddr(scope, headers)
|
|
177
|
+
|
|
178
|
+
ctx.userAgentString = headers.get(USER_AGENT, '')
|
|
179
|
+
ctx.referer = headers.get(REFERER, '')
|
|
180
|
+
|
|
181
|
+
if conf.trace_user_enabled:
|
|
182
|
+
if conf.trace_user_using_ip:
|
|
183
|
+
ctx.userid = parseRemoteAddr(scope, headers)
|
|
184
|
+
else:
|
|
185
|
+
ctx.userid, ctx._rawuserid = getUserId(scope, headers, ctx.remoteIp)
|
|
186
|
+
|
|
187
|
+
mstt = headers.get(
|
|
188
|
+
conf._trace_mtrace_caller_key.lower().replace('-', '_'), '')
|
|
189
|
+
|
|
190
|
+
if mstt:
|
|
191
|
+
ctx.setTransfer(mstt)
|
|
192
|
+
if conf.stat_mtrace_enabled:
|
|
193
|
+
val = headers.get(
|
|
194
|
+
conf._trace_mtrace_info_key.lower().replace('-', '_'), '')
|
|
195
|
+
if val and len(val):
|
|
196
|
+
ctx.setTransferInfo(val)
|
|
197
|
+
pass
|
|
198
|
+
|
|
199
|
+
myid = headers.get(
|
|
200
|
+
conf._trace_mtrace_callee_key.lower().replace('-', '_'), '')
|
|
201
|
+
if myid:
|
|
202
|
+
ctx.setTxid(myid)
|
|
203
|
+
caller_poid = headers.get(
|
|
204
|
+
conf._trace_mtrace_caller_poid_key.upper().replace('-', '_'), '')
|
|
205
|
+
|
|
206
|
+
if caller_poid:
|
|
207
|
+
ctx.mcaller_poid = caller_poid
|
|
208
|
+
|
|
209
|
+
try:
|
|
210
|
+
if isIgnore(ctx.service_name):
|
|
211
|
+
ctx.is_ignored = True
|
|
212
|
+
return fn(*args, **kwargs)
|
|
213
|
+
except Exception as e:
|
|
214
|
+
pass
|
|
215
|
+
|
|
216
|
+
start_interceptor(ctx)
|
|
217
|
+
try:
|
|
218
|
+
scope[WHATAP_CTX] = ctx
|
|
219
|
+
await fn(*args, **kwargs)
|
|
220
|
+
response = ctx.asgi_response
|
|
221
|
+
|
|
222
|
+
query_string = str(scope.get(QUERY_STRING, ''))
|
|
223
|
+
if query_string:
|
|
224
|
+
ctx.service_name += '?{}'.format(query_string)
|
|
225
|
+
|
|
226
|
+
if ctx.service_name.find('.') > -1 and ctx.service_name.split('.')[
|
|
227
|
+
1] in conf.web_static_content_extensions:
|
|
228
|
+
ctx.isStaticContents = 'true'
|
|
229
|
+
|
|
230
|
+
if response:
|
|
231
|
+
status_code = response.status_code
|
|
232
|
+
errors = [response.__class__.__name__, response.reason_phrase]
|
|
233
|
+
interceptor_error_asgi(ctx, status_code, errors)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
if conf.profile_http_header_enabled:
|
|
237
|
+
keys = []
|
|
238
|
+
for key, value in headers.items():
|
|
239
|
+
keys.append(key)
|
|
240
|
+
keys.sort()
|
|
241
|
+
|
|
242
|
+
text = ''
|
|
243
|
+
for key in keys:
|
|
244
|
+
text += '{}={}\n'.format(key.lower(),
|
|
245
|
+
headers[key])
|
|
246
|
+
|
|
247
|
+
datas = ['HTTP-HEADERS', 'HTTP-HEADERS', text]
|
|
248
|
+
ctx.start_time = DateUtil.nowSystem()
|
|
249
|
+
async_sender.send_packet(PacketTypeEnum.TX_MSG, ctx, datas)
|
|
250
|
+
finally:
|
|
251
|
+
if ctx:
|
|
252
|
+
end_interceptor(ctx=ctx)
|
|
253
|
+
|
|
254
|
+
def instrument_asgi(module):
|
|
255
|
+
def wrapper(fn):
|
|
256
|
+
@trace_handler_asgi(fn)
|
|
257
|
+
@blocking_handler_asgi()
|
|
258
|
+
async def trace(instance, scope, receive, send):
|
|
259
|
+
await interceptor_asgi(fn, instance, scope, receive, send)
|
|
260
|
+
return trace
|
|
261
|
+
|
|
262
|
+
### module 있는지 체크 하고 파일을 분리해야함.
|
|
263
|
+
module.ASGIHandler.__call__ = wrapper(module.ASGIHandler.__call__)
|
|
@@ -241,7 +241,7 @@ def interceptor(fn, dependant, *args, **kwargs):
|
|
|
241
241
|
async def interceptor_async(fn, dependant, *args, **kwargs):
|
|
242
242
|
if not hasattr(dependant, _WHATAP_DICT):
|
|
243
243
|
return await fn(*args, **kwargs)
|
|
244
|
-
|
|
244
|
+
|
|
245
245
|
ctx = TraceContextManager.getLocalContext()
|
|
246
246
|
|
|
247
247
|
ctx.service_name = dependant.path
|
|
@@ -288,7 +288,7 @@ async def interceptor_async(fn, dependant, *args, **kwargs):
|
|
|
288
288
|
return await fn(*args, **kwargs)
|
|
289
289
|
except Exception as e:
|
|
290
290
|
pass
|
|
291
|
-
|
|
291
|
+
|
|
292
292
|
start_interceptor(ctx)
|
|
293
293
|
|
|
294
294
|
try:
|
|
@@ -391,7 +391,7 @@ def instrument_util(module):
|
|
|
391
391
|
'query_params': copy(request.query_params),
|
|
392
392
|
})
|
|
393
393
|
ret = await fn(*args, **kwargs)
|
|
394
|
-
if len(ret) >= 4:
|
|
394
|
+
if hasattr(ret, '__len__') and len(ret) >= 4:
|
|
395
395
|
response = ret[3]
|
|
396
396
|
whatap_dict[_RESPONSE] = response
|
|
397
397
|
|
|
@@ -17,7 +17,6 @@ DEFINITION = {
|
|
|
17
17
|
],
|
|
18
18
|
'httpc_urllib3': [
|
|
19
19
|
('urllib3.request', 'instrument_urllib3'),
|
|
20
|
-
# ('requests.packages.urllib3.request', 'instrument_urllib3'),
|
|
21
20
|
],
|
|
22
21
|
'httpc_django': [
|
|
23
22
|
('revproxy.views', 'instrument_revproxy_views'),
|
|
@@ -50,8 +49,6 @@ DEFINITION = {
|
|
|
50
49
|
],
|
|
51
50
|
'application_django': [
|
|
52
51
|
('django.core.handlers.wsgi', 'instrument'),
|
|
53
|
-
('django.core.handlers.asgi', 'instrument_asgi'),
|
|
54
|
-
|
|
55
52
|
('django.core.handlers.base', 'instrument_handlers_base'),
|
|
56
53
|
('django.views.generic.base', 'instrument_generic_base'),
|
|
57
54
|
('django.contrib.staticfiles.handlers', 'instrument_handlers_static'),
|
|
@@ -64,6 +61,9 @@ DEFINITION = {
|
|
|
64
61
|
False),
|
|
65
62
|
|
|
66
63
|
],
|
|
64
|
+
'application_django_asgi': [
|
|
65
|
+
('django.core.handlers.asgi', 'instrument_asgi'),
|
|
66
|
+
],
|
|
67
67
|
'application_flask': [
|
|
68
68
|
('flask', 'instrument'),
|
|
69
69
|
],
|
|
@@ -71,15 +71,9 @@ DEFINITION = {
|
|
|
71
71
|
('tornado.web', 'instrument'),
|
|
72
72
|
],
|
|
73
73
|
'application_celery': [
|
|
74
|
-
# ('celery.task.base', 'instrument_task_base'),
|
|
75
|
-
#('celery.app.task', 'instrument_app_task'),
|
|
76
|
-
#('celery.worker', 'instrument_celery_worker'),
|
|
77
|
-
#('celery.concurrency.processes', 'instrument_celery_worker'),
|
|
78
|
-
#('celery.concurrency.prefork', 'instrument_celery_worker'),
|
|
79
74
|
('celery.execute.trace', 'instrument_celery_execute_trace'),
|
|
80
75
|
('celery.task.trace', 'instrument_celery_execute_trace'),
|
|
81
76
|
('celery.app.trace', 'instrument_celery_execute_trace'),
|
|
82
|
-
#('billiard.pool', 'instrument_billiard_pool'),
|
|
83
77
|
],
|
|
84
78
|
'database_redis':[
|
|
85
79
|
('redis','instrument_redis_connection'),
|
|
@@ -87,9 +81,6 @@ DEFINITION = {
|
|
|
87
81
|
'email_smtp':[
|
|
88
82
|
('smtplib','instrument_smtp'),
|
|
89
83
|
],
|
|
90
|
-
# 'amqp_kombu':[
|
|
91
|
-
# ('kombu','instrument_kombu'),
|
|
92
|
-
# ],
|
|
93
84
|
'amqp_pika':[
|
|
94
85
|
('pika.channel','instrument_pika'),
|
|
95
86
|
],
|
|
@@ -98,8 +89,6 @@ DEFINITION = {
|
|
|
98
89
|
('spsengine.containers', 'instrument_nameko_spawn_worker'),
|
|
99
90
|
],
|
|
100
91
|
'application_graphql':[
|
|
101
|
-
#('graphql','instrument_graphql'),
|
|
102
|
-
|
|
103
92
|
#graphen-core 3.x~
|
|
104
93
|
('graphql.execution.execute','instrument_graphql'),
|
|
105
94
|
|
|
@@ -47,6 +47,7 @@ whatap/trace/mod/application_bottle.py
|
|
|
47
47
|
whatap/trace/mod/application_celery.py
|
|
48
48
|
whatap/trace/mod/application_cherrypy.py
|
|
49
49
|
whatap/trace/mod/application_django.py
|
|
50
|
+
whatap/trace/mod/application_django_asgi.py
|
|
50
51
|
whatap/trace/mod/application_django_py3.py
|
|
51
52
|
whatap/trace/mod/application_fastapi.py
|
|
52
53
|
whatap/trace/mod/application_flask.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|