Harden error handling, unify logging, add OpenTelemetry extension, and improve docs #808
Open
Harden error handling, unify logging, add OpenTelemetry extension, and improve docs #808
Conversation
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
Dependency ReviewThe following issues were found:
Snapshot WarningsEnsure 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
OpenSSF Scorecard
Scanned Files
|
This reverts commit 6fbada8.
This reverts commit 0afc422.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
catch (Exception ignored) {}blocks now log at DEBUG level via SLF4J, making failures diagnosable without impacting production performance#includereader is never closed. Both converted to safe resource managementassertstatements withIllegalStateExceptionnull checks in BTraceRuntimeAccessImpl, InstrumentingMethodVisitor, Indy, and Client —assertis silently disabled by default in production JVMsCompilerClassWriterwas throwingnew RuntimeException(e.toString()), discarding the entire causal stack trace. Now wraps with descriptive message and original causeIllegalArgumentExceptionfor invalid command types (WireIO),IllegalStateExceptionfor class loading failures (RemoteClient), replacing bareRuntimeExceptionLogging
System.err.printlnwith 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
dependency-reviewjob incontinuous.ymlusingactions/dependency-review-action@v4, runs on PRs, fails on high-severity CVEs, posts summary commentCode quality
typeToOpenType()had aFIXME: This is highly incompletefor array types. Now handles arrays of simple types viaArrayType!!HACK!!marker and ambiguousFIXMEwith accurate descriptions of the actual logicDocumentation
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 stageNew feature: OpenTelemetry extension
New
btrace-otelextension module following the established extension pattern (api/impl split,@ExtensionDescriptor,@ServiceDescriptor).span(name, durationNanos),span(name, attrKey, attrValue, durationNanos),counter(name, value),gauge(name, value)HttpURLConnection— zero external dependencies beyond SLF4JConcurrentLinkedQueuewith configurable async background flush (default 5s interval, 256 batch size)btrace.otel.endpoint(defaulthttp://localhost:4318),btrace.otel.service.name,btrace.otel.flush.interval.ms,btrace.otel.batch.sizeCommit breakdown
f80f575a8831d923e0bdefabc809e708a8d2aa90fe109e492b286ad46fbada8c3c5ea4Total: 33 files changed, +870 −85
Test plan
./gradlew compileJava— verify clean compilation across all modules including btrace-otel./gradlew test— full test suite passes-api.jarand shadow impl JAR-Dorg.slf4j.simpleLogger.defaultLogLevel=debugto confirm previously-swallowed exceptions now appear in logshttps://claude.ai/code/session_01UDRNChW9GhRia9L7sa6yum
This change is