Skip to content

Commit 7f2327c

Browse files
committed
Add SDK metrics string into Connect packet
1 parent fd6a5d8 commit 7f2327c

File tree

8 files changed

+34
-1
lines changed

8 files changed

+34
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Primary aspects are:
2727

2828
For more information on the Architecture of the SDK refer [here](http://aws-iot-device-sdk-embedded-c-docs.s3-website-us-east-1.amazonaws.com/index.html)
2929

30+
## Collection of Metrics
31+
Beginning with Release v2.2.0 of the SDK, AWS collects usage metrics indicating which language and version of the SDK is being used. This allows us to prioritize our resources towards addressing issues faster in SDKs that see the most and is an important data point. However, we do understand that not all customers would want to report this data by default. In that case, the sending of usage metrics can be easily disabled by the user by setting the `DISABLE_METRICS` flag to true in the
32+
`aws_iot_config.h` for each application.
33+
3034
## How to get started ?
3135
Ensure you understand the AWS IoT platform and create the necessary certificates and policies. For more information on the AWS IoT platform please visit the [AWS IoT developer guide](http://docs.aws.amazon.com/iot/latest/developerguide/iot-security-identity.html).
3236

samples/linux/shadow_sample/aws_iot_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@
5353
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm
5454
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect.
5555

56+
#define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true
57+
5658
#endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */

samples/linux/shadow_sample_console_echo/aws_iot_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@
5353
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm
5454
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect.
5555

56+
#define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true
57+
5658
#endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */

samples/linux/subscribe_publish_cpp_sample/aws_iot_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@
5353
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm
5454
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect.
5555

56+
#define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true
57+
5658
#endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */

samples/linux/subscribe_publish_library_sample/aws_iot_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@
5353
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm
5454
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect.
5555

56+
#define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true
57+
5658
#endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */

samples/linux/subscribe_publish_sample/aws_iot_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@
5353
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm
5454
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect.
5555

56+
#define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true
57+
5658
#endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */

src/aws_iot_mqtt_client_connect.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@
3939
extern "C" {
4040
#endif
4141

42+
#include <stdio.h>
43+
4244
#include <aws_iot_mqtt_client.h>
4345
#include "aws_iot_mqtt_client_interface.h"
4446
#include "aws_iot_mqtt_client_common_internal.h"
47+
#include "aws_iot_version.h"
48+
49+
#if !DISABLE_METRICS
50+
#define SDK_METRICS_LEN 25
51+
#define SDK_METRICS_TEMPLATE "?SDK=C&Version=%d.%d.%d"
52+
#endif
4553

4654
typedef union {
4755
uint8_t all; /**< all connect flags */
@@ -456,7 +464,9 @@ static IoT_Error_t _aws_iot_mqtt_internal_connect(AWS_IoT_Client *pClient, IoT_C
456464
IoT_Error_t aws_iot_mqtt_connect(AWS_IoT_Client *pClient, IoT_Client_Connect_Params *pConnectParams) {
457465
IoT_Error_t rc, disconRc;
458466
ClientState clientState;
459-
467+
#if !DISABLE_METRICS
468+
char pUsernameTemp[SDK_METRICS_LEN] = {0};
469+
#endif
460470
FUNC_ENTRY;
461471

462472
if(NULL == pClient) {
@@ -473,6 +483,13 @@ IoT_Error_t aws_iot_mqtt_connect(AWS_IoT_Client *pClient, IoT_Client_Connect_Par
473483

474484
aws_iot_mqtt_set_client_state(pClient, clientState, CLIENT_STATE_CONNECTING);
475485

486+
#if !DISABLE_METRICS
487+
if (NULL != pConnectParams) {
488+
pConnectParams->usernameLen = snprintf(pUsernameTemp, SDK_METRICS_LEN, SDK_METRICS_TEMPLATE, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
489+
pConnectParams->pUsername = (char*)&pUsernameTemp;
490+
}
491+
#endif
492+
476493
rc = _aws_iot_mqtt_internal_connect(pClient, pConnectParams);
477494

478495
if(SUCCESS != rc) {

tests/integration/include/aws_iot_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@
4848
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm
4949
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect.
5050

51+
#define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true
52+
5153
#endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */

0 commit comments

Comments
 (0)