Internal - address code scanning and removed dead code#462
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Removes legacy thread-local context handling and dead code in the core Context/Event flow, shifting metadata derivation to the active OpenTelemetry SpanContext, while also addressing code-scanning findings and re-enabling profiling smoke-test verification.
Changes:
- Simplified
Contextto deriveMetadatafromSpan.current().getSpanContext()and removed deprecated context mutation / dead factory methods. - Updated callers/tests to pass
Metadataexplicitly into event creation/reporting and adjusted settings parsing API (readFromByteBufferrename). - Re-enabled profiling smoke tests by enabling the profiler in agent config and adding a new k6-based GraphQL verification path.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| smoke-tests/src/test/java/com/solarwinds/agents/Agent.java | Enables profiler flags for smoke-test agents. |
| smoke-tests/src/test/java/com/solarwinds/SmokeTestV2.java | Re-enables code profiling assertion. |
| smoke-tests/src/test/java/com/solarwinds/SmokeTest.java | Re-enables code profiling assertion. |
| smoke-tests/k6/basic.js | Adds new GraphQL-based profiling verification and removes old NewFrames property check. |
| libs/sampling/src/test/java/com/solarwinds/joboe/sampling/SettingsArgTest.java | Updates tests for renamed settings parsing API. |
| libs/sampling/src/main/java/com/solarwinds/joboe/sampling/TraceConfigs.java | Adds toString() for improved diagnostics. |
| libs/sampling/src/main/java/com/solarwinds/joboe/sampling/SettingsArg.java | Renames readValue(ByteBuffer) to readFromByteBuffer(ByteBuffer). |
| libs/sampling/src/main/java/com/solarwinds/joboe/sampling/SamplingConfiguration.java | Adds toString() for improved diagnostics. |
| libs/sampling/src/main/java/com/solarwinds/joboe/sampling/Metadata.java | Makes Metadata(SpanContext) fully initialize fields without isValid() gating. |
| libs/core/src/test/java/com/solarwinds/joboe/core/rpc/RpcClientTest.java | Updates tests to explicitly construct/pass Metadata into event creation. |
| libs/core/src/test/java/com/solarwinds/joboe/core/TestReporterTest.java | Removes thread-local setup helper and reports with explicit Metadata. |
| libs/core/src/test/java/com/solarwinds/joboe/core/EventImplTest.java | Updates tests for explicit Metadata usage and removes thread-local cleanup. |
| libs/core/src/test/java/com/solarwinds/joboe/core/ContextTest.java | Removes inheritance/thread-local tests and updates for explicit Metadata usage. |
| libs/core/src/main/java/com/solarwinds/joboe/core/util/TimeUtils.java | Code-scanning-driven change to getSum() boxing behavior. |
| libs/core/src/main/java/com/solarwinds/joboe/core/util/ServerHostInfoReader.java | Removes obsolete context save/restore and dead code; modernizes collections/line separator usage. |
| libs/core/src/main/java/com/solarwinds/joboe/core/rpc/RpcSettings.java | Updates settings argument parsing to use readFromByteBuffer. |
| libs/core/src/main/java/com/solarwinds/joboe/core/NoopEvent.java | Removes obsolete report(EventReporter) overload implementation. |
| libs/core/src/main/java/com/solarwinds/joboe/core/EventImpl.java | Removes obsolete report(EventReporter) overload. |
| libs/core/src/main/java/com/solarwinds/joboe/core/Event.java | Removes obsolete report(EventReporter) overload from API. |
| libs/core/src/main/java/com/solarwinds/joboe/core/Context.java | Removes thread-local context state; derives Metadata from OTel SpanContext. |
| custom/src/main/java/com/solarwinds/opentelemetry/extensions/SolarwindsProfilingSpanProcessor.java | Minor refactor (inline single-use local) in profiling span processor. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…event ClassCastException Agent-Logs-Url: https://github.com/solarwinds/apm-java/sessions/f03ea42c-8a1f-4a6a-bb03-e05afe58844b Co-authored-by: cleverchuk <15526124+cleverchuk@users.noreply.github.com>
jerrytfleung
approved these changes
Apr 15, 2026
jerrytfleung
left a comment
There was a problem hiding this comment.
LGTM. I like the explicit metadata in report function that making more sense on metadata handling.
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
Remove dead code from the
Contextclass and address code scanning findings across core and sampling modules. TheContextclass no longer maintains its own thread-local metadata state — it now delegates entirely to the current OpenTelemetrySpanContext. Code profiling smoke tests are re-enabled with a new dedicated verification approach.Dead Code Removal —
ContextclassInheritableThreadLocal<Metadata>and all associated thread-local context management (setMetadata,clearMetadata,setSkipInheritingContext,skipInheritingContextThreadLocal)SettingsArg.DISABLE_INHERIT_CONTEXTlistener that toggled context inheritance behaviorcreateEvent(),createEventWithID(),createEventWithIDAndContext(),createEventWithGeneratedMetadata()getMetadata()now simply constructs aMetadatafrom the current OTelSpan.current().getSpanContext()instead of reading from thread-local storageEvent.report(EventReporter)single-arg overload (and its implementations inEventImplandNoopEvent) — callers now always pass theMetadataexplicitlyCode Scanning Fixes
Metadata(SpanContext)constructor: removed theisValid()guard — the caller is responsible for validity; this avoids leaving fields in an inconsistent half-initialized stateTimeUtils.getSum(): replaced autoboxing of primitiveDouble→doubleand explicitDouble.valueOf()to avoid unnecessary boxing flagged by code scanningSolarwindsProfilingSpanProcessor: inlined a single-use local variable (spanContext) to reduce scopeServerHostInfoReader.getHostId(): removed theContext.clearMetadata()/setMetadata()save-restore pattern that was guarding against accidental tracing during init — no longer needed sinceContextdoesn't hold mutable stategetDockerContainerId()method andHOSTNAME_SEPARATORconstant fromServerHostInfoReadernew HashMap<String, String>()→new HashMap<>()) andSystem.getProperty("line.separator")→System.lineSeparator()@param/@returnjavadoc tagsSettingsArgRenamereadValue(ByteBuffer)method toreadFromByteBuffer(ByteBuffer)across allSettingsArgsubtypes to disambiguate it from thereadValue(Object)overloadObservability Additions
@ToString(Lombok) toSamplingConfigurationandTraceConfigsfor better logging/debugging visibilitySmoke Test — Code Profiling
assertCodeProfilingtest (removed@Disabled) in bothSmokeTestandSmokeTestV2verify_profilefunction in the k6 script that queries the SWO GraphQL API for spans withsw.profile.spans:1, replacing the previous inline property check (NewFrameskey)-Dsw.apm.profiler.enabled=true,-Dsw.apm.profiler.interval=10)Test Updates
Metadatainstances andcreateEventWithContext(metadata)/report(metadata, reporter)instead of the removedContext.createEvent()/event.report(reporter)patternstestInheritContexttest andTestThreadhelper class since thread-local context inheritance no longer existsstartTrace()helper methods fromEventImplTestandTestReporterTest— replaced with inline metadata setupTest services data