Skip to content

Commit dfca354

Browse files
authored
Improvements in telemetry (#180)
***NO_CI***
1 parent faff7a3 commit dfca354

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

nanoFramework.Azure.Devices.Client/DeviceClient.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,7 @@ public bool Open()
222222
userName += $"&model-id={HttpUtility.UrlEncode(ModelId)}";
223223
}
224224

225-
// compose product info
226-
string productInfo = "nano;";
227-
productInfo += $"azrsdk{ThisAssembly.AssemblyInformationalVersion};";
228-
productInfo += $"{Runtime.Native.SystemInfo.TargetName}";
229-
230-
// add to user name
231-
userName += $"&DeviceClientType={HttpUtility.UrlEncode(productInfo)}";
225+
Helper.ComposeTelemetryInformation(ref userName);
232226

233227
// Now connect the device
234228
string key = _isCertificate ? _privateKey : Helper.GetSharedAccessSignature(null, _sasKey, $"{_iotHubName}/devices/{_deviceId}", new TimeSpan(24, 0, 0));

nanoFramework.Azure.Devices.Client/Helper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,16 @@ public static string GetSharedAccessSignature(string keyName, string sharedAcces
4343
HttpUtility.UrlEncode(expiry));
4444
}
4545
}
46+
47+
public static void ComposeTelemetryInformation(ref string userName)
48+
{
49+
// compose product info
50+
string productInfo = "nano;";
51+
productInfo += $"azrsdk{ThisAssembly.AssemblyVersion};";
52+
productInfo += $"{Runtime.Native.SystemInfo.TargetName}";
53+
54+
// add to user name
55+
userName += $"&DeviceClientType={HttpUtility.UrlEncode(productInfo)}";
56+
}
4657
}
4758
}

nanoFramework.Azure.Devices.Client/ProvisioningDeviceClient.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,18 @@ private ProvisioningDeviceClient(string globalDeviceEndpoint, string idScope, st
7676
deviceCert,
7777
MqttSslProtocols.TLSv1_2);
7878

79+
string userName = $"{idScope}/registrations/{_registrationId}/api-version=2019-03-31";
80+
81+
Helper.ComposeTelemetryInformation(ref userName);
82+
7983
// Handler for received messages on the subscribed topics
8084
_mqttc.MqttMsgPublishReceived += ClientMqttMsgReceived;
8185

8286
// Now connect the device
8387
string key = securityProvider != null ? Helper.GetSharedAccessSignature(null, securityProvider, $"{idScope}/registrations/{_registrationId}", new TimeSpan(24, 0, 0)) : string.Empty;
8488
_mqttc.Connect(
8589
_registrationId,
86-
$"{idScope}/registrations/{_registrationId}/api-version=2019-03-31",
90+
userName,
8791
key,
8892
false,
8993
MqttQoSLevel.ExactlyOnce,

0 commit comments

Comments
 (0)