Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry/enable app insights [Finished #114911063] #33

Merged
merged 10 commits into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<Compile Include="azure\cli\_util.py" />
<Compile Include="azure\cli\__init__.py" />
<Compile Include="azure\cli\__main__.py" />
<Compile Include="azure\cli\_telemetry.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="azure\__init__.py" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
applicationinsights==0.10.0
azure==2.0.0rc1
mock==1.3.0
pylint==1.5.4
Expand Down
13 changes: 12 additions & 1 deletion src/azure/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@

import azure.cli.main

sys.exit(azure.cli.main.main(sys.argv[1:]))
from ._telemetry import init_telemetry, user_agrees_to_telemetry, telemetry_flush

try:
try:
if user_agrees_to_telemetry():
init_telemetry()
except Exception: #pylint: disable=broad-except
pass

sys.exit(azure.cli.main.main(sys.argv[1:]))
finally:
telemetry_flush()
34 changes: 34 additions & 0 deletions src/azure/cli/_telemetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import getpass
from applicationinsights import TelemetryClient
from applicationinsights.exceptions import enable
import azure.cli as cli

client = {}

def init_telemetry():
try:
instrumentation_key = 'eb6e9d3a-b6ee-41a6-804f-70e152fdfc36'

global client #pylint: disable=global-statement
client = TelemetryClient(instrumentation_key)

client.context.application.id = 'Azure CLI'
client.context.application.ver = cli.__version__
client.context.user.id = hash(getpass.getuser())

enable(instrumentation_key)
except Exception: #pylint: disable=broad-except
# Never fail the command because of telemetry
pass

def user_agrees_to_telemetry():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do a pivotal bug for this so that we can discuss and decide where this information should be persisted for the session. Perhaps a config.json like we have for Node CLI.

# TODO: agreement, needs to take Y/N from the command line
# and needs a "skip" param to not show (for scripts)
return True

def telemetry_flush():
try:
client.flush()
except Exception: #pylint: disable=broad-except
# Never fail the command because of telemetry
pass