Reproduction Steps for Challenging Errors

Have you ever run into hard to reproduce errors in a production environment? You can see an error happened in the logs but it's just not reproducible in a development or staging environment? Wouldn't it be nice if you could see what the user was doing before the error happened?

With Sitecore you can do this easily. Use Sitecore's built in tracker to append page visit history, browser info, etc to your exception messages to give yourself reproduction steps.

Here's some sample code to get started:

public string GetUserHistory()
		{
			var pageHistory = string.Empty;
			try
			{
				var pages = Sitecore.Analytics.Tracker.Current.Session.Interaction.GetPages();
				foreach(var page in pages)
				{
					pageHistory += $"   Url Visit Date: { page.DateTime.ToString("MM/dd/yyyy h:mm tt") } Url: { page.Url + System.Environment.NewLine }";
				}
			}
			catch (Exception e)
			{
                // the tracker may not have been started
				Sitecore.Diagnostics.Log.Warn("Unable to append analytics data to exception", e, this);
			}

			return pageHistory;
		}
Reproduction Steps for Challenging Errors
Share this