Skip to content

Allow each signal API to be thoroughly disabled#1785

Open
bidetofevil wants to merge 2 commits into
open-telemetry:mainfrom
bidetofevil:hho/disable-signals
Open

Allow each signal API to be thoroughly disabled#1785
bidetofevil wants to merge 2 commits into
open-telemetry:mainfrom
bidetofevil:hho/disable-signals

Conversation

@bidetofevil

Copy link
Copy Markdown
Contributor

Add the ability to disable each signal API via the config DSL that provides a no-op provider instead of just not configuring any processors. This eliminates the overhead of instrumentation that are still configured but whose telemetry doesn't ever get recorded and sent.

@bidetofevil bidetofevil requested a review from a team as a code owner June 3, 2026 05:37
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.36%. Comparing base (37ae421) to head (ca726ef).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...o/opentelemetry/android/OpenTelemetryRumBuilder.kt 94.87% 0 Missing and 2 partials ⚠️
...metry/android/agent/OpenTelemetryRumInitializer.kt 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1785      +/-   ##
==========================================
+ Coverage   62.99%   63.36%   +0.37%     
==========================================
  Files         157      159       +2     
  Lines        3448     3502      +54     
  Branches      352      370      +18     
==========================================
+ Hits         2172     2219      +47     
  Misses       1179     1179              
- Partials       97      104       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

/**
* Whether the tracing API is enabled. Toggle with using [setTracingEnabled]
*/
@Volatile

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to make these volatile?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose its creation and consumption are all done on the main thread, and this object is thrown away after the SDK is initialized, so I can remove this if you feel it makes things slightly more convoluted.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I don't see a reason why making it thread-safe, at least not now. Plus, if it were needed, then I think we should apply the same safety guards to the rest of the config options. But for now I think it's better to keep it simple.

@breedx-splk

Copy link
Copy Markdown
Contributor

Related to #1776

@breedx-splk breedx-splk added this to the 1.5.0 milestone Jun 9, 2026
Comment on lines +39 to +41
fun disableTracing(disable: Boolean) {
rumConfig.setTracingEnabled(!disable)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these would benefit from not allowing the inverse logic, especially when they are enabled by default.

Suggested change
fun disableTracing(disable: Boolean) {
rumConfig.setTracingEnabled(!disable)
}
fun disableTracing() {
rumConfig.setTracingEnabled(false)
}

Comment on lines +46 to +48
fun disableLogging(disable: Boolean) {
rumConfig.setLoggingEnabled(!disable)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun disableLogging(disable: Boolean) {
rumConfig.setLoggingEnabled(!disable)
}
fun disableLogging() {
rumConfig.setLoggingEnabled(false)
}

Comment on lines +53 to +55
fun disableMetrics(disable: Boolean) {
rumConfig.setMetricsEnabled(!disable)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun disableMetrics(disable: Boolean) {
rumConfig.setMetricsEnabled(!disable)
}
fun disableMetrics() {
rumConfig.setMetricsEnabled(false)
}

}

/**
* Disable logging in the SDK by providing no-op implementations that don't incur overhead even if instrumentation emits logs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we also mention that this silences events too?

Comment on lines +72 to +86
if (rumConfig.tracingEnabled) {
addSpanExporterCustomizer {
createSpanExporter(cfg.exportConfig.spansEndpoint())
}
}
if (rumConfig.loggingEnabled) {
addLogRecordExporterCustomizer {
createLogExporter(cfg.exportConfig.logsEndpoint())
}
}
if (rumConfig.metricsEnabled) {
addMetricExporterCustomizer {
createMetricExporter(cfg.exportConfig.metricsEndpoint())
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One interesting edge case of this is that if (for some reason) telemetry data was left on disk, and, after an upgrade, one of the signals was no longer turned on, we wouldn't have an exporter to handle that data on disk. Presumably we would read it and export it to a noop, effectively losing it.

I think I'm fine with that, but just wanted to make a note of it in case it hadn't been considered.

)

server.awaitLogRequest { findLog(it) }
assertEquals(0, server.traceRequestCount())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer fluent assertj assertions.

Suggested change
assertEquals(0, server.traceRequestCount())
assertThat(server.traceRequestCount()).isZero()

}
assertTraceRequestReceived(traceRequest)
server.awaitTraceRequest { findSpan(it) }
assertEquals(0, server.logRequestCount())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertEquals(0, server.logRequestCount())
assertThat(server.logRequestCount()).isZero()

Comment on lines +147 to +168
fun setTracingEnabled(enabled: Boolean): OtelRumConfig {
tracingEnabled = enabled
return this
}

/**
* Enables or disables the logging API for the SDK. When disabled, the SDK will provide no-op implementations to instrumentation
* that use this API.
*/
fun setLoggingEnabled(enabled: Boolean): OtelRumConfig {
loggingEnabled = enabled
return this
}

/**
* Enables or disables the metrics API for the SDK. When disabled, the SDK will provide no-op implementations to instrumentation
* that use this API.
*/
fun setMetricsEnabled(enabled: Boolean): OtelRumConfig {
metricsEnabled = enabled
return this
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my preference would be to have these as disable methods with no arg, since the default is enabled.

Comment on lines -16 to +15
private val openTelemetrySdk: OpenTelemetrySdk,
override val openTelemetry: OpenTelemetry,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@breedx-splk breedx-splk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, but it's looking mostly good to me! Thanks for picking this up.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants