private RaygunIdentifierMessage BuildRaygunIdentifierMessage(string machineName) { RaygunIdentifierMessage message = UserInfo; string deviceId = DeviceId; if (message == null || message.Identifier == null) { if (!String.IsNullOrWhiteSpace(User)) { message = new RaygunIdentifierMessage(User); } else if (!String.IsNullOrWhiteSpace(deviceId)) { message = new RaygunIdentifierMessage(deviceId) { IsAnonymous = true, FullName = machineName, UUID = deviceId }; } } if (message != null && message.UUID == null) { message.UUID = deviceId; } return(message); }
/// <summary> /// Initializes a new instance of the <see cref="RaygunClient" /> class. /// </summary> /// <param name="apiKey">The API key.</param> public RaygunClient(string apiKey) { _apiKey = apiKey; _fileManager = new RaygunFileManager(); _fileManager.Intialise(); MaxReportsStoredOnDevice = RaygunFileManager.MAX_STORED_REPORTS_UPPER_LIMIT; // Setting default user information. var anonUser = GetAnonymousUserInfo(); _userInfo = anonUser; _user = anonUser.Identifier; _wrapperExceptions.Add(typeof(TargetInvocationException)); _wrapperExceptions.Add(typeof(AggregateException)); try { var clientVersion = new AssemblyName(GetType().Assembly.FullName).Version.ToString(); RaygunLogger.Info(string.Format("Configuring Raygun ({0})", clientVersion)); } catch { // Ignore } }
private static string UserInfoString(RaygunIdentifierMessage userInfo) { string str = ""; if (!String.IsNullOrWhiteSpace(userInfo.FullName)) { str += userInfo.FullName + " "; } else if (!String.IsNullOrWhiteSpace(userInfo.FirstName)) { str += userInfo.FirstName + " "; } if (!String.IsNullOrWhiteSpace(userInfo.Identifier)) { str += userInfo.Identifier + " "; } if (!String.IsNullOrWhiteSpace(userInfo.Email)) { str += userInfo.Email + " "; } if (!String.IsNullOrWhiteSpace(userInfo.UUID)) { str += userInfo.UUID + " "; } if (str.Length > 0) { str = str.Substring(0, str.Length - 1); // Removes last space } return(str); }
private void SetUserInfo(RaygunIdentifierMessage userInfo) { if (_activeBatch != null) { // Each batch is tied to the UserInfo at the time it's created. // So when the user info changes, we end any current batch, so the next one can pick up the new user info. _activeBatch.Done(); } if (string.IsNullOrWhiteSpace(userInfo?.Identifier) || string.IsNullOrEmpty(userInfo.Identifier)) { userInfo = GetAnonymousUserInfo(); } // Has the user changed ? if (_userInfo != null && _userInfo.Identifier != userInfo.Identifier && _userInfo.IsAnonymous == false) { if (!string.IsNullOrEmpty(_sessionId)) { SendPulseSessionEventNow(RaygunPulseSessionEventType.SessionEnd); _userInfo = userInfo; _user = userInfo.Identifier; SendPulseSessionEventNow(RaygunPulseSessionEventType.SessionStart); } } else { _userInfo = userInfo; _user = userInfo.Identifier; } }
private void SendCore(PulseEventBatch batch) { try { if (_sessionId == null) { SendPulseSessionEvent(RaygunPulseSessionEventType.SessionStart); } string version = GetVersion(); string os = "Android"; string osVersion = Android.OS.Build.VERSION.Release; string platform = string.Format("{0} {1}", Android.OS.Build.Manufacturer, Android.OS.Build.Model); RaygunIdentifierMessage user = BuildRaygunIdentifierMessage(null); RaygunPulseMessage message = new RaygunPulseMessage(); System.Diagnostics.Debug.WriteLine("BatchSize: " + batch.PendingEventCount); RaygunPulseDataMessage[] eventMessages = new RaygunPulseDataMessage[batch.PendingEventCount]; int index = 0; foreach (PendingEvent pendingEvent in batch.PendingEvents) { RaygunPulseDataMessage dataMessage = new RaygunPulseDataMessage(); dataMessage.SessionId = pendingEvent.SessionId; dataMessage.Timestamp = pendingEvent.Timestamp; dataMessage.Version = version; dataMessage.OS = os; dataMessage.OSVersion = osVersion; dataMessage.Platform = platform; dataMessage.Type = "mobile_event_timing"; dataMessage.User = user; string type = pendingEvent.EventType == RaygunPulseEventType.ViewLoaded ? "p" : "n"; RaygunPulseData data = new RaygunPulseData() { Name = pendingEvent.Name, Timing = new RaygunPulseTimingMessage() { Type = type, Duration = pendingEvent.Duration } }; RaygunPulseData[] dataArray = { data }; string dataStr = SimpleJson.SerializeObject(dataArray); dataMessage.Data = dataStr; eventMessages[index] = dataMessage; index++; } message.EventData = eventMessages; Send(message); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(string.Format("Error sending pulse event batch to Raygun: {0}", e.Message)); } }
public PulseEventBatch(RaygunClient raygunClient) { _raygunClient = raygunClient; _userInfo = _raygunClient.UserInfo; _lastUpdate = DateTime.UtcNow; Thread t = new Thread(CheckTime); t.Start(); }
/// <summary> /// Initializes a new instance of the <see cref="RaygunClient" /> class. /// </summary> /// <param name="apiKey">The API key.</param> public RaygunClient(string apiKey) { _apiKey = apiKey; // Setting default user information. var anonUser = GetAnonymousUserInfo(); _userInfo = anonUser; _user = anonUser.Identifier; _wrapperExceptions.Add(typeof(TargetInvocationException)); _wrapperExceptions.Add(typeof(AggregateException)); ThreadPool.QueueUserWorkItem(state => { SendStoredMessages(0); }); }
internal void SetUserInfo(RaygunIdentifierMessage userInfo) { if (_activeBatch != null) { // Each batch is tied to the UserInfo at the time it's created. // So when the user info changes, we end any current batch, so the next one can pick up the new user info. _activeBatch.Done(); } // Check info is valid if (string.IsNullOrWhiteSpace(userInfo?.Identifier) || string.IsNullOrEmpty(userInfo.Identifier)) { userInfo = GetAnonymousUserInfo(); } // Has the user changed ? if (_userInfo != null && _userInfo.Identifier != userInfo.Identifier && _userInfo.IsAnonymous == false) { if (!string.IsNullOrEmpty(_sessionId)) { SendPulseSessionEventNow(RaygunPulseSessionEventType.SessionEnd); _userInfo = userInfo; _user = userInfo.Identifier; SendPulseSessionEventNow(RaygunPulseSessionEventType.SessionStart); } } else { _userInfo = userInfo; _user = userInfo.Identifier; } // Pass on the info to the native Raygun reporter. if (NativeClient != null) { var info = new NativeRaygunUserInfo(); info.Identifier = _userInfo.Identifier; info.IsAnonymous = _userInfo.IsAnonymous; info.Email = _userInfo.Email; info.FullName = _userInfo.FullName; info.FirstName = _userInfo.FirstName; NativeClient.IdentifyWithUserInfo(info); } }
/// <summary> /// Asynchronously transmits an exception to Raygun. /// </summary> /// <param name="exception">The exception to deliver.</param> /// <param name="tags">A list of strings associated with the message.</param> /// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param> /// <param name="userInfo">Information about the user including the identity string.</param> public void SendInBackground(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { DateTime?currentTime = DateTime.UtcNow; if (CanSend(exception)) { ThreadPool.QueueUserWorkItem(c => { try { Send(BuildMessage(exception, tags, userCustomData, userInfo, currentTime)); } catch (Exception) { // This will swallow any unhandled exceptions unless we explicitly want to throw on error. // Otherwise this can bring the whole process down. if (RaygunSettings.Settings.ThrowOnError) { throw; } } }); FlagAsSent(exception); } }
/// <summary> /// Transmits an exception to Raygun synchronously specifying a list of string tags associated /// with the message for identification, as well as sending a key-value collection of custom data. /// This uses the version number of the originating assembly. /// </summary> /// <param name="exception">The exception to deliver.</param> /// <param name="tags">A list of strings associated with the message.</param> /// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param> /// <param name="userInfo">Information about the user including the identity string.</param> public void Send(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { if (CanSend(exception)) { Send(BuildMessage(exception, tags, userCustomData, userInfo, null)); FlagAsSent(exception); } }
protected async Task StripAndSend(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { foreach (Exception e in StripWrapperExceptions(exception)) { await Send(await BuildMessage(e, tags, userCustomData, userInfo)); } }
private void StripAndSend(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo, DateTime?currentTime) { foreach (Exception e in StripWrapperExceptions(exception)) { Send(BuildMessage(e, tags, userCustomData, userInfo, currentTime)); } }
protected RaygunMessage BuildMessage(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfoMessage) { return(BuildMessage(exception, tags, userCustomData, userInfoMessage, null)); }
protected RaygunMessage BuildMessage(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfoMessage) { exception = StripWrapperExceptions(exception); var message = RaygunMessageBuilder.New .SetHttpDetails(_currentRequestMessage) .SetEnvironmentDetails() .SetMachineName(Environment.MachineName) .SetExceptionDetails(exception) .SetClientDetails() .SetVersion(ApplicationVersion) .SetTags(tags) .SetUserCustomData(userCustomData) .SetUser(userInfoMessage ?? UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null)) .Build(); return(message); }
/// <summary> /// Asynchronously transmits an exception to Raygun.io. /// </summary> /// <param name="exception">The exception to deliver.</param> /// <param name="tags">A list of strings associated with the message.</param> /// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param> /// <param name="userInfo">Information about the user including the identity string.</param> public void SendInBackground(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { if (CanSend(exception)) { // We need to process the HttpRequestMessage on the current thread, // otherwise it will be disposed while we are using it on the other thread. RaygunRequestMessage currentRequestMessage = BuildRequestMessage(); ThreadPool.QueueUserWorkItem(c => { try { _currentRequestMessage = currentRequestMessage; Send(BuildMessage(exception, tags, userCustomData, userInfo)); } catch (Exception) { // This will swallow any unhandled exceptions unless we explicitly want to throw on error. // Otherwise this can bring the whole process down. if (RaygunSettings.Settings.ThrowOnError) { throw; } } }); FlagAsSent(exception); } }
/// <summary> /// Transmits an exception to Raygun.io synchronously specifying a list of string tags associated /// with the message for identification, as well as sending a key-value collection of custom data. /// This uses the version number of the originating assembly. /// </summary> /// <param name="exception">The exception to deliver.</param> /// <param name="tags">A list of strings associated with the message.</param> /// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param> /// <param name="userInfo">Information about the user including the identity string.</param> public void Send(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { if (CanSend(exception)) { _currentRequestMessage = BuildRequestMessage(); _currentBreadcrumbs = _breadcrumbs.ToList(); StripAndSend(exception, tags, userCustomData, userInfo, null); FlagAsSent(exception); } }
/// <summary> /// Asynchronously transmits an exception to Raygun.io. /// </summary> /// <param name="exception">The exception to deliver.</param> /// <param name="tags">A list of strings associated with the message.</param> /// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param> /// <param name="userInfo">Information about the user including the identity string.</param> public void SendInBackground(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { try { if (CanSend(exception)) { // We need to process the HttpRequestMessage on the current thread, // otherwise it will be disposed while we are using it on the other thread. RaygunRequestMessage currentRequestMessage = BuildRequestMessage(); // We need to retrieve the breadcrumbs on the current thread as the HttpContext.Current // will be null on the other thread var currentBreadcrumbs = _breadcrumbs.ToList(); var currentTime = DateTime.UtcNow; ThreadPool.QueueUserWorkItem( c => { try { _currentRequestMessage = currentRequestMessage; _currentBreadcrumbs = currentBreadcrumbs; StripAndSend(exception, tags, userCustomData, userInfo, currentTime); } catch (Exception) { // This will swallow any unhandled exceptions unless we explicitly want to throw on error. // Otherwise this can bring the whole process down. if (RaygunSettings.Settings.ThrowOnError) { throw; } } }); FlagAsSent(exception); } } catch (Exception) { // This will swallow any unhandled exceptions unless we explicitly want to throw on error. // Otherwise this can bring the whole process down. if (RaygunSettings.Settings.ThrowOnError) { throw; } } }
/// <summary> /// Asynchronously transmits an exception to Raygun. /// </summary> /// <param name="exception">The exception to deliver.</param> /// <param name="tags">A list of strings associated with the message.</param> /// <param name="userCustomData">A key-value collection of custom data that will be added to the payload.</param> /// <param name="userInfo">Information about the user including the identity string.</param> public virtual async Task SendInBackground(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { if (CanSend(exception)) { var task = Task.Run(async() => { await StripAndSend(exception, tags, userCustomData, userInfo); }); FlagAsSent(exception); await task; } }
protected RaygunMessage BuildMessage(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfoMessage, DateTime?currentTime) { RaygunMessageBuilder builder = RaygunMessageBuilder.New; builder.SetBreadcrumbs(_currentBreadcrumbs); var message = builder .SetHttpDetails(_currentRequestMessage) .SetTimeStamp(currentTime) .SetEnvironmentDetails() .SetMachineName(Environment.MachineName) .SetExceptionDetails(exception) .SetClientDetails() .SetVersion(ApplicationVersion) .SetTags(tags) .SetUserCustomData(userCustomData) .SetContextId(ContextId) .SetUser(userInfoMessage ?? UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null)) .Build(); var customGroupingKey = OnCustomGroupingKey(exception, message); if (string.IsNullOrEmpty(customGroupingKey) == false) { message.Details.GroupingKey = customGroupingKey; } return(message); }
protected virtual async Task <RaygunMessage> BuildMessage(Exception exception, IList <string> tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { var message = RaygunMessageBuilder.New(_settings) .SetEnvironmentDetails() .SetMachineName(Environment.MachineName) .SetExceptionDetails(exception) .SetClientDetails() .SetVersion(ApplicationVersion) .SetTags(tags) .SetUserCustomData(userCustomData) .SetUser(userInfo ?? UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null)) .Build(); var customGroupingKey = await OnCustomGroupingKey(exception, message); if (string.IsNullOrEmpty(customGroupingKey) == false) { message.Details.GroupingKey = customGroupingKey; } return(message); }
public IRaygunMessageBuilder SetUser(RaygunIdentifierMessage user) { _raygunMessage.Details.User = user; return(this); }
private void SendCore(PulseEventBatch batch) { try { if (_sessionId == null) { SendPulseSessionEvent(RaygunPulseSessionEventType.SessionStart); } string version = GetVersion(); string os = UIDevice.CurrentDevice.SystemName; string osVersion = UIDevice.CurrentDevice.SystemVersion; string platform = Mindscape.Raygun4Net.Builders.RaygunEnvironmentMessageBuilder.GetStringSysCtl("hw.machine"); string machineName = null; try { machineName = UIDevice.CurrentDevice.Name; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception getting device name {0}", e.Message); } RaygunIdentifierMessage user = BuildRaygunIdentifierMessage(machineName); RaygunPulseMessage message = new RaygunPulseMessage(); Debug.WriteLine("BatchSize: " + batch.PendingEventCount); RaygunPulseDataMessage[] eventMessages = new RaygunPulseDataMessage[batch.PendingEventCount]; int index = 0; foreach (PendingEvent pendingEvent in batch.PendingEvents) { RaygunPulseDataMessage dataMessage = new RaygunPulseDataMessage(); dataMessage.SessionId = pendingEvent.SessionId; dataMessage.Timestamp = pendingEvent.Timestamp; dataMessage.Version = version; dataMessage.OS = os; dataMessage.OSVersion = osVersion; dataMessage.Platform = platform; dataMessage.Type = "mobile_event_timing"; dataMessage.User = user; string type = pendingEvent.EventType == RaygunPulseEventType.ViewLoaded ? "p" : "n"; RaygunPulseData data = new RaygunPulseData() { Name = pendingEvent.Name, Timing = new RaygunPulseTimingMessage() { Type = type, Duration = pendingEvent.Duration } }; RaygunPulseData[] dataArray = { data }; string dataStr = SimpleJson.SerializeObject(dataArray); dataMessage.Data = dataStr; eventMessages[index] = dataMessage; index++; } message.EventData = eventMessages; Send(message); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(string.Format("Error sending pulse event batch to Raygun: {0}", e.Message)); } }