sentry icon indicating copy to clipboard operation
sentry copied to clipboard

Allow Logs to be disabled during runtime

Open igorsantos07 opened this issue 2 months ago • 5 comments

Problem Statement

This is simple, at least from the developer POV: I want to add an option in my app's Settings screen that allow the user to enable/disable full logging behavior. This would require a way to toggle enableLogs on/off, but right now that's not possible.

Solution Brainstorm

The Docs AI even told me to try to write to that property, in the React SDK, via getOptions().enableLogs, but that just caused erratic behavior 🤷‍♂️

Right now, I solved this with a global variable checked in beforeSendLog, but running a function over and over again to check a simple boolean seems quite suboptimal, when there are other runtime functions in the SDK — such as changing user details, etc.

I'm not submitting this to the React SDK, even though it's my current target, as I can see this being useful in most platforms.

Also, it looks like there's not yet a Product Area: Logs? 😅

Product Area

Other

igorsantos07 avatar Nov 10 '25 21:11 igorsantos07

ENG-5871

linear[bot] avatar Nov 10 '25 21:11 linear[bot]

Assigning to @getsentry/support for routing ⏲️

getsantry[bot] avatar Nov 10 '25 21:11 getsantry[bot]

Do you want to also skip capturing errors, spans, user feedback (and other stuff the sdk collects?)

If so, you can conditionally init the SDK based on user permission, and then call Sentry.close() to disable the SDK. Once you've disabled the SDK though, you can't re-enable it.

The Docs AI even told me to try to write to that property, in the React SDK, via getOptions().enableLogs, but that just caused erratic behavior

This should work as long as you only have a single client. What was the erratic behaviour you were seeing?

AbhiPrasad avatar Nov 10 '25 22:11 AbhiPrasad

Routing to @getsentry/product-owners-explore for triage ⏲️

getsantry[bot] avatar Nov 17 '25 13:11 getsantry[bot]

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

getsantry[bot] avatar Dec 09 '25 08:12 getsantry[bot]

This should work as long as you only have a single client. What was the erratic behaviour you were seeing?

It didn't seem to work properly, although the logs page isn't as instant as it seems, so I may have gotten confused.

Nonetheless, considering it's not documented explicitly, and... using an object created on the fly via a get method + setting a property on it doesn't seem the most common API around. I get that JS nowadays have magic setters which can implement more logic than simply flipping a property, but it's confusing, at the very least.

If that's really the way, this could be documented as such, at least.

igorsantos07 avatar Dec 11 '25 19:12 igorsantos07