Skip to content

Commit

Permalink
Added default user to telemetry
Browse files Browse the repository at this point in the history
This will provide a username when UIControlledApplication or ControlledApplication is the only
handle provided by Revit API. These two don't have any user information
  • Loading branch information
eirannejad committed Jun 30, 2023
1 parent efa8423 commit ffffa6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 3 additions & 1 deletion pyrevitlib/pyrevit/runtime/EventTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public class EventTelemetry : IEventTypeHandler {
private static EventTelemetryExternalEventHandler extTelemetryEventHandler;
private static ExternalEvent extTelemetryEvent;

public EventTelemetry(string handlerId) {
public EventTelemetry(string handlerId, string username) {
if (handlerId == null)
handlerId = Guid.NewGuid().ToString();
HandlerId = handlerId;
extTelemetryEventHandler = new EventTelemetryExternalEventHandler();
extTelemetryEvent = ExternalEvent.Create(extTelemetryEventHandler);

Telemetry.DefaultUser = username;
}

public static string GetParameterValue(Parameter param) {
Expand Down
14 changes: 6 additions & 8 deletions pyrevitlib/pyrevit/runtime/telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public TelemetryRecord() {

public static class Telemetry {
private static string _exeBuild = null;


public static string DefaultUser { get; set; } = string.Empty;

public static string SerializeTelemetryRecord(object telemetryRecord) {
return JsonConvert.SerializeObject(telemetryRecord);
}
Expand Down Expand Up @@ -91,19 +93,15 @@ private static string GetISOTimeStamp(DateTime dtimeValue) {
}

public static string GetRevitUser(object source) {
string username = string.Empty;

switch (source) {
case UIApplication uiapp:
username = uiapp.Application.Username;
break;
return uiapp.Application.Username;

case Application app:
username = app.Username;
break;
return app.Username;
}

return username;
return DefaultUser;
}

public static string GetRevitVersion(object source) {
Expand Down
2 changes: 1 addition & 1 deletion pyrevitlib/pyrevit/telemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def setup_telemetry(session_id=None):
set_apptelemetry_server_url(apptelemetry_server_url)

# setup events
new_telemetry_handler = EventTelemetry(session_id)
new_telemetry_handler = EventTelemetry(session_id, HOST_APP.username)
telemetry_handler = get_apptelemetry_handler()
if telemetry_handler:
# clear existing
Expand Down

0 comments on commit ffffa6d

Please sign in to comment.