-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement telemetry for commands (#84)
* lsClient has been remove from webview. clean up Signed-off-by: Nok <[email protected]> * add consent script Signed-off-by: Nok Lam Chan <[email protected]> * Install requirements from viz, telemetry separately Signed-off-by: Nok Lam Chan <[email protected]> * Refactor globalState into constants to have one place to keep track of all the globalstate we used Signed-off-by: Nok Lam Chan <[email protected]> * fixing telemetry schema Signed-off-by: Nok Lam Chan <[email protected]> * send telemetry Signed-off-by: Nok Lam Chan <[email protected]> * remove unused import Signed-off-by: Nok Lam Chan <[email protected]> * update version Signed-off-by: Nok Lam Chan <[email protected]> * remove true in logging, bug fix Signed-off-by: Nok Lam Chan <[email protected]> * bug fix - should use telemetry requirements file Signed-off-by: Nok Lam Chan <[email protected]> * bug fix -passing wrong parameters Signed-off-by: Nok Lam Chan <[email protected]> * bug fix Signed-off-by: Nok Lam Chan <[email protected]> * Properties Map to object Signed-off-by: Jitendra Gundaniya <[email protected]> * Update bundled/tool/check_consent.py Co-authored-by: Jitendra Gundaniya <[email protected]> * Update schema Signed-off-by: Nok Lam Chan <[email protected]> * fix telemetry schema Signed-off-by: Nok Lam Chan <[email protected]> * format & missing imports Signed-off-by: Nok Lam Chan <[email protected]> * fix consent check Signed-off-by: Nok Lam Chan <[email protected]> --------- Signed-off-by: Nok <[email protected]> Signed-off-by: Nok Lam Chan <[email protected]> Signed-off-by: Jitendra Gundaniya <[email protected]> Co-authored-by: Jitendra Gundaniya <[email protected]> Co-authored-by: Jitendra Gundaniya <[email protected]>
- Loading branch information
1 parent
4ed8552
commit a573818
Showing
12 changed files
with
272 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from common import update_sys_path | ||
from pathlib import Path | ||
import os | ||
import sys | ||
import json | ||
|
||
update_sys_path( | ||
os.fspath(Path(__file__).parent.parent / "libs"), | ||
os.getenv("LS_IMPORT_STRATEGY", "useBundled"), | ||
) | ||
|
||
# important to keep this after sys.path is updated | ||
from kedro_telemetry.plugin import _check_for_telemetry_consent | ||
from kedro_telemetry.plugin import ( | ||
_get_project_properties, | ||
_get_or_create_uuid, | ||
) | ||
|
||
if __name__ == "__main__": | ||
from pathlib import Path | ||
import sys | ||
|
||
if len(sys.argv) > 1: | ||
project_path = Path(sys.argv[1]) | ||
else: | ||
project_path = Path.cwd() | ||
consent = _check_for_telemetry_consent(project_path) | ||
|
||
# Project Metadata | ||
|
||
user_uuid = _get_or_create_uuid() | ||
properties = _get_project_properties(user_uuid, project_path) | ||
# Extension will parse this message | ||
properties["consent"] = consent | ||
print("telemetry consent: ", end="") | ||
# It is important to use json.dump, if the message is printed together Python | ||
# convert it to single quote and the result is no longer valid JSON. The message | ||
# will be parsed by the extension client. | ||
result = json.dump(properties, sys.stdout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
def install_dependencies(extension_root_dir): | ||
""" | ||
Install dependencies required for the Kedro extension. | ||
Args: | ||
extension_root_dir (str): The root directory of the extension. | ||
Raises: | ||
ImportError: If the required dependencies are not found. | ||
""" | ||
... | ||
libs_path = Path(extension_root_dir) / "bundled" / "libs" | ||
requirements_path = Path(extension_root_dir) / "kedro-telemetry-requirements.txt" | ||
|
||
try: | ||
import kedro_telemetry | ||
from packaging.version import parse | ||
|
||
version = parse(kedro_telemetry.__version__) | ||
if version.major<1 and version.minor<6: # at least >0.6.0 | ||
raise ImportError("kedro-telemetry version must be >=0.6.0") | ||
except ImportError: | ||
subprocess.check_call( | ||
[ | ||
sys.executable, | ||
"-m", | ||
"pip", | ||
"install", | ||
"-r", | ||
Path(requirements_path), | ||
"-t", | ||
Path(libs_path), | ||
"--no-cache-dir", | ||
"--no-deps" | ||
] | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) > 1: | ||
extension_root_dir = sys.argv[1] | ||
else: | ||
extension_root_dir = None | ||
install_dependencies(extension_root_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
packaging | ||
kedro-telemetry>=0.6.0 # First version that does not prompt for telemetry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fastapi>=0.100.0,<0.200.0 | ||
pydantic>=2.0.0 # In case of FastAPI installs pydantic==1 | ||
orjson>=3.9, <4.0 | ||
orjson>=3.9, <4.0 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import axios from 'axios'; | ||
|
||
// from kedro_telemetry.plugin | ||
interface HeapData { | ||
app_id: string; | ||
event: string; | ||
timestamp: string; | ||
properties: any; | ||
identity?: string; | ||
} | ||
|
||
const HEAP_APPID_PROD = '4039408868'; // todo: Dev server, change it back to prod | ||
const HEAP_ENDPOINT = 'https://heapanalytics.com/api/track'; | ||
const HEAP_HEADERS = { 'Content-Type': 'application/json' }; | ||
|
||
export async function sendHeapEvent(commandName: string, properties?: any, identity?: string): Promise<void> { | ||
var telemetryData; | ||
const eventName = "Kedro VSCode Command"; | ||
|
||
if (properties) { | ||
telemetryData = { ...properties }; | ||
telemetryData["command_name"] = commandName; | ||
} | ||
|
||
|
||
const data: HeapData = { | ||
app_id: HEAP_APPID_PROD, | ||
event: eventName, | ||
timestamp: new Date().toISOString(), | ||
properties: telemetryData || {}, | ||
}; | ||
|
||
if (identity) { | ||
data.identity = identity; | ||
} | ||
|
||
try { | ||
const response = await axios.post(HEAP_ENDPOINT, data, { | ||
headers: HEAP_HEADERS, | ||
timeout: 10000, // 10 seconds | ||
}); | ||
|
||
// Handle the response if needed | ||
console.log('Heap event sent successfully:', response.status); | ||
} catch (error) { | ||
console.error('Error sending Heap event:', error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.