Skip to content

NH-125600 Add integration tests for set_transaction_name - #832

Open
tammy-baylis-swi wants to merge 9 commits into
mainfrom
NH-125600-set-txn-name-tests
Open

NH-125600 Add integration tests for set_transaction_name#832
tammy-baylis-swi wants to merge 9 commits into
mainfrom
NH-125600-set-txn-name-tests

Conversation

@tammy-baylis-swi

@tammy-baylis-swi tammy-baylis-swi commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Adds missing integration tests for set_transaction_name, including TestSetTransactionNameDistributed. 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.

@tammy-baylis-swi
tammy-baylis-swi marked this pull request as ready for review July 30, 2026 00:21
@tammy-baylis-swi
tammy-baylis-swi requested a review from a team as a code owner July 30, 2026 00:21
Copilot AI review requested due to automatic review settings July 30, 2026 00:21
@tammy-baylis-swi
tammy-baylis-swi requested a review from a team as a code owner July 30, 2026 00:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() sets sw.transaction on 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"

Comment thread tests/integration/test_set_transaction_name.py
Comment thread tests/integration/test_set_transaction_name.py Outdated
Comment thread tests/integration/test_set_transaction_name.py Outdated
Comment thread tests/integration/test_set_transaction_name.py Outdated
Comment thread tests/integration/test_set_transaction_name.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-memory MeterProvider into other tests (especially ones that don't call reset_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.server is 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()

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.

2 participants