-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add subscription id and resource name in telemetry (#231)
- Loading branch information
1 parent
a6f8a4e
commit 5a54a94
Showing
5 changed files
with
66 additions
and
6 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
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,39 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { AzExtTreeItem, ISubscriptionContext } from "@microsoft/vscode-azext-utils"; | ||
import * as assert from "assert"; | ||
import { TelemetryUtils } from "../../../utils/telemetryUtils"; | ||
|
||
class MockAzExtTreeItem extends AzExtTreeItem { | ||
public label: string; | ||
public contextValue: string; | ||
constructor(subscriptionContext: ISubscriptionContext) { | ||
super(undefined); | ||
this.label = 'mockLabel'; | ||
this.contextValue = 'mockContext'; | ||
this._subscription = subscriptionContext; | ||
} | ||
|
||
private _subscription: ISubscriptionContext; | ||
|
||
public get subscription(): ISubscriptionContext { | ||
return this._subscription; | ||
} | ||
} | ||
|
||
describe("telemetryUtils", () => { | ||
it("set Azure Resources Info", () => { | ||
const mockSubscriptionContext = { | ||
subscriptionId: "mockSubscriptionId", | ||
}; | ||
const mockItem = new MockAzExtTreeItem(mockSubscriptionContext as ISubscriptionContext); | ||
|
||
const properties: { [key: string]: string; } = {}; | ||
|
||
TelemetryUtils.setAzureResourcesInfo(properties, mockItem); | ||
|
||
assert.strictEqual(properties["subscriptionId"], "mockSubscriptionId"); | ||
assert.strictEqual(properties["resourceName"], "mockLabel"); | ||
}); | ||
}); |
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,18 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { AzExtTreeItem } from "@microsoft/vscode-azext-utils"; | ||
import { TelemetryProperties } from "../common/telemetryEvent"; | ||
|
||
export namespace TelemetryUtils { | ||
export function setAzureResourcesInfo(properties: { [key: string]: string; }, arg: any): void { | ||
if (arg && arg instanceof AzExtTreeItem) { | ||
if (arg.subscription.subscriptionId) { | ||
properties[TelemetryProperties.subscriptionId] = arg.subscription.subscriptionId; | ||
} | ||
if (arg.label) { | ||
properties[TelemetryProperties.resourceName] = arg.label; | ||
} | ||
} | ||
} | ||
} |