Internal - Use pre-computed transaction name from span attributes#479
Merged
Conversation
Contributor
There was a problem hiding this comment.
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(...)whensw.transactionis already set on the span. - Promote
TRANSACTION_NAME_KEY(and addLEGACY_TRANSACTION_NAME_KEY) intoSharedNamesas typedAttributeKey<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. |
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.
TLDR
Short-circuit
buildTransactionNamewhen asw.transactionattribute already exists on the span, avoiding redundant name resolution. ConsolidateTRANSACTION_NAME_KEYandLEGACY_TRANSACTION_NAME_KEYintoSharedNamesas typedAttributeKey<String>constants.Motivation
InboundMeasurementMetricsGenerator.onEndingcomputes and sets the transaction name on the span viasetAttribute. However, if the span is later read again (e.g., by metrics recording inonEnd),buildTransactionNamere-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:
buildTransactionNamenow checksspanAttributes.get(TRANSACTION_NAME_KEY)first. If a non-null, non-empty value exists, it returns immediately. This makes the already-setsw.transactionattribute 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_KEYwas previously a plainStringinSharedNamesand each consumer independently wrapped it withAttributeKey.stringKey(...). It is now declared asAttributeKey<String>directly, eliminating the repeated wrapping.LEGACY_TRANSACTION_NAME_KEY("TransactionName") was a private constant inInboundMeasurementMetricsGeneratorand is now shared alongside it.Resolution priority order (unchanged except for the new first step):
sw.transactionspan attribute (new)CustomTransactionNameDict)NamingScheme.createName)http.routeTests
Three new tests cover the pre-computed name path:
sw.transactionattribute is presentTest services data