Skip to content

try-except more things#756

Merged
tammy-baylis-swi merged 7 commits intomainfrom
try-except-more-scenarios
Apr 16, 2026
Merged

try-except more things#756
tammy-baylis-swi merged 7 commits intomainfrom
try-except-more-scenarios

Conversation

@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Apr 14, 2026

Adds more exception handling to prevent distro crashing instrumented app, even if theoretical. Logs warning or debug, depending on similar existing logs. Adds a bit of test coverage.

What do you think of this?: I'm keeping the raise in JsonSampler (restored in fcfb05c) because something is very wrong with the environment. Or, we can log an error once and return [].

Will be doing an apm_config update in a separate PR because that needs some extra test coverage: #757

@tammy-baylis-swi tammy-baylis-swi marked this pull request as ready for review April 14, 2026 16:36
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner April 14, 2026 16:36
Copilot AI review requested due to automatic review settings April 14, 2026 16:36
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner April 14, 2026 16:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the SolarWinds APM distribution against unexpected input/runtime failures by adding defensive exception handling in multiple parsing and sampling-related code paths, aiming to prevent the distro from crashing instrumented applications.

Changes:

  • Add try/except guards around various header/config parsing and conversion operations (trace options, span/trace flags, HTTP status code, service key token extraction).
  • Improve resiliency of sampling settings ingestion (JSON file/HTTP response parsing) and hostname discovery.
  • Add targeted logging when exceptional/invalid inputs are encountered.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
solarwinds_apm/w3c_transformer.py Adds exception handling to span-id extraction from SW tracestate value.
solarwinds_apm/traceoptions.py Adds guarded parsing of x-trace-options and more robust ts handling.
solarwinds_apm/oboe/trace_options.py Wraps signature digest creation with exception handling and warning log.
solarwinds_apm/oboe/sampler.py Guards HTTP status-code integer conversion when building span metadata.
solarwinds_apm/oboe/oboe_sampler.py Guards parsing of trace flags from trace_state in parent-based sampling.
solarwinds_apm/oboe/json_sampler.py Logs on invalid JSON settings file parse and re-raises.
solarwinds_apm/oboe/http_sampler.py Adds hostname fallback on failure and catches JSON decode errors when parsing collector responses.
solarwinds_apm/distro.py Guards service key split to avoid crashing on unexpected types.
solarwinds_apm/apm_logging.py Guards parsing of SW_APM_DEBUG_LEVEL to avoid exceptions.

Comment thread solarwinds_apm/oboe/http_sampler.py
Comment thread solarwinds_apm/oboe/http_sampler.py
Comment thread solarwinds_apm/traceoptions.py
Comment thread solarwinds_apm/traceoptions.py
Comment thread solarwinds_apm/w3c_transformer.py Outdated
Comment thread solarwinds_apm/w3c_transformer.py Outdated
Comment thread solarwinds_apm/oboe/json_sampler.py Outdated
Comment thread tests/unit/test_w3c_transformer.py Fixed
…ral'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and agree on the reverted change for json_sampler, since _read() is called in an already guarded try/except that would catch the decode error.

@tammy-baylis-swi tammy-baylis-swi merged commit c4f6dda into main Apr 16, 2026
64 checks passed
@tammy-baylis-swi tammy-baylis-swi deleted the try-except-more-scenarios branch April 16, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants