Skip to content

Commit

Permalink
Merge pull request #121 from solarwindscloud/NH-34221-del-xto-respons…
Browse files Browse the repository at this point in the history
…e-only-if-present

NH-34221 delete xtraceoptions response from tracestate only if present
  • Loading branch information
tammy-baylis-swi authored Mar 9, 2023
2 parents c269848 + 14f9dd3 commit 69f75be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/solarwindscloud/solarwinds-apm-python/compare/rel-0.8.1...HEAD)
### Changed
- Fixed noisy trace state KV deletion attempts when key not present ([#121](https://github.com/solarwindscloud/solarwinds-apm-python/pull/121))

## [0.8.1](https://github.com/solarwindscloud/solarwinds-apm-python/releases/tag/rel-0.8.1) - 2023-03-08
### Changed
Expand Down
4 changes: 3 additions & 1 deletion solarwinds_apm/w3c_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ def sw_from_span_and_decision(cls, span_id: int, decision: str) -> str:
@classmethod
def remove_response_from_sw(cls, trace_state: TraceState) -> TraceState:
"""Remove xtraceoptions response from tracestate"""
return trace_state.delete(INTL_SWO_X_OPTIONS_RESPONSE_KEY)
if trace_state.get(INTL_SWO_X_OPTIONS_RESPONSE_KEY):
trace_state = trace_state.delete(INTL_SWO_X_OPTIONS_RESPONSE_KEY)
return trace_state
6 changes: 5 additions & 1 deletion tests/unit/test_w3c_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def test_sw_from_span_and_decision(self):
assert W3CTransformer.sw_from_span_and_decision(1234, "01") \
== "{:016x}-{}".format(1234, "01")

def test_remove_response_from_sw(self):
def test_remove_response_from_sw_key_present(self):
ts = TraceState([["bar", "456"],["xtrace_options_response", "123"]])
assert W3CTransformer.remove_response_from_sw(ts) == TraceState([["bar", "456"]])

def test_remove_response_from_sw_key_absent(self):
ts = TraceState([["bar", "456"]])
assert W3CTransformer.remove_response_from_sw(ts) == TraceState([["bar", "456"]])

0 comments on commit 69f75be

Please sign in to comment.