/// <summary> /// Send voice message (or just audio file if it's not vorbis ogg) /// </summary> /// <param name="audio">Audio to send</param> /// <param name="chatId">Chat ID to send photo to</param> /// <param name="caption"></param> /// <param name="parseMode"></param> /// <param name="replyToId"></param> /// <param name="duration"></param> public static async Task <Message> SendVoice(InputOnlineFile audio, long chatId, string caption = null, ParseMode?parseMode = null, int replyToId = 0, int duration = 0) { SentrySdk.ConfigureScope(scope => { scope.Contexts["Data"] = new { Audio = audio, Duration = duration, ChatID = chatId, Message = caption, ParseMode = parseMode, ReplyID = replyToId }; }); try { return(await api.SendVoiceAsync(chatId, audio, caption, parseMode, duration : duration, replyToMessageId : replyToId)); } catch (Exception ex) { Log.Error(ex.InnerMessageIfAny()); } return(null); }
/// <summary> /// Downloads file from the server using File ID /// </summary> /// <param name="fileId">File ID to download</param> /// <param name="path">Where to download</param> public static async Task <bool> DownloadFile(string fileId, string path) { if (string.IsNullOrEmpty(fileId) || string.IsNullOrEmpty(path)) { return(false); } SentrySdk.ConfigureScope(scope => { scope.Contexts["Data"] = new { FileId = fileId, Path = path }; }); await using var stream = new MemoryStream(); var file = await api.GetFileAsync(fileId); await api.DownloadFileAsync(file.FilePath, stream); await System.IO.File.WriteAllBytesAsync(path, stream.ToArray()); return(true); }
/// <summary> /// Edit media caption /// </summary> /// <param name="chatId">Chat ID to edit message in</param> /// <param name="messageId">Message to edit</param> /// <param name="caption">New caption</param> /// <param name="replyMarkup"></param> /// <param name="parseMode"></param> public static async Task <Message> EditMediaCaption(long chatId, int messageId, string caption, InlineKeyboardMarkup replyMarkup = null, ParseMode?parseMode = null) { SentrySdk.ConfigureScope(scope => { scope.Contexts["Data"] = new { MessageID = messageId, ChatID = chatId, Message = caption, ParseMode = parseMode, ReplyMarkup = replyMarkup }; }); try { return(await api.EditMessageCaptionAsync(chatId, messageId, caption, replyMarkup : replyMarkup, parseMode : parseMode)); } catch (Exception ex) { Log.Error(ex.InnerMessageIfAny()); } return(null); }
/// <summary> /// Edit message /// </summary> /// <param name="chatId">Chat ID to edit message in</param> /// <param name="messageId">Message to edit</param> /// <param name="message">New message</param> /// <param name="replyMarkup"></param> /// <param name="parseMode"></param> /// <param name="disablePreview"></param> public static async Task <Message> EditMessage(long chatId, int messageId, string message, InlineKeyboardMarkup replyMarkup = null, ParseMode?parseMode = null, bool disablePreview = true) { SentrySdk.ConfigureScope(scope => { scope.Contexts["Data"] = new { MessageID = messageId, ChatID = chatId, Message = message, ParseMode = parseMode, ReplyMarkup = replyMarkup }; }); try { return(await api.EditMessageTextAsync(chatId, messageId, message, parseMode, disableWebPagePreview : disablePreview, replyMarkup : replyMarkup)); } catch (Exception ex) { Log.Error(ex.InnerMessageIfAny()); } return(null); }
public static IDisposable WithScope(Action <Scope> configureScope) { var scope = SentrySdk.PushScope(); SentrySdk.ConfigureScope(configureScope); return(scope); }
/// <summary> /// Send message /// </summary> /// <param name="message">Text to send</param> /// <param name="chatId">Chat ID to send message to</param> /// <param name="parseMode">ParseMode to use (None/Markdown/HTML)</param> /// <param name="replyToId">Message ID to reply to</param> /// <param name="replyMarkup"></param> /// <param name="disablePreview"></param> public static async Task <Message> SendMessage(string message, long chatId, ParseMode?parseMode = null, int replyToId = 0, IReplyMarkup replyMarkup = null, bool disablePreview = true) { SentrySdk.ConfigureScope(scope => { scope.Contexts["Data"] = new { ChatID = chatId, Message = message, ParseMode = parseMode, ReplyID = replyToId, ReplyMarkup = replyMarkup, DisablePreview = disablePreview }; } ); try { if (!string.IsNullOrEmpty(message)) { return(await api.SendTextMessageAsync(chatId, message, parseMode, disableWebPagePreview : disablePreview, replyToMessageId : replyToId, replyMarkup : replyMarkup)); } } catch (Exception ex) { Log.Error(ex.InnerMessageIfAny()); } return(null); }
private static async Task App() { SentrySdk.ConfigureScope(scope => scope.AddTag("Initial scope data.")); SentrySdk.WithClientAndScope((client, scope) => { // Create heavy event stuff var evt = new SentryEvent("Entrypoint event."); scope.AddTag("Some scope change done in the callback"); return(client.CaptureEvent(evt, scope)); }); // TODO: how does it behave with .ConfigureAwait(false); var task = Task.Run(() => { // If no scope is pushed here, it'd be mutating the outer scope SentrySdk.PushScope(); // New scope, clone of the parent // Should it be ConfigureNewScope instead and bundle operations? SentrySdk.ConfigureScope(scope => scope.AddTag("First TPL task adding to scope")); // Simply send event SentrySdk.CaptureEvent(new SentryEvent("First Event from TPL")); }); await task; // here we shouldn't see side-effect from the TPL task SentrySdk.CaptureEvent(new SentryEvent("Final event from main thread")); throw new Exception("Error in the app"); }
public MainWindow() { SentrySdk.Init("https://[email protected]/4202655"); SentrySdk.ConfigureScope(scope => { scope.User = new User { Id = MachineCode.MachineCode.GetMachineCode() }; }); InitializeComponent(); _basePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DiskSearch" ); _resultList = new BindingList <Results>(); ResultListView.ItemsSource = _resultList; TagSelector.SelectedItem = TagSelector; _config = new Config(Path.Combine(_basePath, "config.json")); SetupIndex(); _backend.Watch(_config.SearchPath); Closed += OnClosedEvent; }
public static IDisposable Initialize(string releaseName) { try { _user = new User { Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name, Id = GetSystemFingerprint() }; var ret = SentrySdk.Init(o => { #if DEBUG o.Debug = true; #endif o.Dsn = new Dsn(Id); o.Release = releaseName; o.BeforeSend = BeforeSend; }); SentrySdk.ConfigureScope(s => { s.User = _user; } ); return(ret); } catch (Exception ex) { LogTo.Error(ex, "Exception while initializing Sentry"); return(null); } }
public void Init_MultipleCalls_ReplacesHubWithLatest() { var first = SentrySdk.Init(ValidDsnWithSecret); SentrySdk.AddBreadcrumb("test", "category"); var called = false; SentrySdk.ConfigureScope(p => { called = true; Assert.Single(p.Breadcrumbs); }); Assert.True(called); called = false; var second = SentrySdk.Init(ValidDsnWithSecret); SentrySdk.ConfigureScope(p => { called = true; Assert.Empty(p.Breadcrumbs); }); Assert.True(called); first.Dispose(); second.Dispose(); }
public void ConfigureScope_Sync_CallbackNeverInvoked() { var invoked = false; SentrySdk.ConfigureScope(_ => invoked = true); Assert.False(invoked); }
static void RunPeriodically(CmdOptions opts) { SentrySdk.ConfigureScope(scope => { scope.SetTag("rpc", opts.RpcUrl); scope.SetTag("dbname", opts.MongoDbName); scope.SetTag("dburl", opts.MongoUrl); }); // Migration step if (opts.MigrateDB) { Console.WriteLine("Start DB migration"); MigrateDatabase(opts); } BlockChainImporter importer = new BlockChainImporter(opts); while (true) { long lag = importer.GetCurrentLag(); if (lag > 50) { importer.RunImporter(); } else { Console.WriteLine($"Waiting for more fresh blocks ({lag} blocks waiting)..."); } Thread.Sleep(TimeSpan.FromSeconds(10)); } // ReSharper disable once FunctionNeverReturns }
public void UpdateScope(IOsInfo osInfo) { SentrySdk.ConfigureScope(scope => { scope.SetTag("is_docker", $"{osInfo.IsDocker}"); }); }
public async Task <IActionResult> Calculate(CalculateMapModel model) { if (string.IsNullOrEmpty(model.Map)) { return(StatusCode(400, new { err = "Incorrect beatmap link!" })); } SentrySdk.ConfigureScope(scope => { scope.Contexts["Map"] = model; }); if (!uint.TryParse(model.Map, out var mapId)) { var parsedLink = BeatmapLinkParser.Parse(model.Map); if (parsedLink == null) { return(StatusCode(400, new { err = "Incorrect beatmap link!" })); } if (parsedLink.IsBeatmapset) { return(StatusCode(400, new { err = "Beatmap set links aren't supported" })); } mapId = parsedLink.Id; } var mapInfo = await calculationService.Calculate(mapId, model.Mods); if (!string.IsNullOrEmpty(mapInfo)) { return(Ok(mapInfo)); } return(StatusCode(500, new { err = "Failed to calculate!" })); }
public static BaseMessageParser BuildParser(SPPMessage msg) { BaseMessageParser b = null; for (int i = 0; i < RegisteredParsers.Length; i++) { var act = (object)Activator.CreateInstance(RegisteredParsers[i]); if (act.GetType() == RegisteredParsers[i]) { BaseMessageParser parser = (BaseMessageParser)act; if (parser.HandledType == msg.Id) { SentrySdk.ConfigureScope(scope => { scope.SetTag("msg-data-available", "true"); scope.SetExtra("msg-type", msg.Type.ToString()); scope.SetExtra("msg-id", msg.Id); scope.SetExtra("msg-size", msg.Size); scope.SetExtra("msg-total-size", msg.TotalPacketSize); scope.SetExtra("msg-crc16", msg.CRC16); scope.SetExtra("msg-payload", Hex.Dump(msg.Payload, 512, false, false, false)); }); parser.ParseMessage(msg); b = parser; break; } } } return(b); }
public async Task Invoke(IDictionary <string, object> environment) { using (SentrySdk.PushScope()) { SentrySdk.ConfigureScope(scope => { // Gets called if an event is sent out within this request. // By a logger.LogError or FirstChanceException scope.AddEventProcessor(@event => { ApplyContext(@event, environment); return(@event); }); }); try { await _next(environment); } catch (Exception ex) { // An exception thrown in the ExceptionHandler will end up here. var evt = new SentryEvent(ex); ApplyContext(evt, environment); SentrySdk.CaptureEvent(evt); throw; } } }
public static void Main() { System.Console.SetWindowSize(160, 60); System.Console.SetBufferSize(160, Int16.MaxValue - 1); //https://stackoverflow.com/questions/1600962/displaying-the-build-date var linkTimeLocal = new DateTime(Builtin.CompileTime, DateTimeKind.Utc); var username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; #if DEBUG App.Main(); #else using (SentrySdk.Init((o) => { o.Dsn = "https://[email protected]/5390642"; o.Release = $"TacControl@{linkTimeLocal:yy-MM-dd_HH-mm}"; o.Environment = username == "Dedmen-PC\\dedmen" ? "Dev" : "Alpha"; })) { SentrySdk.ConfigureScope((scope) => { scope.User = new User { Username = username }; }); App.Main(); } #endif }
public static void Initialize() { if (_initialized) { return; } var dsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); SentrySdk.ConfigureScope(scope => { scope.User = new User { Id = Setup.SUUID, }; scope.SetTag("hostApplication", Setup.HostApplication); }); var env = "production"; #if DEBUG env = "dev"; #endif SentrySdk.Init(o => { o.Dsn = dsn; o.Environment = env; o.Debug = true; o.Release = "SpeckleCore@" + Assembly.GetExecutingAssembly().GetName().Version.ToString(); }); _initialized = true; }
public void SetTag(string tag, string value) { SentrySdk.ConfigureScope(scope => { scope.SetTag(tag, value); }); }
private async Task HandleCommandAsync(SocketMessage messageParam) { if (!(messageParam is SocketUserMessage message)) { return; } int argPos = 0; if (message.HasCharPrefix('%', ref argPos) && !message.Author.IsBot) { var context = new SocketCommandContext(Client, message); using (SentrySdk.PushScope()) { SentrySdk.ConfigureScope(scope => { scope.User = new Sentry.Protocol.User { Id = message.Author.Id.ToString(), Username = message.Author.Username + "#" + message.Author.Discriminator, }; scope.SetExtra("message", message.Content); }); Log.Debug("Executing command {Command}", message.Content); await _commands.ExecuteAsync(context, argPos, _services); } } }
public void UnsetTag(string tag) { SentrySdk.ConfigureScope(scope => { scope.UnsetTag(tag); }); }
private static void Main(string[] args) { SentrySdk.Init("https://[email protected]/4202655"); SentrySdk.ConfigureScope(scope => { scope.User = new User { Id = MachineCode.MachineCode.GetMachineCode() }; }); var basePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DiskSearch" ); _backend = new Backend(basePath); AppDomain.CurrentDomain.ProcessExit += (s, e) => _backend.Close(); if (args.Length != 1) { Prompt(); } else { Console.WriteLine("Indexing..."); _backend.Walk(args[0]); GC.Collect(); GC.WaitForPendingFinalizers(); _backend.Watch(args[0]); Prompt(); } }
public CatalogProcessor( ICursor cursor, ICatalogClient client, ICatalogLeafProcessor leafProcessor, CatalogProcessorSettings settings, ILogger <CatalogProcessor> logger) { _leafProcessor = leafProcessor ?? throw new ArgumentNullException(nameof(leafProcessor)); _client = client ?? throw new ArgumentNullException(nameof(client)); _cursor = cursor ?? throw new ArgumentNullException(nameof(cursor)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (settings.ServiceIndexUrl == null) { throw new ArgumentException( $"The {nameof(CatalogProcessorSettings.ServiceIndexUrl)} property of the " + $"{nameof(CatalogProcessorSettings)} must not be null.", nameof(settings)); } // Clone the settings to avoid mutability issues. _settings = settings.Clone(); SentrySdk.ConfigureScope(s => s.Contexts["CatalogProcessorSettings"] = _settings); }
/// <summary> /// Initializes the Sentry environment. /// Sentry is an open-source application monitoring platform that help to identify issues. /// </summary> /// <returns></returns> private static IDisposable InitSentry() { if (!GlobalSettings.Instance.IsSentryEnabled || IsDebugBuild) { Log.Info("Sentry is disabled"); return(null); } Log.Info("Initializing Sentry"); IDisposable sentrySdkInstance = null; try { string environment = "Release"; #if DEBUG environment = "Debug"; #elif BETA environment = "Beta"; #endif sentrySdkInstance = SentrySdk.Init(o => { o.Dsn = new Dsn("https://[email protected]/1478084"); o.Release = "AML@" + GetCurrentVersionString(); // prefix because releases are global per organization o.Debug = false; o.Environment = environment; o.MaxBreadcrumbs = 50; o.BeforeSend = sentryEvent => { sentryEvent.User.Email = null; return(sentryEvent); }; }); SentrySdk.ConfigureScope(scope => { scope.User = new User { Id = GlobalSettings.Instance.Guid, Username = GlobalSettings.Instance.UserName, IpAddress = null }; }); Log.Info($"Sentry initialized ({GlobalSettings.Instance.Guid})"); } catch (Exception ex) { // If Sentry wasn't initialized correctly we at least try to send one message to report this. // (this won't throw another Ex, even if Init() failed) Log.Error("Sentry setup failed", ex); SentrySdk.Close(); Debug.WriteLine(ex.Message); } return(sentrySdkInstance); }
public void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args) { SentrySdk.ConfigureScope(scope => scope.SetTag("Handled", "False") ); SentrySdk.CaptureException((Exception)args.ExceptionObject); SentrySdk.FlushAsync(new TimeSpan(0, 1, 0)).Wait(); // 1 minute to send or to make an offline backup }
public override void OnException(HttpActionExecutedContext context) { SentrySdk.ConfigureScope(scope => { scope.SetTag("servername", Environment.MachineName.ToString()); }); SentrySdk.CaptureException(context.Exception); }
public SentryRemoteLogger() { if (TestingUtility.IsRunningFromUnitTest || Debugger.IsAttached) { return; } SentrySdk.Init("https://[email protected]/5555548"); SentrySdk.ConfigureScope(ConfigureScope); }
private static void ConfigureErrorTracking() { SentrySdk.ConfigureScope(scope => { // add configuration to crash reports scope.SetExtra("configuration", _gameServerConfiguration); scope.SetExtra("path", AppContext.BaseDirectory); }); }
public static void updateSettingsInfo(string woxLanguage) { _woxLanguage = woxLanguage; SentrySdk.ConfigureScope(scope => { scope.SetTag("woxLanguage", _woxLanguage); }); }
public void UnsetTags(List <string> tags) { SentrySdk.ConfigureScope(scope => { foreach (string tag in tags) { scope.UnsetTag(tag); } }); }