Initial telemetry hookup (works on wire, not working server-side)

This commit is contained in:
Burt Bielicki 2016-03-03 10:17:34 -08:00
Родитель 2a60c963a1
Коммит 79b9830f86
5 изменённых файлов: 74 добавлений и 2 удалений

Просмотреть файл

@ -12,8 +12,10 @@
<OutputPath>.</OutputPath> <OutputPath>.</OutputPath>
<ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids> <ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<LaunchProvider>Standard Python launcher</LaunchProvider> <LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId>{4ae3497d-f45c-4ec2-9e26-57476ef276a0}</InterpreterId> <InterpreterId>{153669af-0334-46c7-a6f1-029c48dc84d1}</InterpreterId>
<InterpreterVersion>3.5</InterpreterVersion> <InterpreterVersion>2.7</InterpreterVersion>
<CommandLineArguments>storage account list</CommandLineArguments>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" /> <PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" /> <PropertyGroup Condition="'$(Configuration)' == 'Release'" />
@ -25,7 +27,12 @@
<Compile Include="azure\cli\commands\account.py" /> <Compile Include="azure\cli\commands\account.py" />
<Compile Include="azure\cli\commands\login.py" /> <Compile Include="azure\cli\commands\login.py" />
<Compile Include="azure\cli\commands\logout.py" /> <Compile Include="azure\cli\commands\logout.py" />
<Compile Include="azure\cli\commands\network.py" />
<Compile Include="azure\cli\commands\resourcegroup.py" />
<Compile Include="azure\cli\commands\storage.py" /> <Compile Include="azure\cli\commands\storage.py" />
<Compile Include="azure\cli\commands\vm.py" />
<Compile Include="azure\cli\commands\_auto_command.py" />
<Compile Include="azure\cli\commands\_command_creation.py" />
<Compile Include="azure\cli\commands\__init__.py" /> <Compile Include="azure\cli\commands\__init__.py" />
<Compile Include="azure\cli\main.py" /> <Compile Include="azure\cli\main.py" />
<Compile Include="azure\cli\tests\test_argparse.py"> <Compile Include="azure\cli\tests\test_argparse.py">
@ -45,6 +52,9 @@
<Compile Include="azure\cli\_util.py" /> <Compile Include="azure\cli\_util.py" />
<Compile Include="azure\cli\__init__.py" /> <Compile Include="azure\cli\__init__.py" />
<Compile Include="azure\cli\__main__.py" /> <Compile Include="azure\cli\__main__.py" />
<Compile Include="azure\cli\_telemetry.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\__init__.py" /> <Compile Include="azure\__init__.py" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -54,6 +64,17 @@
<Folder Include="azure\cli\tests\" /> <Folder Include="azure\cli\tests\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Interpreter Include="..\..\Temp\burt\env27AppInsights\">
<Id>{153669af-0334-46c7-a6f1-029c48dc84d1}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
<Version>2.7</Version>
<Description>env27AppInsights (Python 2.7)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<LibraryPath>Lib\</LibraryPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture>
</Interpreter>
<Interpreter Include="..\..\Temp\burt\env27b\"> <Interpreter Include="..\..\Temp\burt\env27b\">
<Id>{83c20e12-84e3-4c10-a1ba-466d2b57483d}</Id> <Id>{83c20e12-84e3-4c10-a1ba-466d2b57483d}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter> <BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
@ -65,6 +86,17 @@
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable> <PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture> <Architecture>X86</Architecture>
</Interpreter> </Interpreter>
<Interpreter Include="..\..\Temp\burt\env35AppInsights\">
<Id>{12627503-1b89-4332-94a5-8ddd298e66ac}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
<Version>3.5</Version>
<Description>env35AppInsights (Python 3.5)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<LibraryPath>Lib\</LibraryPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture>
</Interpreter>
<Interpreter Include="..\..\Temp\burt\env35d\"> <Interpreter Include="..\..\Temp\burt\env35d\">
<Id>{4ae3497d-f45c-4ec2-9e26-57476ef276a0}</Id> <Id>{4ae3497d-f45c-4ec2-9e26-57476ef276a0}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter> <BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>

Просмотреть файл

@ -1,3 +1,4 @@
azure==2.0.0a1 azure==2.0.0a1
mock==1.3.0 mock==1.3.0
pylint==1.5.4 pylint==1.5.4
applicationinsights=0.10.0

Просмотреть файл

@ -3,6 +3,7 @@ import sys
from ._locale import L, get_file as locale_get_file from ._locale import L, get_file as locale_get_file
from ._logging import logger from ._logging import logger
from ._telemetry import telemetry_log_event
# Named arguments are prefixed with one of these strings # Named arguments are prefixed with one of these strings
ARG_PREFIXES = sorted(('-', '--', '/'), key=len, reverse=True) ARG_PREFIXES = sorted(('-', '--', '/'), key=len, reverse=True)
@ -222,6 +223,11 @@ class ArgumentParser(object):
old_stdout = sys.stdout old_stdout = sys.stdout
try: try:
sys.stdout = out sys.stdout = out
try:
telemetry_log_event("Command Executing", {"CommandName": handler.__name__})
except Exception(e):
#pass
raise e
return handler(parsed, others) return handler(parsed, others)
except IncorrectUsageError as ex: except IncorrectUsageError as ex:
print(str(ex), file=out) print(str(ex), file=out)

Просмотреть файл

@ -0,0 +1,29 @@
from applicationinsights import TelemetryClient
from applicationinsights.exceptions import enable
import azure.cli as cli
# event, exception, Trace, metric, message
class Telemetry(object): # pylint:disable=too-few-public-methods
client = None
@staticmethod
def init_telemetry():
instrumentation_key = 'eb6e9d3a-b6ee-41a6-804f-70e152fdfc36'
Telemetry.client = TelemetryClient(instrumentation_key)
Telemetry.client.context.application.id = 'Azure CLI'
Telemetry.client.context.application.ver = cli.__version__
#Telemetry.client.context.user.id = TODO: get user ID somehow or does AI do it server-side?
enable(instrumentation_key)
def user_agrees_to_telemetry():
# TODO: agreement
return True
def telemetry_log_event(name, properties=None, measurements=None):
Telemetry.client.track_event(name, properties, measurements)
Telemetry.client.flush()

Просмотреть файл

@ -4,6 +4,7 @@ from ._argparse import ArgumentParser
from ._logging import configure_logging, logger from ._logging import configure_logging, logger
from ._session import Session from ._session import Session
from ._output import OutputProducer from ._output import OutputProducer
from ._telemetry import Telemetry, user_agrees_to_telemetry
# CONFIG provides external configuration options # CONFIG provides external configuration options
CONFIG = Session() CONFIG = Session()
@ -17,6 +18,9 @@ def main(args):
configure_logging(args, CONFIG) configure_logging(args, CONFIG)
if user_agrees_to_telemetry():
Telemetry.init_telemetry()
from ._locale import install as locale_install from ._locale import install as locale_install
locale_install(os.path.join(os.path.dirname(os.path.abspath(__file__)), locale_install(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'locale', 'locale',