public TraceResponse Report([FromBody] MyTraceModel model) { var builders = model?.Builders.Cast <ISpanBuilder>().ToArray(); //var builders = new ISpanBuilder[0]; if (model == null || model.AppId.IsNullOrEmpty() || builders == null || builders.Length == 0) { return(null); } // 校验应用 var app = AppTracer.FindByName(model.AppId); if (app == null) { app = new AppTracer { Name = model.AppId, DisplayName = model.AppName, Enable = Setting.Current.AutoRegister, }; app.Save(); } if (!app.Enable) { throw new Exception($"无效应用[{model.AppId}/{model.AppName}]"); } // 插入数据 var ip = HttpContext.GetUserHost(); if (ip.IsNullOrEmpty()) { ip = ManageProvider.UserHost; } Task.Run(() => ProcessData(app, ip, builders)); _stat.Add(app.ID); _appStat.Add(app.ID); // 构造响应 return(new TraceResponse { Period = app.Period, MaxSamples = app.MaxSamples, MaxErrors = app.MaxErrors, }); }
public TraceResponse Report([FromBody] TraceModel model, String token) { var builders = model?.Builders.Cast <ISpanBuilder>().ToArray(); //var builders = new ISpanBuilder[0]; if (model == null || model.AppId.IsNullOrEmpty() || builders == null || builders.Length == 0) { return(null); } var ip = HttpContext.GetUserHost(); if (ip.IsNullOrEmpty()) { ip = ManageProvider.UserHost; } var set = Setting.Current; // 新版验证方式,访问令牌 Data.App ap = null; if (!token.IsNullOrEmpty() && token.Split(".").Length == 3) { ap = _service.DecodeToken(token, set); if (ap == null || ap.Name != model.AppId) { throw new InvalidOperationException($"授权不匹配[{model.AppId}]!=[{ap.Name}]!"); } } Data.App.UpdateInfo(model, ip); // 该应用的跟踪配置信息 var app = AppTracer.FindByName(model.AppId); if (app == null) { app = new AppTracer { Name = model.AppId, DisplayName = model.AppName, Enable = set.AutoRegister, }; app.Save(); } // 校验应用 if (app == null || !app.Enable) { throw new Exception($"无效应用[{model.AppId}/{model.AppName}]"); } // 插入数据 Task.Run(() => ProcessData(app, model, ip, builders)); // 构造响应 var rs = new TraceResponse { Period = app.Period, MaxSamples = app.MaxSamples, MaxErrors = app.MaxErrors, Timeout = app.Timeout, //Excludes = app.Excludes?.Split(",", ";"), }; // 新版本才返回Excludes,老版本客户端在处理Excludes时有BUG,错误处理/ if (!model.Version.IsNullOrEmpty()) { rs.Excludes = app.Excludes?.Split(",", ";"); } return(rs); }
public TraceResponse Report([FromBody] TraceModel model, String token) { var builders = model?.Builders; if (model == null || model.AppId.IsNullOrEmpty()) { return(null); } var ip = HttpContext.GetUserHost(); if (ip.IsNullOrEmpty()) { ip = ManageProvider.UserHost; } var set = Setting.Current; // 新版验证方式,访问令牌 App ap = null; if (!token.IsNullOrEmpty() && token.Split(".").Length == 3) { ap = _service.DecodeToken(token, set); //if (ap == null || ap.Name != model.AppId) throw new InvalidOperationException($"授权不匹配[{model.AppId}]!=[{ap?.Name}]!"); if (ap == null) { throw new InvalidOperationException($"授权不匹配[{model.AppId}]!=[{ap?.Name}]!"); } } App.UpdateInfo(model, ip); var clientId = model.ClientId; if (clientId.IsNullOrEmpty()) { var(jwt, ex) = _service.DecodeToken(token, set.TokenSecret); clientId = jwt?.Id; } AppOnline.UpdateOnline(ap, clientId, ip, token, model.Info); // 该应用的追踪配置信息 var app = AppTracer.FindByName(model.AppId); if (app == null) { app = new AppTracer { Name = model.AppId, DisplayName = model.AppName, Enable = set.AutoRegister, }; app.Save(); } // 校验应用 if (app == null || !app.Enable) { throw new Exception($"无效应用[{model.AppId}/{model.AppName}]"); } // 插入数据 if (builders != null && builders.Length > 0) { Task.Run(() => ProcessData(app, model, ip, builders)); } // 构造响应 var rs = new TraceResponse { Period = app.Period, MaxSamples = app.MaxSamples, MaxErrors = app.MaxErrors, Timeout = app.Timeout, //Excludes = app.Excludes?.Split(",", ";"), }; // Vip客户端。高频次大样本采样,10秒100次,逗号分割,支持*模糊匹配 if (app.IsVip(model.ClientId)) { rs.Period = 10; rs.MaxSamples = 100; } // 新版本才返回Excludes,老版本客户端在处理Excludes时有BUG,错误处理/ if (!model.Version.IsNullOrEmpty()) { rs.Excludes = app.Excludes?.Split(",", ";"); } return(rs); }