From 46a96e2024ba2194444f693727725d903c2a3eea Mon Sep 17 00:00:00 2001 From: Axel Suarez Date: Thu, 16 Jan 2020 17:41:25 -0800 Subject: [PATCH 1/9] Initial version of aiohttp telemetry middleware --- .../applicationinsights/aiohttp/__init__.py | 0 .../aiohttp/aiohttp_telemetry_middleware.py | 24 +++++++++++++++++++ .../aiohttp/aiohttp_telemetry_processor.py | 22 +++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/__init__.py create mode 100644 libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py create mode 100644 libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_processor.py diff --git a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/__init__.py b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py new file mode 100644 index 000000000..4a9eaac92 --- /dev/null +++ b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py @@ -0,0 +1,24 @@ +from threading import current_thread +from aiohttp.web import middleware + +# Map of thread id => POST body text +_REQUEST_BODIES = {} + +def retrieve_aiohttp_body(): + """ retrieve_flask_body + Retrieve the POST body text from temporary cache. + The POST body corresponds with the thread id and should resides in + cache just for lifetime of request. + """ + result = _REQUEST_BODIES.pop(current_thread().ident, None) + return result + +@middleware +async def bot_telemetry_middleware(request, handler): + """Process the incoming Flask request.""" + if "application/json" in request.headers["Content-Type"]: + body = await request.json() + _REQUEST_BODIES[current_thread().ident] = body + + response = await handler(request) + return response diff --git a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_processor.py b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_processor.py new file mode 100644 index 000000000..be6439195 --- /dev/null +++ b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_processor.py @@ -0,0 +1,22 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +"""Telemetry processor for aiohttp.""" +import sys + +from ..processor.telemetry_processor import TelemetryProcessor +from .aiohttp_telemetry_middleware import retrieve_aiohttp_body + + +class AiohttpTelemetryProcessor(TelemetryProcessor): + def can_process(self) -> bool: + return self.detect_aiohttp() + + def get_request_body(self) -> str: + if self.detect_aiohttp(): + return retrieve_aiohttp_body() + return None + + @staticmethod + def detect_aiohttp() -> bool: + """Detects if running in aiohttp.""" + return "aiohttp" in sys.modules From c6457db20f0ab9f28f693803fd03512ae43c68c7 Mon Sep 17 00:00:00 2001 From: Axel Suarez Date: Thu, 16 Jan 2020 17:42:01 -0800 Subject: [PATCH 2/9] black: Initial version of aiohttp telemetry middleware --- .../applicationinsights/aiohttp/aiohttp_telemetry_middleware.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py index 4a9eaac92..acc0c69cc 100644 --- a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py +++ b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py @@ -4,6 +4,7 @@ # Map of thread id => POST body text _REQUEST_BODIES = {} + def retrieve_aiohttp_body(): """ retrieve_flask_body Retrieve the POST body text from temporary cache. @@ -13,6 +14,7 @@ def retrieve_aiohttp_body(): result = _REQUEST_BODIES.pop(current_thread().ident, None) return result + @middleware async def bot_telemetry_middleware(request, handler): """Process the incoming Flask request.""" From 24be56403e331a609560e0d1c77469156c54a087 Mon Sep 17 00:00:00 2001 From: Axel Suarez Date: Tue, 21 Jan 2020 18:46:24 -0800 Subject: [PATCH 3/9] created separate package --- .../README.rst | 87 +++++++++++++++++++ .../ext/aiohttp/__init__.py | 7 ++ .../applicationinsights/ext/aiohttp/about.py | 15 ++++ .../aiohttp/aiohttp_telemetry_middleware.py | 0 .../aiohttp/aiohttp_telemetry_processor.py | 0 .../setup.py | 57 ++++++++++++ .../test_aiohttp_telemetry_middleware.py | 8 ++ .../applicationinsights/aiohttp/__init__.py | 0 8 files changed, 174 insertions(+) create mode 100644 libraries/botbuilder-applicationinsights-ext-aiohttp/README.rst create mode 100644 libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/__init__.py create mode 100644 libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/about.py rename libraries/{botbuilder-applicationinsights/botbuilder/applicationinsights => botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext}/aiohttp/aiohttp_telemetry_middleware.py (100%) rename libraries/{botbuilder-applicationinsights/botbuilder/applicationinsights => botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext}/aiohttp/aiohttp_telemetry_processor.py (100%) create mode 100644 libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py create mode 100644 libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py delete mode 100644 libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/__init__.py diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/README.rst b/libraries/botbuilder-applicationinsights-ext-aiohttp/README.rst new file mode 100644 index 000000000..8479d7ea1 --- /dev/null +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/README.rst @@ -0,0 +1,87 @@ + +======================================================== +BotBuilder-ApplicationInsights SDK extension for aiohttp +======================================================== + +.. image:: https://fuselabs.visualstudio.com/SDK_v4/_apis/build/status/Python/SDK_v4-Python-CI?branchName=master + :target: https://fuselabs.visualstudio.com/SDK_v4/_apis/build/status/Python/SDK_v4-Python-CI + :align: right + :alt: Azure DevOps status for master branch +.. image:: https://badge.fury.io/py/botbuilder-applicationinsights.svg + :target: https://badge.fury.io/py/botbuilder-applicationinsights + :alt: Latest PyPI package version + +Within the Bot Framework, BotBuilder-ApplicationInsights enables the Azure Application Insights service. + +Application Insights is an extensible Application Performance Management (APM) service for developers on multiple platforms. +Use it to monitor your live bot application. It includes powerful analytics tools to help you diagnose issues and to understand +what users actually do with your bot. + +How to Install +============== + +.. code-block:: python + + pip install botbuilder-applicationinsights-aiohttp + + +Documentation/Wiki +================== + +You can find more information on the botbuilder-python project by visiting our `Wiki`_. + +Requirements +============ + +* `Python >= 3.7.0`_ + + +Source Code +=========== +The latest developer version is available in a github repository: +https://github.com/Microsoft/botbuilder-python/ + + +Contributing +============ + +This project welcomes contributions and suggestions. Most contributions require you to agree to a +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us +the rights to use your contribution. For details, visit https://cla.microsoft.com. + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide +a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions +provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the `Microsoft Open Source Code of Conduct`_. +For more information see the `Code of Conduct FAQ`_ or +contact `opencode@microsoft.com`_ with any additional questions or comments. + +Reporting Security Issues +========================= + +Security issues and bugs should be reported privately, via email, to the Microsoft Security +Response Center (MSRC) at `secure@microsoft.com`_. You should +receive a response within 24 hours. If for some reason you do not, please follow up via +email to ensure we received your original message. Further information, including the +`MSRC PGP`_ key, can be found in +the `Security TechCenter`_. + +License +======= + +Copyright (c) Microsoft Corporation. All rights reserved. + +Licensed under the MIT_ License. + +.. _Wiki: https://github.com/Microsoft/botbuilder-python/wiki +.. _Python >= 3.7.0: https://www.python.org/downloads/ +.. _MIT: https://github.com/Microsoft/vscode/blob/master/LICENSE.txt +.. _Microsoft Open Source Code of Conduct: https://opensource.microsoft.com/codeofconduct/ +.. _Code of Conduct FAQ: https://opensource.microsoft.com/codeofconduct/faq/ +.. _opencode@microsoft.com: mailto:opencode@microsoft.com +.. _secure@microsoft.com: mailto:secure@microsoft.com +.. _MSRC PGP: https://technet.microsoft.com/en-us/security/dn606155 +.. _Security TechCenter: https://github.com/Microsoft/vscode/blob/master/LICENSE.txt + +.. `_ \ No newline at end of file diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/__init__.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/__init__.py new file mode 100644 index 000000000..7dd6e6aa4 --- /dev/null +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/__init__.py @@ -0,0 +1,7 @@ +from .aiohttp_telemetry_middleware import bot_telemetry_middleware +from .aiohttp_telemetry_processor import AiohttpTelemetryProcessor + +__all__ = [ + "bot_telemetry_middleware", + "AiohttpTelemetryProcessor", +] diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/about.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/about.py new file mode 100644 index 000000000..b63d1ad95 --- /dev/null +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/about.py @@ -0,0 +1,15 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +"""Bot Framework Application Insights integration package for aiohttp library.""" + +import os + +__title__ = "botbuilder-applicationinsights-aiohttp" +__version__ = ( + os.environ["packageVersion"] if "packageVersion" in os.environ else "4.4.0b1" +) +__uri__ = "https://www.github.com/Microsoft/botbuilder-python" +__author__ = "Microsoft" +__description__ = "Microsoft Bot Framework Bot Builder" +__summary__ = "Microsoft Bot Framework Bot Builder SDK for Python." +__license__ = "MIT" diff --git a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_middleware.py similarity index 100% rename from libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py rename to libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_middleware.py diff --git a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_processor.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py similarity index 100% rename from libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/aiohttp_telemetry_processor.py rename to libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py new file mode 100644 index 000000000..9a8bd2486 --- /dev/null +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py @@ -0,0 +1,57 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import os +from setuptools import setup + +REQUIRES = [ + "applicationinsights>=0.11.9", + "botbuilder-schema>=4.4.0b1", + "botframework-connector>=4.4.0b1", + "botbuilder-core>=4.4.0b1", + "botbuilder-applicationinsights>=4.4.0b1", +] +TESTS_REQUIRES = [ + "aiounittest==1.3.0", + "aiohttp==3.5.4", +] + +root = os.path.abspath(os.path.dirname(__file__)) + +with open(os.path.join(root, "about.py")) as f: + package_info = {} + info = f.read() + exec(info, package_info) + +with open(os.path.join(root, "README.rst"), encoding="utf-8") as f: + long_description = f.read() + +setup( + name=package_info["__title__"], + version=package_info["__version__"], + url=package_info["__uri__"], + author=package_info["__author__"], + description=package_info["__description__"], + keywords=[ + "BotBuilderApplicationInsights", + "bots", + "ai", + "botframework", + "botbuilder", + "aiohttp", + ], + long_description=long_description, + long_description_content_type="text/x-rst", + license=package_info["__license__"], + install_requires=REQUIRES + TESTS_REQUIRES, + tests_require=TESTS_REQUIRES, + include_package_data=True, + classifiers=[ + "Programming Language :: Python :: 3.7", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Development Status :: 5 - Production/Stable", + "Topic :: Scientific/Engineering :: Artificial Intelligence", + ], +) diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py new file mode 100644 index 000000000..90807ee33 --- /dev/null +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py @@ -0,0 +1,8 @@ +from aiounittest import AsyncTestCase + +from botbuilder.applicationinsights.aiohttp import bot_telemetry_middleware + + +class TestAiohttpTelemetryMiddleware(AsyncTestCase): + async def test_bot_telemetry_middleware(self): + pass diff --git a/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/__init__.py b/libraries/botbuilder-applicationinsights/botbuilder/applicationinsights/aiohttp/__init__.py deleted file mode 100644 index e69de29bb..000000000 From 1ee1115f4a78d560df32b11f971eac6025c23cfe Mon Sep 17 00:00:00 2001 From: Axel Suarez Date: Tue, 21 Jan 2020 18:50:29 -0800 Subject: [PATCH 4/9] pylint: created separate package --- .../ext/aiohttp/aiohttp_telemetry_processor.py | 2 +- .../botbuilder-applicationinsights-ext-aiohttp/setup.py | 5 ++++- .../tests/test_aiohttp_telemetry_middleware.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py index be6439195..642e494b0 100644 --- a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py @@ -3,7 +3,7 @@ """Telemetry processor for aiohttp.""" import sys -from ..processor.telemetry_processor import TelemetryProcessor +from botbuilder.applicationinsights import TelemetryProcessor from .aiohttp_telemetry_middleware import retrieve_aiohttp_body diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py index 9a8bd2486..f163a5070 100644 --- a/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py @@ -18,7 +18,7 @@ root = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(root, "about.py")) as f: +with open(os.path.join(root, "botbuilder", "applicationinsights", "ext", "about.py")) as f: package_info = {} info = f.read() exec(info, package_info) @@ -43,6 +43,9 @@ long_description=long_description, long_description_content_type="text/x-rst", license=package_info["__license__"], + packages=[ + "botbuilder.applicationinsights.ext.aiohttp", + ], install_requires=REQUIRES + TESTS_REQUIRES, tests_require=TESTS_REQUIRES, include_package_data=True, diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py index 90807ee33..83da66492 100644 --- a/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py @@ -1,6 +1,6 @@ from aiounittest import AsyncTestCase -from botbuilder.applicationinsights.aiohttp import bot_telemetry_middleware +# from botbuilder.applicationinsights.aiohttp import bot_telemetry_middleware class TestAiohttpTelemetryMiddleware(AsyncTestCase): From 870fbca45c5808d6f393c8cf4f8352a23091e717 Mon Sep 17 00:00:00 2001 From: Axel Suarez Date: Tue, 21 Jan 2020 18:50:47 -0800 Subject: [PATCH 5/9] black: created separate package --- .../botbuilder-applicationinsights-ext-aiohttp/setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py index f163a5070..9084dfb6a 100644 --- a/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py +++ b/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py @@ -18,7 +18,9 @@ root = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(root, "botbuilder", "applicationinsights", "ext", "about.py")) as f: +with open( + os.path.join(root, "botbuilder", "applicationinsights", "ext", "about.py") +) as f: package_info = {} info = f.read() exec(info, package_info) @@ -43,9 +45,7 @@ long_description=long_description, long_description_content_type="text/x-rst", license=package_info["__license__"], - packages=[ - "botbuilder.applicationinsights.ext.aiohttp", - ], + packages=["botbuilder.applicationinsights.ext.aiohttp",], install_requires=REQUIRES + TESTS_REQUIRES, tests_require=TESTS_REQUIRES, include_package_data=True, From 3414486ee37f8f1a75c2554970314aba5d05d733 Mon Sep 17 00:00:00 2001 From: Axel Suarez Date: Wed, 22 Jan 2020 14:13:12 -0800 Subject: [PATCH 6/9] namespace renamed and tests added --- .../test_aiohttp_telemetry_middleware.py | 8 ----- .../README.rst | 0 .../applicationinsights}/aiohttp/__init__.py | 0 .../applicationinsights}/aiohttp/about.py | 2 +- .../aiohttp/aiohttp_telemetry_middleware.py | 0 .../aiohttp/aiohttp_telemetry_processor.py | 4 ++- .../setup.py | 6 ++-- .../tests/test_aiohttp_processor.py | 26 ++++++++++++++ .../test_aiohttp_telemetry_middleware.py | 35 +++++++++++++++++++ 9 files changed, 69 insertions(+), 12 deletions(-) delete mode 100644 libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py rename libraries/{botbuilder-applicationinsights-ext-aiohttp => botbuilder-integration-applicationinsights-aiohttp}/README.rst (100%) rename libraries/{botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext => botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights}/aiohttp/__init__.py (100%) rename libraries/{botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext => botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights}/aiohttp/about.py (86%) rename libraries/{botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext => botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights}/aiohttp/aiohttp_telemetry_middleware.py (100%) rename libraries/{botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext => botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights}/aiohttp/aiohttp_telemetry_processor.py (85%) rename libraries/{botbuilder-applicationinsights-ext-aiohttp => botbuilder-integration-applicationinsights-aiohttp}/setup.py (89%) create mode 100644 libraries/botbuilder-integration-applicationinsights-aiohttp/tests/test_aiohttp_processor.py create mode 100644 libraries/botbuilder-integration-applicationinsights-aiohttp/tests/test_aiohttp_telemetry_middleware.py diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py b/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py deleted file mode 100644 index 83da66492..000000000 --- a/libraries/botbuilder-applicationinsights-ext-aiohttp/tests/test_aiohttp_telemetry_middleware.py +++ /dev/null @@ -1,8 +0,0 @@ -from aiounittest import AsyncTestCase - -# from botbuilder.applicationinsights.aiohttp import bot_telemetry_middleware - - -class TestAiohttpTelemetryMiddleware(AsyncTestCase): - async def test_bot_telemetry_middleware(self): - pass diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/README.rst b/libraries/botbuilder-integration-applicationinsights-aiohttp/README.rst similarity index 100% rename from libraries/botbuilder-applicationinsights-ext-aiohttp/README.rst rename to libraries/botbuilder-integration-applicationinsights-aiohttp/README.rst diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/__init__.py b/libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/__init__.py similarity index 100% rename from libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/__init__.py rename to libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/__init__.py diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/about.py b/libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/about.py similarity index 86% rename from libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/about.py rename to libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/about.py index b63d1ad95..1fc4d035b 100644 --- a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/about.py +++ b/libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/about.py @@ -4,7 +4,7 @@ import os -__title__ = "botbuilder-applicationinsights-aiohttp" +__title__ = "botbuilder-integration-applicationinsights-aiohttp" __version__ = ( os.environ["packageVersion"] if "packageVersion" in os.environ else "4.4.0b1" ) diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_middleware.py b/libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py similarity index 100% rename from libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_middleware.py rename to libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/aiohttp_telemetry_middleware.py diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py b/libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/aiohttp_telemetry_processor.py similarity index 85% rename from libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py rename to libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/aiohttp_telemetry_processor.py index 642e494b0..2962a5fe8 100644 --- a/libraries/botbuilder-applicationinsights-ext-aiohttp/botbuilder/applicationinsights/ext/aiohttp/aiohttp_telemetry_processor.py +++ b/libraries/botbuilder-integration-applicationinsights-aiohttp/botbuilder/integration/applicationinsights/aiohttp/aiohttp_telemetry_processor.py @@ -3,7 +3,9 @@ """Telemetry processor for aiohttp.""" import sys -from botbuilder.applicationinsights import TelemetryProcessor +from botbuilder.applicationinsights.processor.telemetry_processor import ( + TelemetryProcessor, +) from .aiohttp_telemetry_middleware import retrieve_aiohttp_body diff --git a/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py b/libraries/botbuilder-integration-applicationinsights-aiohttp/setup.py similarity index 89% rename from libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py rename to libraries/botbuilder-integration-applicationinsights-aiohttp/setup.py index 9084dfb6a..28b8dd9bb 100644 --- a/libraries/botbuilder-applicationinsights-ext-aiohttp/setup.py +++ b/libraries/botbuilder-integration-applicationinsights-aiohttp/setup.py @@ -19,7 +19,9 @@ root = os.path.abspath(os.path.dirname(__file__)) with open( - os.path.join(root, "botbuilder", "applicationinsights", "ext", "about.py") + os.path.join( + root, "botbuilder", "integration", "applicationinsights", "aiohttp", "about.py" + ) ) as f: package_info = {} info = f.read() @@ -45,7 +47,7 @@ long_description=long_description, long_description_content_type="text/x-rst", license=package_info["__license__"], - packages=["botbuilder.applicationinsights.ext.aiohttp",], + packages=["botbuilder.integration.applicationinsights.aiohttp"], install_requires=REQUIRES + TESTS_REQUIRES, tests_require=TESTS_REQUIRES, include_package_data=True, diff --git a/libraries/botbuilder-integration-applicationinsights-aiohttp/tests/test_aiohttp_processor.py b/libraries/botbuilder-integration-applicationinsights-aiohttp/tests/test_aiohttp_processor.py new file mode 100644 index 000000000..37ca54267 --- /dev/null +++ b/libraries/botbuilder-integration-applicationinsights-aiohttp/tests/test_aiohttp_processor.py @@ -0,0 +1,26 @@ +from unittest.mock import Mock +from aiounittest import AsyncTestCase + +import aiohttp # pylint: disable=unused-import + +from botbuilder.integration.applicationinsights.aiohttp import ( + aiohttp_telemetry_middleware, + AiohttpTelemetryProcessor, +) + + +class TestAiohttpTelemetryProcessor(AsyncTestCase): + # pylint: disable=protected-access + def test_can_process(self): + assert AiohttpTelemetryProcessor.detect_aiohttp() + assert AiohttpTelemetryProcessor().can_process() + + def test_retrieve_aiohttp_body(self): + aiohttp_telemetry_middleware._REQUEST_BODIES = Mock() + aiohttp_telemetry_middleware._REQUEST_BODIES.pop = Mock( + return_value="test body" + ) + assert aiohttp_telemetry_middleware.retrieve_aiohttp_body() == "test body" + + assert AiohttpTelemetryProcessor().get_request_body() == "test body" + aiohttp_telemetry_middleware._REQUEST_BODIES = {} diff --git a/libraries/botbuilder-integration-applicationinsights-aiohttp/tests/test_aiohttp_telemetry_middleware.py b/libraries/botbuilder-integration-applicationinsights-aiohttp/tests/test_aiohttp_telemetry_middleware.py new file mode 100644 index 000000000..673040b4b --- /dev/null +++ b/libraries/botbuilder-integration-applicationinsights-aiohttp/tests/test_aiohttp_telemetry_middleware.py @@ -0,0 +1,35 @@ +from asyncio import Future +from unittest.mock import Mock, MagicMock +from aiounittest import AsyncTestCase + +from botbuilder.integration.applicationinsights.aiohttp import ( + bot_telemetry_middleware, + aiohttp_telemetry_middleware, +) + + +class TestAiohttpTelemetryMiddleware(AsyncTestCase): + # pylint: disable=protected-access + async def test_bot_telemetry_middleware(self): + req = Mock() + req.headers = {"Content-Type": "application/json"} + req.json = MagicMock(return_value=Future()) + req.json.return_value.set_result("mock body") + + async def handler(value): + return value + + sut = await bot_telemetry_middleware(req, handler) + + assert "mock body" in aiohttp_telemetry_middleware._REQUEST_BODIES.values() + aiohttp_telemetry_middleware._REQUEST_BODIES.clear() + assert req == sut + + def test_retrieve_aiohttp_body(self): + aiohttp_telemetry_middleware._REQUEST_BODIES = Mock() + aiohttp_telemetry_middleware._REQUEST_BODIES.pop = Mock( + return_value="test body" + ) + assert aiohttp_telemetry_middleware.retrieve_aiohttp_body() == "test body" + + aiohttp_telemetry_middleware._REQUEST_BODIES = {} From ada363bc79e894d3afebed0aec37e26577810f22 Mon Sep 17 00:00:00 2001 From: Axel Suarez Date: Thu, 23 Jan 2020 13:31:26 -0800 Subject: [PATCH 7/9] testing yaml pipeline --- ci-pr-pipeline.yml | 100 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 ci-pr-pipeline.yml diff --git a/ci-pr-pipeline.yml b/ci-pr-pipeline.yml new file mode 100644 index 000000000..b5b4b392a --- /dev/null +++ b/ci-pr-pipeline.yml @@ -0,0 +1,100 @@ +variables: + # Container registry service connection established during pipeline creation + CI_PULL_REQUEST: $(System.PullRequest.PullRequestId) + COVERALLS_FLAG_NAME: Build \# $(Build.BuildNumber) + COVERALLS_GIT_BRANCH: $(Build.SourceBranchName) + COVERALLS_GIT_COMMIT: $(Build.SourceVersion) + COVERALLS_TOKEN: Set this value later + COVERALLS_SERVICE_JOB_ID: $(Build.BuildId) + COVERALLS_SERVICE_NAME: python-ci + python.version: 3.7.6 + system.collectionId: ae8b0170-8c49-492d-afe5-8666d1955c7e + system.debug: false + system.definitionId: 431 + system.teamProject: SDK_v4 + + + + +jobs: +# Build and publish container +- job: Build +#Multi-configuration and multi-agent job options are not exported to YAML. Configure these options using documentation guidance: https://docs.microsoft.com/vsts/pipelines/process/phases + pool: + name: Hosted Ubuntu 1604 + #Your build pipeline references the ‘python.version’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971 + #Your build pipeline references the ‘python.version’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971 + + steps: + - powershell: | + Get-ChildItem env:* | sort-object name | Format-Table -Autosize -Wrap | Out-String -Width 120 + displayName: 'Get environment vars' + + - task: UsePythonVersion@0 + displayName: 'Use Python $(python.version)' + inputs: + versionSpec: '$(python.version)' + + - script: 'sudo ln -s /opt/hostedtoolcache/Python/3.6.9/x64/lib/libpython3.6m.so.1.0 /usr/lib/libpython3.6m.so' + displayName: libpython3.6m + + - script: | + python -m pip install --upgrade pip + pip install -e ./libraries/botbuilder-schema + pip install -e ./libraries/botframework-connector + pip install -e ./libraries/botbuilder-core + pip install -e ./libraries/botbuilder-ai + pip install -e ./libraries/botbuilder-applicationinsights + pip install -e ./libraries/botbuilder-dialogs + pip install -e ./libraries/botbuilder-azure + pip install -e ./libraries/botbuilder-testing + pip install -r ./libraries/botframework-connector/tests/requirements.txt + pip install -r ./libraries/botbuilder-core/tests/requirements.txt + pip install coveralls + pip install pylint + pip install black + displayName: 'Install dependencies' + + - script: 'pip install requests_mock' + displayName: 'Install requests mock (REMOVE AFTER MERGING INSPECTION)' + enabled: false + + - script: | + pip install pytest + pip install pytest-cov + pip install coveralls + pytest --junitxml=junit/test-results.xml --cov-config=.coveragerc --cov --cov-report=xml --cov-report=html + displayName: Pytest + + - script: 'black --check libraries' + displayName: 'Check Black compliant' + + - script: 'pylint --rcfile=.pylintrc libraries' + displayName: Pylint + + - task: PublishTestResults@2 + displayName: 'Publish Test Results **/test-results.xml' + inputs: + testResultsFiles: '**/test-results.xml' + testRunTitle: 'Python $(python.version)' + + - script: 'COVERALLS_REPO_TOKEN=$(COVERALLS_TOKEN) coveralls' + displayName: 'Push test results to coveralls https://coveralls.io/github/microsoft/botbuilder-python' + continueOnError: true + + - powershell: | + Set-Location .. + Get-ChildItem -Recurse -Force + + displayName: 'Dir workspace' + condition: succeededOrFailed() + + - powershell: | + # This task copies the code coverage file created by dotnet test into a well known location. In all + # checks I've done, dotnet test ALWAYS outputs the coverage file to the temp directory. + # My attempts to override this and have it go directly to the CodeCoverage directory have + # all failed, so I'm just doing the copy here. (cmullins) + + Get-ChildItem -Path "$(Build.SourcesDirectory)" -Include "*coverage*" | Copy-Item -Destination "$(Build.ArtifactStagingDirectory)/CodeCoverage" + displayName: 'Copy .coverage Files to CodeCoverage folder' + continueOnError: true From a28ec3094dc08cebc929286c0918e7c675aa7ad8 Mon Sep 17 00:00:00 2001 From: Axel Suarez Date: Thu, 23 Jan 2020 14:02:01 -0800 Subject: [PATCH 8/9] removing pipeline --- ci-pr-pipeline.yml | 100 --------------------------------------------- 1 file changed, 100 deletions(-) delete mode 100644 ci-pr-pipeline.yml diff --git a/ci-pr-pipeline.yml b/ci-pr-pipeline.yml deleted file mode 100644 index b5b4b392a..000000000 --- a/ci-pr-pipeline.yml +++ /dev/null @@ -1,100 +0,0 @@ -variables: - # Container registry service connection established during pipeline creation - CI_PULL_REQUEST: $(System.PullRequest.PullRequestId) - COVERALLS_FLAG_NAME: Build \# $(Build.BuildNumber) - COVERALLS_GIT_BRANCH: $(Build.SourceBranchName) - COVERALLS_GIT_COMMIT: $(Build.SourceVersion) - COVERALLS_TOKEN: Set this value later - COVERALLS_SERVICE_JOB_ID: $(Build.BuildId) - COVERALLS_SERVICE_NAME: python-ci - python.version: 3.7.6 - system.collectionId: ae8b0170-8c49-492d-afe5-8666d1955c7e - system.debug: false - system.definitionId: 431 - system.teamProject: SDK_v4 - - - - -jobs: -# Build and publish container -- job: Build -#Multi-configuration and multi-agent job options are not exported to YAML. Configure these options using documentation guidance: https://docs.microsoft.com/vsts/pipelines/process/phases - pool: - name: Hosted Ubuntu 1604 - #Your build pipeline references the ‘python.version’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971 - #Your build pipeline references the ‘python.version’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971 - - steps: - - powershell: | - Get-ChildItem env:* | sort-object name | Format-Table -Autosize -Wrap | Out-String -Width 120 - displayName: 'Get environment vars' - - - task: UsePythonVersion@0 - displayName: 'Use Python $(python.version)' - inputs: - versionSpec: '$(python.version)' - - - script: 'sudo ln -s /opt/hostedtoolcache/Python/3.6.9/x64/lib/libpython3.6m.so.1.0 /usr/lib/libpython3.6m.so' - displayName: libpython3.6m - - - script: | - python -m pip install --upgrade pip - pip install -e ./libraries/botbuilder-schema - pip install -e ./libraries/botframework-connector - pip install -e ./libraries/botbuilder-core - pip install -e ./libraries/botbuilder-ai - pip install -e ./libraries/botbuilder-applicationinsights - pip install -e ./libraries/botbuilder-dialogs - pip install -e ./libraries/botbuilder-azure - pip install -e ./libraries/botbuilder-testing - pip install -r ./libraries/botframework-connector/tests/requirements.txt - pip install -r ./libraries/botbuilder-core/tests/requirements.txt - pip install coveralls - pip install pylint - pip install black - displayName: 'Install dependencies' - - - script: 'pip install requests_mock' - displayName: 'Install requests mock (REMOVE AFTER MERGING INSPECTION)' - enabled: false - - - script: | - pip install pytest - pip install pytest-cov - pip install coveralls - pytest --junitxml=junit/test-results.xml --cov-config=.coveragerc --cov --cov-report=xml --cov-report=html - displayName: Pytest - - - script: 'black --check libraries' - displayName: 'Check Black compliant' - - - script: 'pylint --rcfile=.pylintrc libraries' - displayName: Pylint - - - task: PublishTestResults@2 - displayName: 'Publish Test Results **/test-results.xml' - inputs: - testResultsFiles: '**/test-results.xml' - testRunTitle: 'Python $(python.version)' - - - script: 'COVERALLS_REPO_TOKEN=$(COVERALLS_TOKEN) coveralls' - displayName: 'Push test results to coveralls https://coveralls.io/github/microsoft/botbuilder-python' - continueOnError: true - - - powershell: | - Set-Location .. - Get-ChildItem -Recurse -Force - - displayName: 'Dir workspace' - condition: succeededOrFailed() - - - powershell: | - # This task copies the code coverage file created by dotnet test into a well known location. In all - # checks I've done, dotnet test ALWAYS outputs the coverage file to the temp directory. - # My attempts to override this and have it go directly to the CodeCoverage directory have - # all failed, so I'm just doing the copy here. (cmullins) - - Get-ChildItem -Path "$(Build.SourcesDirectory)" -Include "*coverage*" | Copy-Item -Destination "$(Build.ArtifactStagingDirectory)/CodeCoverage" - displayName: 'Copy .coverage Files to CodeCoverage folder' - continueOnError: true From 61fa2c8dadeb21f585d25e7b0ac7fa60f291d398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20Su=C3=A1rez?= Date: Thu, 23 Jan 2020 14:50:46 -0800 Subject: [PATCH 9/9] Update ci-pr-pipeline.yml for Azure Pipelines Updating pipeline for new integration package (appinsights-aiohttp) --- ci-pr-pipeline.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ci-pr-pipeline.yml b/ci-pr-pipeline.yml index b97d5256f..13d622d1c 100644 --- a/ci-pr-pipeline.yml +++ b/ci-pr-pipeline.yml @@ -41,6 +41,7 @@ jobs: pip install -e ./libraries/botbuilder-dialogs pip install -e ./libraries/botbuilder-azure pip install -e ./libraries/botbuilder-testing + pip install -e ./libraries/botbuilder-integration-applicationinsights-aiohttp pip install -r ./libraries/botframework-connector/tests/requirements.txt pip install -r ./libraries/botbuilder-core/tests/requirements.txt pip install coveralls @@ -48,10 +49,6 @@ jobs: pip install black displayName: 'Install dependencies' - - script: 'pip install requests_mock' - displayName: 'Install requests mock (REMOVE AFTER MERGING INSPECTION)' - enabled: false - - script: | pip install pytest pip install pytest-cov