Skip to content

Harden error handling, unify logging, add OpenTelemetry extension, and improve docs #808

Open
jbachorik wants to merge 15 commits intodevelopfrom
claude/project-review-HBcMK
Open

Harden error handling, unify logging, add OpenTelemetry extension, and improve docs #808
jbachorik wants to merge 15 commits intodevelopfrom
claude/project-review-HBcMK

Conversation

@jbachorik
Copy link
Copy Markdown
Collaborator

@jbachorik jbachorik commented Mar 28, 2026

Summary

Systematic project-wide review of the BTrace codebase resulting in 10 improvements across error handling, logging, CI, code quality, documentation, and observability.

Error handling & reliability

  • Fix 30+ swallowed exceptions across 7 modules (compiler, client, ext-cli, extension loader) — silent catch (Exception ignored) {} blocks now log at DEBUG level via SLF4J, making failures diagnosable without impacting production performance
  • Fix resource leaks — DOTWriter leaks FileOutputStream if PrintStream construction fails; PCPP #include reader is never closed. Both converted to safe resource management
  • Replace 4 production assert statements with IllegalStateException null checks in BTraceRuntimeAccessImpl, InstrumentingMethodVisitor, Indy, and Client — assert is silently disabled by default in production JVMs
  • Preserve exception chainsCompilerClassWriter was throwing new RuntimeException(e.toString()), discarding the entire causal stack trace. Now wraps with descriptive message and original cause
  • Use specific exception typesIllegalArgumentException for invalid command types (WireIO), IllegalStateException for class loading failures (RemoteClient), replacing bare RuntimeException

Logging

  • Replace System.err.println with SLF4J in 7 infrastructure modules: Instrumentor, ClassFilter, BTraceMethodNode, BTraceRuntimeAccessImpl, Printer, MethodInvocationRecorder, CompilerClassWriter. Unifies log output under the standard logging framework and respects log level configuration. Intentional CLI output (usage messages, ProbePrinter) and bootstrap module code (btrace-boot, which has no SLF4J dependency) are left unchanged.

CI/CD

  • Add dependency vulnerability scanning — new dependency-review job in continuous.yml using actions/dependency-review-action@v4, runs on PRs, fails on high-severity CVEs, posts summary comment

Code quality

  • Implement BTraceMBean array type supporttypeToOpenType() had a FIXME: This is highly incomplete for array types. Now handles arrays of simple types via ArrayType
  • Clean up PCPP comments — replace !!HACK!! marker and ambiguous FIXME with accurate descriptions of the actual logic

Documentation

  • Update version references from 2.x to 3.0.0 in BTraceTutorial.md (header) and GettingStarted.md (JBang example, Docker install paths)
  • Add GraalVM Native Image compatibility guide (docs/GraalVMSupport.md) — documents why Native Image is incompatible (no Instrumentation API, no runtime bytecode generation, closed-world assumption), available workarounds (JIT mode, build-time script validation), and deployment recommendations per stage

New feature: OpenTelemetry extension

