in src/distributedTracingManager.ts [136:167]
private async updateDeviceTwin(enable: boolean, samplingRate: number, iotHubConnectionString: string, deviceIds: string[]): Promise<any> {
const twinPatch = {
etag: "*",
properties: {
desired: {},
},
};
if (enable === undefined && samplingRate === undefined) {
return;
}
if (!twinPatch.properties.desired[Constants.DISTRIBUTED_TWIN_NAME]) {
twinPatch.properties.desired[Constants.DISTRIBUTED_TWIN_NAME] = {};
}
if (enable !== undefined) {
twinPatch.properties.desired[Constants.DISTRIBUTED_TWIN_NAME].sampling_mode = enable ? 1 : 2;
}
if (samplingRate !== undefined) {
twinPatch.properties.desired[Constants.DISTRIBUTED_TWIN_NAME].sampling_rate = samplingRate;
}
if (deviceIds.length === 1) {
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
await registry.updateTwin(deviceIds[0], JSON.stringify(twinPatch), twinPatch.etag);
return;
}
return this.scheduleTwinUpdate(twinPatch, iotHubConnectionString, deviceIds);
}