[meshkit] fix: disable tracing when no endpoint configured, suppress repeated export-failure logs
Fixes: #894
Summary
This PR makes two related fixes to tracing/tracing.go:
-
Treats a missing/empty endpoint as implicitly disabled tracing: Previously,
InitTracerreturned a hard error ifEndpointwas empty, even when tracing was never intended to be used. Now, if no endpoint is configured (or tracing is explicitly disabled via a newEnabled *boolfield),InitTracerreturnsnil, nilβ a clean no-op, not an error. -
Suppresses repeated identical export-failure logs : when an endpoint is configured but unreachable (e.g. collector down, wrong address, not yet started), the OTLP exporter retries indefinitely, and previously logged a failure on every retry (~every 10-15s). This adds an error handler (via
otel.SetErrorHandler) that logs the first failure once, then suppresses further identical failures, without affecting the underlying retry behavior itself.Any previously registered OTel error handler is preserved and still invoked, so this doesn't silently override unrelated error handling that may already be in place.
Why
Meshery Server was logging repeated "connection refused" errors when no trace collector was configured, because it kept trying to reach a default. OTLP address. Investigation showed this had two separate causes:
- The original reported scenario (nothing configured at all) was independently fixed in meshery's
main.go/Makefile defaults, but the same protection was never added at the meshkit layer, so any other meshkit consumer remained exposed to it. - A related, still-open case: a user (or a Helm deployment, once meshery/meshery#20898 lands) explicitly configuring an endpoint that's unreachable still produces the same noisy log loop today.
Known limitation
- The suppression does not currently reset on recovery, if the collector comes back online and later goes down again, the second failure streak won't log again, since
otel.SetErrorHandleronly exposes a failure hook, not a success hook. This still resolves the reported issue (no more infinite log spam) but is noted here as a possible future improvement (e.g. wrapping the exporter directly to detect successful exports). - The suppression currently applies to all OTel errors process-wide, not specifically to export failures, it doesn't distinguish "collector unreachable" from other kinds of OTel errors that might occur. A more precise fix would inspect the error type or wrap the exporter directly instead of using the global handler, which felt like a larger change than this PR's scope.
Testing
-
Added unit tests covering: explicit disable, missing endpoint (no-op, not an error), and explicit enable with no endpoint (still a no-op).
-
Verified live, against a real collector:
- Confirmed
make serverwith noOTEL_CONFIGalready logs cleanly ("tracing disabled"), unaffected by this change.
- Confirmed
https://github.com/user-attachments/assets/3b7ffb50-3dac-47c3-8081-69b53328167a
- Demonstrated the still-open problem this PR fixes: with an endpoint configured but unreachable, the exporter retries and logs a failure on every attempt, continuously (~every 10-15s), before this fix.
https://github.com/user-attachments/assets/9d08ff30-2990-4862-bc37-113c10798fbc
- With the fix applied: configured the same unreachable endpoint and confirmed the failure now logs only once, not on every retry. Then started a local Jaeger instance (OTLP on 4317) and confirmed traces from
meshery-serverappear correctly in Jaeger's UI. Then stopped Jaeger again and confirmed no renewed log spam occurs (consistent with the known limitation noted above, suppression persists rather than resetting on recovery).
https://github.com/user-attachments/assets/74e3c2da-76ce-4ecb-a499-15ea555d3e94
Related
Companion Helm chart change (exposes OTEL_CONFIG in values.yaml):
meshery/meshery#20898
Signed commits
- [x] Yes, I signed my commits.
Summary by CodeRabbit
Summary by CodeRabbit
-
New Features
- Added an
enabledoption to explicitly turn tracing on or off via YAML/JSON configuration.
- Added an
-
Bug Fixes
- Tracing now behaves as a safe no-op when tracing is disabled or when no endpoint is configured, instead of failing to start.
- Prevented repeated tracing export failures from repeatedly flooding logs.
-
Tests
- Expanded tracer initialization tests to verify nil/no-op behavior and correct shutdown handling when tracing is disabled or omitted.
No actionable comments were generated in the recent review. π
βΉοΈ Recent review info
βοΈ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 11c55baf-aea1-43d9-b65f-5946cf4c06e2
π₯ Commits
Reviewing files that changed from the base of the PR and between eb3e30e1bdaa7ed2594086d17f094276bc633641 and d13464b79b4b49fdc6496f8f1effdbe07b341173.
π Files selected for processing (2)
tracing/tracing.gotracing/tracing_test.go
π§ Files skipped from review as they are similar to previous changes (2)
- tracing/tracing_test.go
- tracing/tracing.go
π Walkthrough
Walkthrough
Tracing configuration adds explicit disabling, treats an empty endpoint as a no-op, and suppresses repeated OpenTelemetry export failures. Tests verify nil-provider and error behavior across enabled and disabled configurations.
Changes
Tracing configuration
| Layer / File(s) | Summary |
|---|---|
Tracing controls and error suppression tracing/tracing.go |
Adds the optional Config.Enabled flag, synchronized suppression of repeated OpenTelemetry export errors, and global error-handler chaining. |
Initialization behavior and validation tracing/tracing.go, tracing/tracing_test.go |
InitTracer returns nil, nil when disabled or when no endpoint is configured; tests cover provider nil-ness and error expectations across configurations. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Possibly related issues
- meshery/meshkit#1071 β Refines the OpenTelemetry export-error deduplication behavior introduced in this change.
π₯ Pre-merge checks | β 4 | β 1
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Linked Issues check | β οΈ Warning | Only meshkit tracing changes are present; #894 also requires Meshery env, Helm, and docs updates that are not shown here. |
Add the Meshery-side config/env wiring, expose it in Helm values, and update docs so tracing can be disabled end-to-end. |
β Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title matches the main change: disabling tracing when no endpoint is configured and suppressing repeated export-failure logs. |
| Out of Scope Changes check | β Passed | The changes stay focused on tracing configuration and tests, with no obvious unrelated code paths introduced. |
| Docstring Coverage | β Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
Comment @coderabbitai help to get the list of available commands.
@uzairhameed there is an earlier PR on this same topic. Please reconcile.
@uzairhameed there is an earlier PR on this same topic. Please reconcile.
Yes, I reviewed the earlier PR and shared my feedback during the development meeting on July 14. You can refer to the meeting recording from 51:00β58:00.
Lee gave me the go-ahead to work on this and suggested that I coordinate with the original PR author. However, as you can see, they haven't been active on this issue since January, so I proceeded with the implementation.
Closing this in favor of a re-scoped PR, per feedback to keep this fix narrowly focused on the endpoint/enabled check: #1088 .