Skip to content

Enable the Sentry offline cache by default, keeping 50 reports #133

Description

@karlspace

Problem

Neither of the library's two Sentry entry points configures an offline cache:

  • the Sentry.NLog target in Logging/BGLoggerConfiguration.cs (around line 613, used through BGLogger.Configuration.ErrorTracking)
  • SentrySdk.Init in ErrorTracking/BGErrorTracking.cs:64

Without CacheDirectoryPath, the Sentry SDK sends straight over HTTP (decompiled Sentry.Internal.SdkComposer.CreateTransport, Sentry 6.6.0). A report that cannot be sent is lost: the station was offline, the endpoint was unreachable, or the process ended before the in-memory queue was flushed. That includes the crash report, which is sent from a process that is about to end.

With a cache directory, the SDK writes every envelope to disk before sending it. Whatever was not sent goes out after a network failure or on the next start.

Proposal

Enable the offline cache by default in both entry points:

  • CacheDirectoryPath: a folder inside the application's data folder, e.g. %ProgramData%\<App>\ErrorReports. The SDK creates a subfolder per DSN.
  • MaxCacheItems = 50 by default. The SDK default is 30, and when the limit is reached it deletes the oldest envelope whatever its level. A station that is offline for a while would otherwise lose an early crash to the warnings that follow. 50 keeps that window reasonable without an unbounded folder.
  • InitCacheFlushTimeout = TimeSpan.Zero, so application start never waits for the cache to be sent.
  • Make all three configurable on BGLoggerConfiguration and BGErrorTrackingConfiguration. Passing null or an empty value for the directory disables the cache.
  • Do not let a folder that cannot be created break the SDK start. CachingTransport.Initialize does not catch a failed CreateDirectory, and Sentry.NLog then swallows it, so reporting silently stays off.

Depends on

#132: in single-file applications the application data folder currently collapses to %ProgramData%, so the cache folder should be derived only after that is fixed, or together with it.

Context

bgIndustrialAutomation Client currently sets this itself, by reflection on the protected TargetErrorTracking before switching error tracking on (MaxCacheItems = 100, cache under its settings folder). A library default would let applications drop that workaround.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions