in src/distributedTracingManager.ts [49:134]
public async updateDistributedTracingSettingForDevices(deviceIds: string[], iotHubConnectionString: string, updateType: DistributedSettingUpdateType, node) {
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
let mode: boolean;
let samplingRate: number;
let twin;
if (deviceIds.length === 1) {
await vscode.window.withProgress({
title: `Get Current Distributed Tracing Setting`,
location: vscode.ProgressLocation.Notification,
}, async () => {
twin = await Utility.getTwin(registry, deviceIds[0]);
if (twin.properties.desired[Constants.DISTRIBUTED_TWIN_NAME]) {
mode = Utility.parseDesiredSamplingMode(twin);
samplingRate = Utility.parseDesiredSamplingRate(twin);
}
if (updateType === DistributedSettingUpdateType.OnlySamplingRate) {
mode = undefined;
}
if (updateType === DistributedSettingUpdateType.OnlyMode) {
samplingRate = undefined;
}
});
}
if (updateType !== DistributedSettingUpdateType.OnlySamplingRate) {
const selectedItem: SamplingModeItem = await vscode.window.showQuickPick(
this.getSamplingModePickupItems(),
{ placeHolder: "Select whether to enable/disable the distributed tracing...", ignoreFocusOut: true },
);
if (!selectedItem) {
return;
}
mode = selectedItem.distributedTracingEnabled;
}
if (updateType !== DistributedSettingUpdateType.OnlyMode) {
if (mode !== false) {
samplingRate = await this.promptForSamplingRate(`Enter sampling rate, integer within [0, 100]`, samplingRate);
if (samplingRate === undefined) {
return;
}
}
}
await vscode.window.withProgress({
title: `Update Distributed Tracing Setting`,
location: vscode.ProgressLocation.Notification,
}, async () => {
try {
const result = await this.updateDeviceTwin(mode, samplingRate, iotHubConnectionString, deviceIds);
TelemetryClient.sendEvent(Constants.IoTHubAIUpdateDistributedSettingDoneEvent,
{ Result: "Success", UpdateType: updateType.toString(), DeviceCount: deviceIds.length.toString(),
SamplingRate: samplingRate ? samplingRate.toString() : "" , SamplingMode: mode ? mode.toString() : "" }, iotHubConnectionString);
let resultTip = "";
if (result) {
resultTip = "\nDetailed information are shown as below:\n" + JSON.stringify(result, null, 2);
}
this._outputChannel.show();
this.outputLine(Constants.IoTHubDistributedTracingSettingLabel,
`Update distributed tracing setting for device [${deviceIds.join(",")}] complete!` +
(mode === true ? " (Distributed Tracing is in public preview stage and is available only in some regions, please check detail https://aka.ms/iottracing)" : "")
+ resultTip);
if (node instanceof DistributedTracingLabelNode) {
vscode.commands.executeCommand("azure-iot-toolkit.refresh", node);
} else if (node instanceof DistributedTracingSettingNode) {
vscode.commands.executeCommand("azure-iot-toolkit.refresh", node.parent);
} else {
vscode.commands.executeCommand("azure-iot-toolkit.refresh");
}
} catch (err) {
TelemetryClient.sendEvent(Constants.IoTHubAIUpdateDistributedSettingDoneEvent,
{ Result: "Fail", UpdateType: updateType.toString(), DeviceCount: deviceIds.length.toString(),
SamplingRate: samplingRate ? "" : samplingRate.toString(), SamplingMode: mode ? "" : mode.toString() }, iotHubConnectionString);
this._outputChannel.show();
this.outputLine(Constants.IoTHubDistributedTracingSettingLabel, `Failed to get or update distributed setting: ${err.message}`);
}
});
}