private static void DoMathHomework(TimeSpan forHowLong) { //Track work as span SimpleTracer.TrackWork("Do Math Homework", () => { Thread.Sleep(forHowLong); }); }
private static void CallMyBestFriend(TimeSpan forHowLong) { //Track work as span SimpleTracer.TrackWork("Call My Bestie", () => { throw new Exception("Get back to work!!!"); }); }
private static void DoComputerScienceHomework(TimeSpan forHowLong) { //Track work as span SimpleTracer.TrackWork("Do Computer Science Homework", () => { SimpleTracer.CurrentSpan(s => s.WithAttribute("Method", "DoComputerScienceHomework")); Thread.Sleep(forHowLong); }); }
/// <summary> /// This method will be tracked as a span. Since this is a topmost span, when this work is complete, the SpanBatch /// consisting of this span and all of its children will be sentt to New Relic. /// </summary> private static void DoHomework() { //Track work as span SimpleTracer.TrackWork("Do Homework", () => { DoMathHomework(TimeSpan.FromSeconds(2)); TakeABreak(TimeSpan.FromSeconds(1)); DoScienceHomework(); }); }
public static void Main(string[] args) { Console.WriteLine("Welcome to the Telemetry SDK sample Application."); Console.WriteLine(new String('-', 100)); var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); SimpleTracer.WithConfiguration(config); SimpleTracer.EnableTracing(); DoHomework(); SimpleTracer.DisableTracing(); }
private static void DoScienceHomework() { //Track work as span SimpleTracer.TrackWork("Do Science Homework", () => { DoComputerScienceHomework(TimeSpan.FromSeconds(1)); TakeABreak(TimeSpan.FromSeconds(2)); try { CallMyBestFriend(TimeSpan.FromSeconds(20)); } catch (Exception ex) { Console.Error.WriteLine($"Captured Expected Exception - {ex.Message}"); } DoBiologyHomework(TimeSpan.FromSeconds(1)); }); }
/// <summary> /// This method introduces a delay that is not tracked by a span. /// Its time would be accounted for in the caller's span. /// </summary> /// <param name="forHowLong"></param> private static void TakeABreak(TimeSpan forHowLong) { SimpleTracer.CurrentSpan((s) => { s.WithAttribute("Length of Break", forHowLong.TotalSeconds); }); Thread.Sleep(forHowLong); }