New btrace-otel extension module following the established extension pattern (api/impl split, @ExtensionDescriptor, @ServiceDescriptor).

  • API: span(name, durationNanos), span(name, attrKey, attrValue, durationNanos), counter(name, value), gauge(name, value)
  • Transport: OTLP/HTTP+JSON via raw HttpURLConnection — zero external dependencies beyond SLF4J
  • Buffering: Lock-free ConcurrentLinkedQueue with configurable async background flush (default 5s interval, 256 batch size)
  • Configuration: System properties btrace.otel.endpoint (default http://localhost:4318), btrace.otel.service.name, btrace.otel.flush.interval.ms, btrace.otel.batch.size
  • Compatible with: Jaeger, Grafana Tempo, Datadog, any OTLP-compatible collector

Commit breakdown

Commit Description Files changed
f80f575 Fix 30+ swallowed exceptions with SLF4J debug logging 7
a8831d9 Fix resource leaks with try-with-resources 2
23e0bde Replace production assertions with proper null checks 4
fabc809 Replace System.err.println with SLF4J logging 7
e708a8d Add dependency vulnerability scanning to CI 1
2aa90fe Improve exception messages and types 5
109e492 Address FIXME/HACK comments in BTraceMBean and PCPP 2
b286ad4 Update documentation version references to 3.0.0 2
6fbada8 Add OpenTelemetry extension module 5
c3c5ea4 Add GraalVM Native Image compatibility documentation 1

Total: 33 files changed, +870 −85

Test plan

  • ./gradlew compileJava — verify clean compilation across all modules including btrace-otel
  • ./gradlew test — full test suite passes
  • btrace-otel produces both -api.jar and shadow impl JAR
  • CI dependency-review job triggers on this PR
  • Spot-check: run with -Dorg.slf4j.simpleLogger.defaultLogLevel=debug to confirm previously-swallowed exceptions now appear in logs
  • GraalVMSupport.md renders correctly on GitHub

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum


This change is Reviewable

claude added 11 commits March 28, 2026 14:18
Thorough analysis of the BTrace codebase identifying the most impactful
fixes, improvements, and new features: swallowed exceptions, resource
leaks, assertion misuse, logging unification, CI security scanning,
exception hierarchy, FIXME completions, docs updates, OpenTelemetry
extension, and GraalVM compatibility.

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
Replace silently ignored catch blocks across 7 files with appropriate
SLF4J debug-level logging. This preserves the fail-safe behavior while
making failures diagnosable in production.

Files fixed:
- CompilerHelper: extension scanning, resource cleanup, class dump
- VerifierVisitor: service jar scanning, permission parsing
- Client: port availability check, socket cleanup, VM properties
- JpsUtils: VM attach/detach operations
- ExtensionBridgeImpl: ServiceLoader lookup, TCCL fallback
- ExtensionInspector: jar metadata reading, permission scanning
- Installer: download attempts, post-install inspection

Also converts CompilerHelper.dump() to try-with-resources.

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
- DOTWriter: prevent FileOutputStream leak if PrintStream constructor
  fails by closing the underlying stream in catch block
- PCPP: wrap #include file reader in try-with-resources to ensure
  BufferedReader is closed after processing included files

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
Java assertions are disabled by default in production JVMs (-ea flag
required). Replace assert statements used for critical null checks with
explicit if-null-throw-IllegalStateException patterns that work
regardless of JVM flags.

- InstrumentingMethodVisitor: opType null check during bytecode analysis
- Indy: repository initialization check in bootstrap method
- Client: protocol null check before command loop
- BTraceRuntimeAccessImpl: runtime wrapper initialization check

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
Convert System.err.println and printStackTrace() calls to proper SLF4J
logging in core infrastructure files. Excludes CLI user-facing output
(usage messages, interactive prompts) and bootstrap code (btrace-boot)
where SLF4J is not available.

Files updated:
- Client.java: attach error logging (debug level)
- BTraceMethodNode.java: unsupported attribute and sampler warnings
- ClassFilter.java: invalid regex pattern errors
- Instrumentor.java: invalid regex pattern errors
- Printer.java: preprocessor ifdef/endif mismatch warnings
- BTraceRuntimeAccessImpl.java: TLS clone and accessor registration
- MethodInvocationRecorder.java: unexpected null record warnings

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
Add a dependency-review job that runs on pull requests to detect
known vulnerabilities in dependency changes. Uses GitHub's
dependency-review-action to fail on high-severity vulnerabilities
and post a summary comment on the PR.

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
- CompilerClassWriter: preserve original exception as cause instead of
  using e.toString() which loses the stack trace entirely
- MemoryJavaFileManager: add context to preprocessing failure message
- Compiler: add context to preprocessing failure message
- WireIO: use IllegalArgumentException for invalid command types
- RemoteClient: use IllegalStateException for class loading failures

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
- BTraceMBean.typeToOpenType(): add array type support for JMX
  OpenType conversion and remove the FIXME comment
- PCPP: replace misleading HACK comment with accurate description
  of the word-token spacing logic
- PCPP: replace FIXME about parenthesized negatives with a clear
  explanation of the tokenizer limitation

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
- BTraceTutorial.md: update header from BTrace 2.3.0 to 3.0.0
- GettingStarted.md: update JBang example version to 3.0.0
- GettingStarted.md: update Docker manual install example to 3.0.0

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
New btrace-otel extension module exports trace spans and metrics via
OTLP/HTTP+JSON to any OpenTelemetry-compatible collector (Jaeger,
Prometheus, Grafana, Datadog, etc.).

API: span(), counter(), gauge() methods. Implementation uses lock-free
queues with async background flush — zero external dependencies beyond
SLF4J (uses raw HttpURLConnection for OTLP transport).

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
Documents current limitations (no java.lang.instrument, no runtime
bytecode generation), available workarounds (JIT mode, build-time
script validation), and recommendations for each deployment stage.

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 28, 2026

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 1 package(s) with unknown licenses.
See the Details below.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA b8683e9.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

License Issues

.github/workflows/continuous.yml

PackageVersionLicenseIssue Type
actions/dependency-review-action4.*.*NullUnknown License

OpenSSF Scorecard

PackageVersionScoreDetails
actions/actions/dependency-review-action 4.*.* 🟢 7.8
Details
CheckScoreReason
Security-Policy🟢 9security policy file detected
Code-Review🟢 10all changesets reviewed
Binary-Artifacts🟢 10no binaries found in the repo
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Packaging⚠️ -1packaging workflow not detected
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Pinned-Dependencies⚠️ 1dependency not pinned by hash detected -- score normalized to 1
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Branch-Protection🟢 6branch protection is not maximal on development and all release branches
SAST🟢 10SAST tool is run on all commits

Scanned Files

  • .github/workflows/continuous.yml

@jbachorik jbachorik changed the title Add comprehensive project review with top 10 improvements Harden error handling, unify logging, add OpenTelemetry extension, and improve docs Mar 28, 2026
claude added 4 commits March 28, 2026 15:11
Added SLF4J as an explicit dependency since Gradle's implementation
scope doesn't expose it transitively from btrace-core/btrace-agent.
Required because ExtensionInspector and Installer now use SLF4J logging.

https://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
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.

2 participants