kezhenxu94 commented on a change in pull request #178: URL: https://github.com/apache/skywalking-python/pull/178#discussion_r794520737
########## File path: skywalking/plugins/sw_mysqlclient.py ########## @@ -0,0 +1,81 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from skywalking import Layer, Component, config +from skywalking.trace.context import get_context +from skywalking.trace.tags import TagDbType, TagDbInstance, TagDbStatement, TagDbSqlParameters + +link_vector = ['https://mysqlclient.readthedocs.io/'] +support_matrix = { + 'mysqlclient': { + '>=2.1.0': ['1.0'] + } +} +note = """""" + + +def install(): + import wrapt + import MySQLdb + + _connect = MySQLdb.connect + + def _sw_connect(*args, **kwargs): + con = _connect(*args, **kwargs) + con.host = kwargs['host'] + con.db = kwargs['db'] + return ProxyConnection(con) + + class ProxyCursor(wrapt.ObjectProxy): + def __init__(self, cur): + wrapt.ObjectProxy.__init__(self, cur) + + self._self_cur = cur + + def __enter__(self): + return ProxyCursor(wrapt.ObjectProxy.__enter__(self)) + + def execute(self, query, args=None): + peer = f'{self.connection.host}:{self.connection.port}' + with get_context().new_exit_span(op='Mysql/MysqlClient/execute', peer=peer, + component=Component.MysqlClient) as span: Review comment: > How about fastapi?we want to use this in our new project ,so we will dev the plugin. But we find fastapi is different with flask, so can you give us prompt or suggestion to diraction?thanks very much! The idea is the same , find out the key method of the framework that will be invoked when serving an API, and intercept it. What do you mean it's different from Flask? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
