Skip to content

Internal - Use pre-computed transaction name from span attributes#479

Merged
cleverchuk merged 1 commit into
mainfrom
cc/NH-135557
May 1, 2026
Merged

Internal - Use pre-computed transaction name from span attributes#479
cleverchuk merged 1 commit into
mainfrom
cc/NH-135557

Conversation

@cleverchuk
Copy link
Copy Markdown
Contributor

TLDR

Short-circuit buildTransactionName when a sw.transaction attribute already exists on the span, avoiding redundant name resolution. Consolidate TRANSACTION_NAME_KEY and LEGACY_TRANSACTION_NAME_KEY into SharedNames as typed AttributeKey<String> constants.

Motivation

InboundMeasurementMetricsGenerator.onEnding computes and sets the transaction name on the span via setAttribute. However, if the span is later read again (e.g., by metrics recording in onEnd), buildTransactionName re-executes the full resolution chain — custom dictionary lookup, naming scheme, handler name, http.route, URL pattern extraction — even though the answer is already sitting in the span's attributes. This is wasted work.

What changed

Early-return on pre-computed name: buildTransactionName now checks spanAttributes.get(TRANSACTION_NAME_KEY) first. If a non-null, non-empty value exists, it returns immediately. This makes the already-set sw.transaction attribute the highest-priority source in the resolution chain, ahead of custom dictionary names, naming schemes, and URL-based derivation.

Type promotion of shared constants: TRANSACTION_NAME_KEY was previously a plain String in SharedNames and each consumer independently wrapped it with AttributeKey.stringKey(...). It is now declared as AttributeKey<String> directly, eliminating the repeated wrapping. LEGACY_TRANSACTION_NAME_KEY ("TransactionName") was a private constant in InboundMeasurementMetricsGenerator and is now shared alongside it.

Resolution priority order (unchanged except for the new first step):

  1. Pre-computed sw.transaction span attribute (new)
  2. Custom transaction name dictionary (CustomTransactionNameDict)
  3. Naming scheme (NamingScheme.createName)
  4. Handler name (e.g., Spring MVC)
  5. http.route
  6. URL pattern extraction
  7. Span name fallback

Tests

Three new tests cover the pre-computed name path:

  • Returns pre-computed name when sw.transaction attribute is present
  • Falls back to standard resolution when attribute value is empty
  • Falls back to standard resolution when attribute is absent

Test services data

  1. e-1712644058766987264
  2. e-1712643928659124224
  3. e-1742334541200846848
  4. e-1777406072376840192

Copilot AI review requested due to automatic review settings May 1, 2026 17:40
@cleverchuk cleverchuk requested review from a team as code owners May 1, 2026 17:40
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 optimizes transaction-name resolution in the shared extensions by short-circuiting TransactionNameManager.buildTransactionName(...) when the transaction name is already present on the span, and centralizes transaction-name attribute keys in SharedNames.

Changes:

  • Add an early-return in TransactionNameManager.buildTransactionName(...) when sw.transaction is already set on the span.
  • Promote TRANSACTION_NAME_KEY (and add LEGACY_TRANSACTION_NAME_KEY) into SharedNames as typed AttributeKey<String> constants, and update consumers/tests accordingly.
  • Add unit tests covering the pre-computed transaction-name behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
libs/shared/src/main/java/com/solarwinds/opentelemetry/extensions/TransactionNameManager.java Early-return when sw.transaction is already present on the span attributes.
libs/shared/src/main/java/com/solarwinds/opentelemetry/extensions/SharedNames.java Converts transaction name constants to AttributeKey<String> and adds legacy key constant.
libs/shared/src/main/java/com/solarwinds/opentelemetry/extensions/InboundMeasurementMetricsGenerator.java Switches to shared AttributeKey constants for setting transaction-name attributes.
libs/shared/src/test/java/com/solarwinds/opentelemetry/extensions/InboundMeasurementMetricsGeneratorTest.java Updates assertions to use the typed shared attribute key.
libs/shared/src/test/java/com/solarwinds/opentelemetry/extensions/TransactionNameManagerTest.java New tests for pre-computed transaction name and fallback behavior.

Copy link
Copy Markdown

@jerrytfleung jerrytfleung left a comment

Choose a reason for hiding this comment

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

LGTM

@cleverchuk cleverchuk merged commit 8d1e490 into main May 1, 2026
20 checks passed
@cleverchuk cleverchuk deleted the cc/NH-135557 branch May 1, 2026 18:46
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.

3 participants