Skip to content

Commit

Permalink
log heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
zeusongit committed Dec 4, 2023
1 parent cd1c4f9 commit 5135512
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/DynamoCore/Logging/DynamoAnalyticsClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Autodesk.Analytics.ADP;
Expand Down Expand Up @@ -258,6 +259,28 @@ public void TrackScreenView(string viewName)
}
});
}
/// <summary>
/// This API is used to track user/machine's activity status.
/// </summary>
/// <param name="activityType">Value must be either machine or user. If no value is provided the API will default to user activity type.</param>
public void TrackActivityStatus(string activityType)
{
if (Analytics.DisableAnalytics) return;

Task.Run(() =>
{
serviceInitialized.Wait();

lock (trackEventLockObj)
{
if (!ReportingAnalytics) return;

var hbType = (new[] { "machine", "user" }).Contains(activityType?.ToLower()) ? activityType : "user";
var e = new HeartBeatEvent(activityType);
e.Track();
}
});
}

public void TrackException(Exception ex, bool isFatal)
{
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/StateMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Notes;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.Nodes;
using Dynamo.Selection;
Expand Down Expand Up @@ -626,6 +627,7 @@ private void SetCurrentState(State newState)

internal bool HandleLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Analytics.TrackActivityStatus(HeartBeatType.User.ToString());
if (ignoreMouseClick)
{
ignoreMouseClick = false;
Expand Down
9 changes: 9 additions & 0 deletions src/NodeServices/Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public static void TrackScreenView(string viewName)
if (client != null) client.TrackScreenView(viewName);
}

/// <summary>
/// Tracks user/machine idle and active states while using the application.
/// </summary>
/// <param name="activityType">Defines the activity type i.e: machine or user</param>
public static void TrackActivityStatus(string activityType)
{
if (client != null) client.TrackActivityStatus(activityType);
}

/// <summary>
/// Tracks an exception. If the exception is fatal, its recorded as crash.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/NodeServices/IAnalyticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ public enum Actions
Export
}

public enum HeartBeatType
{
User,
Machine
}

/// <summary>
/// Implements analytics and logging functions. This interface is defined
/// for internal use only to implement analytics functions and mock the tests.
Expand Down Expand Up @@ -506,6 +512,13 @@ public interface IAnalyticsClient
/// <param name="isFatal">If it's fatal</param>
void TrackException(Exception ex, bool isFatal);

/// <summary>
/// This API is used to track user/machine's activity status.
/// </summary>
/// <param name="activityType">Value must be: machine or user. If no value is provided the API will default to user activity type.</param>
/// <returns>0 if successful, otherwise returns an error code.</returns>
void TrackActivityStatus(string activityType);

/// <summary>
/// Creates a new timed event with start state and tracks its start.
/// Disposing the returnd event will record the event completion.
Expand Down

0 comments on commit 5135512

Please sign in to comment.