public void SendTrace(EpsagonTrace trace) { Utils.DebugLogIfEnabled("sending trace, url: {url}", this.CollectorUrl); var client = new RestClient(this.CollectorUrl) { Timeout = Utils.CurrentConfig.SendTimeout * 1000 }; var request = new RestRequest(Method.POST); request .AddHeader("Authorization", $"Bearer {this.Token}") .AddHeader("Content-Type", "application/json") .AddJsonBody(Utils.SerializeObject(trace)); var res = client.Execute(request); Utils.DebugLogIfEnabled("sent trace, {trace}", Utils.SerializeObject(trace)); if (!res.IsSuccessful) { Utils.DebugLogIfEnabled("request - method: {@method}, endpoint: {@ep}, timeout: {@to}", request.Method, request.Resource, request.Timeout); Utils.DebugLogIfEnabled("request body: {@body}", request.Body); Utils.DebugLogIfEnabled("response - headers: {@h}, status: {@s}, error: {@e}", res.Headers, res.StatusCode, res.ErrorMessage); Utils.DebugLogIfEnabled("response content: {@content}", res.Content); } JaegerTracer.Clear(); }
public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddAuthentication(AzureADDefaults.AuthenticationScheme) .AddAzureAD(options => Configuration.Bind("AzureAd", options)); services.AddMvc(options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); var loggerFactory = new LoggerFactory().AddConsole(); var tracer = JaegerTracer.CreateTracer("web-app", loggerFactory); services.AddOpenTracing(); GlobalTracer.Register(tracer); services.AddHttpClient <IDoughnutClient, DoughnutClient>(); services.AddHttpClient <IUserClient, UserClient>(); }
private static void CreateTraceAndSend() { var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); EpsagonTrace.SendTrace(trace); JaegerTracer.Clear(); EpsagonUtils.ClearTraceUrl(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); var loggerFactory = new LoggerFactory().AddConsole(); var tracer = JaegerTracer.CreateTracer("doughnuts-api", loggerFactory); services.AddOpenTracing(); GlobalTracer.Register(tracer); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <UserContext>(opt => opt.UseSqlite("Data Source=Users.db")); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); var loggerFactory = new LoggerFactory().AddConsole(); var logger = loggerFactory.CreateLogger <Program>(); var tracer = JaegerTracer.CreateTracer("users-api", loggerFactory); services.AddOpenTracing(); GlobalTracer.Register(tracer); }
public static void Bootstrap(bool useOpenTracingCollector = false, IEpsagonConfiguration configuration = null) { var levelSwitch = new LoggingLevelSwitch(LogEventLevel.Error); if ((Environment.GetEnvironmentVariable("EPSAGON_DEBUG") ?? "").ToLower() == "true") { levelSwitch.MinimumLevel = LogEventLevel.Debug; } var loggerConfig = new LoggerConfiguration() .MinimumLevel.ControlledBy(levelSwitch) .Enrich.FromLogContext() .WriteTo.Console(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { loggerConfig.WriteTo.EventLog("Epsagon"); } var logConfig = configuration?.LogFile ?? Environment.GetEnvironmentVariable("EPSAGON_LOG_FILE"); if (!string.IsNullOrWhiteSpace(logConfig)) { loggerConfig.WriteTo.File(logConfig); } Log.Logger = loggerConfig.CreateLogger(); if ((Environment.GetEnvironmentVariable("DISABLE_EPSAGON") ?? "").ToUpper() != "TRUE") { if (configuration != null) { Utils.RegisterConfiguration(configuration); } else { Utils.RegisterConfiguration(LoadConfiguration()); } CustomizePipeline(); // Use either legacy tracer or opentracing tracer if (useOpenTracingCollector) { Utils.DebugLogIfEnabled("remote"); JaegerTracer.CreateRemoteTracer(); } else { JaegerTracer.CreateTracer(); } Utils.DebugLogIfEnabled("finished bootstraping epsagon"); } }
public void SendTrace(EpsagonTrace trace) { Utils.DebugLogIfEnabled("sending trace, url: {url}"); var traceJsonString = Convert.ToBase64String(Encoding.UTF8.GetBytes(Utils.SerializeObject(trace))); System.Console.WriteLine("EPSAGON_TRACE: {0}", traceJsonString); Utils.DebugLogIfEnabled("sent trace, {trace}", Utils.SerializeObject(trace)); Utils.DebugLogIfEnabled("trace base64, {trace}", traceJsonString); JaegerTracer.Clear(); }
public static TRes Handle <TEvent, TRes>(TEvent input, ILambdaContext context, Func <TRes> handlerFn) { if (Utils.CurrentConfig == null || Utils.CurrentConfig.IsEpsagonDisabled) { return(handlerFn()); } var clientCodeExecuted = false; var returnValue = default(TRes); Exception exception = null; try { Utils.DebugLogIfEnabled("entered epsagon lambda handler"); // handle trigger event using (var scope = GlobalTracer.Instance.BuildSpan("").StartActive(finishSpanOnDispose: true)) { var trigger = TriggerFactory.CreateInstance(input.GetType(), input); trigger.Handle(context, scope); } // handle invocation event using (var scope = GlobalTracer.Instance.BuildSpan((typeof(TEvent).Name)).StartActive(finishSpanOnDispose: true)) using (var handler = new LambdaTriggerHandler <TEvent, TRes>(input, context, scope)) { handler.HandleBefore(); try { clientCodeExecuted = true; returnValue = handlerFn(); } catch (Exception e) { scope.Span.AddException(e); exception = e; } handler.HandleAfter(returnValue); } var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); EpsagonTrace.SendTrace(trace); JaegerTracer.Clear(); Utils.DebugLogIfEnabled("finishing epsagon lambda handler"); } catch (Exception ex) { HandleInstrumentationError(ex); } finally { if (exception != null) { throw exception; } if (!clientCodeExecuted) { returnValue = handlerFn(); } } return(returnValue); }
static void Main(string[] args) { EpsagonBootstrap.Bootstrap(); var client = new MongoClient("mongodb://*****:*****@test.com", PasswordHash = "secret" }); var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); Utils.DebugLogIfEnabled("sent trace, {trace}", Utils.SerializeObject(trace)); }
static void Main(string[] args) { var loggerFactory = new LoggerFactory().AddConsole(); var logger = loggerFactory.CreateLogger <Program>(); logger.LogInformation("Starting app"); var tracer = JaegerTracer.CreateTracer("console-app", loggerFactory); GlobalTracer.Register(tracer); var doughnutCollection = DoughnutCollectionHelper.GetTracingMongoClient(); doughnutCollection.InsertOne(new Doughnut { Price = 1, Color = "Red" }); using (var scope = tracer.BuildSpan("custom-span").StartActive(finishSpanOnDispose: true)) { try { var doughnuts = doughnutCollection.Find(a => true).ToList(); doughnutCollection.FindOneAndDelete(a => a.Id == ObjectId.GenerateNewId()); throw new Exception("Some exception"); } catch (Exception e) { scope.Span.SetTag(Tags.Error, true); scope.Span.Log(new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>("message", e.Message), new KeyValuePair <string, object>("stack.trace", e.StackTrace), new KeyValuePair <string, object>("source", e.Source) }); } } System.Console.ReadKey(); }
public static void Bootstrap() { var levelSwitch = new LoggingLevelSwitch(LogEventLevel.Error); if ((System.Environment.GetEnvironmentVariable("EPSAGON_DEBUG") ?? "").ToLower() == "true") { levelSwitch.MinimumLevel = LogEventLevel.Debug; } Log.Logger = new LoggerConfiguration() .MinimumLevel.ControlledBy(levelSwitch) .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); if ((Environment.GetEnvironmentVariable("DISABLE_EPSAGON") ?? "").ToUpper() != "TRUE") { JaegerTracer.CreateTracer(); CustomizePipeline(); Utils.RegisterConfiguration(LoadConfiguration()); Utils.DebugLogIfEnabled("finished bootstraping epsagon"); } }
public void SendTrace(EpsagonTrace trace) { Utils.DebugLogIfEnabled("sending trace, url: {url}", this.CollectorUrl); var client = new RestClient(this.CollectorUrl) { Timeout = 5000 }; var request = new RestRequest(Method.POST); request .AddHeader("Authorization", $"Bearer {this.Token}") .AddHeader("Content-Type", "application/json") .AddJsonBody(Utils.SerializeObject(trace)); var res = client.Execute(request); Utils.DebugLogIfEnabled("sent trace, {trace}", Utils.SerializeObject(trace)); Utils.DebugLogIfEnabled("request: {@request}", request); Utils.DebugLogIfEnabled("response: {@response}", res); JaegerTracer.Clear(); }
public static T Handle <T>(Func <T> clientFn, HttpContext context) { if (Utils.CurrentConfig == null || Utils.CurrentConfig.IsEpsagonDisabled) { return(clientFn()); } T result; var startTime = new DateTimeOffset(DateTime.UtcNow); using (var scope = CreateRunner(context)) { result = ExecuteClientCode(clientFn, scope); } CreateTrigger(context, startTime); var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); EpsagonTrace.SendTrace(trace); JaegerTracer.Clear(); EpsagonUtils.ClearTraceUrl(); return(result); }
public static async Task Handle <TEvent>(TEvent input, ILambdaContext context, Func <Task> handlerFn) { if (Utils.CurrentConfig == null || Utils.CurrentConfig.IsEpsagonDisabled) { await handlerFn(); return; } var clientCodeExecuted = false; Exception exception = null; try { if (Utils.CurrentConfig.IsEpsagonDisabled) { await handlerFn(); } Utils.DebugLogIfEnabled("entered epsagon lambda handler"); Utils.DebugLogIfEnabled("handling trigger event"); using (var scope = GlobalTracer.Instance.BuildSpan("").StartActive(finishSpanOnDispose: true)) { var trigger = TriggerFactory.CreateInstance(input.GetType(), input); trigger.Handle(context, scope); } // handle invocation event Utils.DebugLogIfEnabled("handling invocation event"); using (var scope = GlobalTracer.Instance.BuildSpan((typeof(TEvent).Name)).StartActive(finishSpanOnDispose: true)) using (var handler = new LambdaTriggerHandler <TEvent, string>(input, context, scope)) { Utils.DebugLogIfEnabled("handling before execution"); handler.HandleBefore(); Utils.DebugLogIfEnabled("calling client handler"); try { clientCodeExecuted = true; await handlerFn(); } catch (Exception e) { scope.Span.AddException(e); exception = e; } Utils.DebugLogIfEnabled("handling after execution"); handler.HandleAfter(""); } Utils.DebugLogIfEnabled("creating trace"); var trace = EpsagonConverter.CreateTrace(JaegerTracer.GetSpans()); EpsagonTrace.SendTrace(trace); JaegerTracer.Clear(); Utils.DebugLogIfEnabled("finishing epsagon lambda handler"); } catch (Exception ex) { HandleInstrumentationError(ex); } finally { if (exception != null) { throw exception; } if (!clientCodeExecuted) { await handlerFn(); } } }