Skip to content

Always pass a non-null SpanRef to withSpan closures#543

Merged
lbwexler merged 1 commit intodevelopfrom
otelFixes
Apr 18, 2026
Merged

Always pass a non-null SpanRef to withSpan closures#543
lbwexler merged 1 commit intodevelopfrom
otelFixes

Conversation

@lbwexler
Copy link
Copy Markdown
Member

Summary

  • TraceService.withSpan now supplies a shared SpanRef.NOOP (backed by Span.invalid / Scope.noop()) when tracing is disabled, so closures always receive a non-null SpanRef.
  • Removes the need for ?. null-safe calls on span at every instrumented call site — updated JSONClient, BaseProxyService, docs, and examples.
  • ObservedRun.run carries the same non-null guarantee via activeSpan = SpanRef.NOOP default.

Test plan

  • ./gradlew assemble (compileGroovy passes locally).
  • Exercise a traced code path with tracing disabled and confirm span.setTag / span.setHttpStatus are safe no-ops.
  • Exercise the same path with xhTraceConfig.enabled = true and confirm spans export normally.

🤖 Generated with Claude Code

TraceService.withSpan now supplies a shared no-op SpanRef.NOOP (backed by Span.invalid / Scope.noop()) when tracing is disabled, so closures never need to guard calls like span.setHttpStatus(...) with ?. — simplifying every instrumented call site. ObservedRun.run carries the same guarantee.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lbwexler lbwexler requested a review from amcclain April 17, 2026 21:30
@lbwexler lbwexler marked this pull request as draft April 17, 2026 22:04
@lbwexler lbwexler marked this pull request as ready for review April 17, 2026 22:05
@lbwexler lbwexler merged commit fd76fac into develop Apr 18, 2026
7 checks passed
@lbwexler lbwexler deleted the otelFixes branch April 18, 2026 23:08
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.

1 participant