NH-125600 Add integration tests for set_transaction_name - #832
Open
tammy-baylis-swi wants to merge 9 commits into
Open
NH-125600 Add integration tests for set_transaction_name#832tammy-baylis-swi wants to merge 9 commits into
tammy-baylis-swi wants to merge 9 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds new integration test coverage for the public solarwinds_apm.api.set_transaction_name() API, including basic/edge-case behavior and a two-service (distributed trace) scenario using Flask + requests instrumentation.
Changes:
- Introduces integration tests validating that
set_transaction_name()setssw.transactionon the service entry span and that “last call wins”. - Adds edge-case tests for invalid names (empty/None), calling outside an active span, and long-name truncation.
- Adds a distributed trace test harness with a second Flask app to validate independent custom transaction names per service entry span.
Comments suppressed due to low confidence (4)
tests/integration/test_set_transaction_name.py:315
- After shutting down the WSGI server thread, the listening socket should be closed to reliably free the port between tests/processes (especially when binding to an ephemeral port).
def tearDown(self):
self.server.shutdown()
self.server_thread.join(timeout=1)
super().tearDown()
tests/integration/test_set_transaction_name.py:424
- Same as above: use the dynamically allocated server port and a short timeout to prevent hung test runs if the downstream service is unavailable.
resp = requests.get("http://127.0.0.1:5001/service_b_manual/")
return f"service-a-response: {resp.text}"
tests/integration/test_set_transaction_name.py:442
- This test also assumes a deterministic ordering of exported spans. To avoid flakiness, assert on the set of entry-span transaction names rather than their positions in the list.
assert len(entry_spans) == 2
# leaf-most entry span will be first
assert entry_spans[0].attributes.get(INTL_SWO_TRANSACTION_ATTR_KEY) == "custom-service-b"
assert entry_spans[1].attributes.get(INTL_SWO_TRANSACTION_ATTR_KEY) == "custom-service-a"
tests/integration/test_set_transaction_name.py:448
- The manual-span assertions depend on exporter ordering (and cross-thread timing between services). This can be flaky; assert on the set of expected span names instead.
manual_spans = [s for s in spans if s.name.startswith("manual-")]
assert len(manual_spans) == 4
assert manual_spans[0].name == "manual-inner-b"
assert manual_spans[1].name == "manual-outer-b"
assert manual_spans[2].name == "manual-inner-a"
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
tests/integration/test_base_sw_headers_attrs.py:131
set_meter_provider(self.meter_provider)mutates OpenTelemetry global state, but this base class never resets it. That can leak the in-memoryMeterProviderinto other tests (especially ones that don't callreset_metrics_globals()), causing cross-test interference and flakiness. Add a cleanup right after setting the provider (or reset in tearDown) so the global meter provider is restored for subsequent tests.
self.metric_reader = InMemoryMetricReader()
self.meter_provider = MeterProvider(metric_readers=[self.metric_reader])
set_meter_provider(self.meter_provider)
tests/integration/test_set_transaction_name.py:437
- The Werkzeug server is shut down but the listening socket is never explicitly closed. With a fixed port, this can leave the port bound (or delay reuse) and cause subsequent tests to fail with "Address already in use". Also, if setUp fails before
self.serveris created, this tearDown will raise and can mask the real failure. Close the server and guard teardown cleanup.
def tearDown(self):
self.server.shutdown()
self.server_thread.join(timeout=1)
super().tearDown()
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.
Adds missing integration tests for
set_transaction_name, includingTestSetTransactionNameDistributed. Latter uses test base class' Flask app plus a second Flask app for asserting txn name of each entry span in a distributed trace, and txn name on response_time metrics. Only tests synchronous scenarios.