Skip to content

Commit

Permalink
grasshopper workspace id tracking (#3653)
Browse files Browse the repository at this point in the history
* grasshopper workspace id tracking

* formatting
  • Loading branch information
JR-Morgan authored Nov 5, 2024
1 parent 407022b commit af1b479
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public ComponentTracker(GH_Component parent)
Parent = parent;
}

private static void AppendHostAppInfoToProperties(Dictionary<string, object> properties)
private static void AppendHostAppInfoToProperties(Dictionary<string, object?> properties)
{
properties["hostAppVersion"] = Loader.GetGrasshopperHostAppVersion();
properties["hostApp"] = HostApplications.Grasshopper.Slug;
}

public void TrackEvent(Speckle.Core.Logging.Analytics.Events eventName, Dictionary<string, object> properties)
public void TrackEvent(Speckle.Core.Logging.Analytics.Events eventName, Dictionary<string, object?> properties)
{
AppendHostAppInfoToProperties(properties);
Speckle.Core.Logging.Analytics.TrackEvent(eventName, properties);
Expand All @@ -44,9 +44,9 @@ public void TrackNodeRun(string? name = null, string? node = null)
Speckle.Core.Logging.Analytics.TrackEvent(Speckle.Core.Logging.Analytics.Events.NodeRun, customProperties);
}

public void TrackNodeSend(Account acc, bool auto, bool sync = false)
public void TrackNodeSend(Account acc, bool auto, string? workspaceId, bool sync = false)
{
var customProperties = new Dictionary<string, object>();
var customProperties = new Dictionary<string, object>() { { "workspace_id", workspaceId } };
if (auto)
{
customProperties.Add("auto", auto);
Expand All @@ -61,14 +61,15 @@ public void TrackNodeSend(Account acc, bool auto, bool sync = false)
Speckle.Core.Logging.Analytics.TrackEvent(acc, Speckle.Core.Logging.Analytics.Events.Send, customProperties);
}

public void TrackNodeReceive(Account acc, bool auto, bool isMultiplayer, string sourceHostApp)
public void TrackNodeReceive(Account acc, bool auto, bool isMultiplayer, string sourceHostApp, string? workspaceId)
{
var properties = new Dictionary<string, object>
var properties = new Dictionary<string, object?>
{
{ "auto", auto },
{ "isMultiplayer", isMultiplayer },
{ "sourceHostApp", HostApplications.GetHostAppFromString(sourceHostApp).Slug },
{ "sourceHostAppVersion", sourceHostApp },
{ "workspace_id", workspaceId },
};
AppendHostAppInfoToProperties(properties);
Speckle.Core.Logging.Analytics.TrackEvent(acc, Speckle.Core.Logging.Analytics.Events.Receive, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ public override void DoWork(Action<string, double> ReportProgress, Action Done)
Done();
return;
}
receiveComponent.Tracker.TrackNodeSend(client.Account, receiveComponent.AutoReceive);

receiveComponent.Tracker.TrackNodeSend(client.Account, receiveComponent.AutoReceive, null);

var remoteTransport = new ServerTransport(InputWrapper?.GetAccount().Result, InputWrapper?.StreamId);
remoteTransport.TransportName = "R";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public override void DoWork(Action<string, double> ReportProgress, Action Done)
continue;
}

sendComponent.Tracker.TrackNodeSend(acc, sendComponent.AutoSend);
sendComponent.Tracker.TrackNodeSend(acc, sendComponent.AutoSend, null);

var serverTransport = new ServerTransport(acc, sw.StreamId) { TransportName = $"T{t}" };
transportBranches.Add(serverTransport, sw.BranchName ?? "main");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public override void DoWork(Action<string, double> ReportProgress, Action Done)
transportBranches.Add(serverTransport, sw.BranchName ?? "main");
Transports.Add(serverTransport);

sendComponent.Tracker.TrackNodeSend(acc, sendComponent.AutoSend);
sendComponent.Tracker.TrackNodeSend(acc, sendComponent.AutoSend, null);
}
else if (transport is ITransport otherTransport)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,15 @@ public override void SolveInstanceWithLogContext(IGH_DataAccess DA)
return null;
}

Tracker.TrackNodeReceive(acc, AutoReceive, myCommit.authorId != acc.userInfo.id, myCommit.sourceApplication);
var workspaceId = await client.GetWorkspaceId(StreamWrapper.StreamId).ConfigureAwait(false);

Tracker.TrackNodeReceive(
acc,
AutoReceive,
myCommit.authorId != acc.userInfo.id,
myCommit.sourceApplication,
workspaceId
);

var totalObjectCount = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,14 @@ public override void DoWork(Action<string, double> ReportProgress, Action Done)
}

ReceivedCommit = myCommit;
var workspaceId = await receiveComponent.ApiClient.GetWorkspaceId(InputWrapper.StreamId).ConfigureAwait(false);

receiveComponent.Tracker.TrackNodeReceive(
acc,
receiveComponent.AutoReceive,
myCommit.authorId != acc.userInfo.id,
myCommit.sourceApplication
myCommit.sourceApplication,
workspaceId
);

if (CancellationToken.IsCancellationRequested)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,10 @@ public override void DoWork(Action<string, double> ReportProgress, Action Done)
transportBranches.Add(serverTransport, sw.BranchName ?? "main");
Transports.Add(serverTransport);

sendComponent.Tracker.TrackNodeSend(acc, sendComponent.AutoSend);
using Client c = new(acc);
var workspaceId = c.GetWorkspaceId(sw.StreamId).Result;

sendComponent.Tracker.TrackNodeSend(acc, sendComponent.AutoSend, workspaceId);
}
else if (transport is ITransport otherTransport)
{
Expand Down

0 comments on commit af1b479

Please sign in to comment.