Enriching New Relic APM Traces with Business Context Using Custom Attributes
Learn how to enrich New Relic APM traces with business context using custom attributes, see a Java code example, verify in the UI, and understand the cardinality and sensitivity trade‑offs.
02 Feb 2026, 01:06 UTC

Problem: Missing the business side of performance data
When you instrument a service with New Relic APM you get detailed timing and error information, but the trace view often lacks the business details that explain why a request is slow. Without knowing the user ID, order value, or feature‑flag state attached to a transaction, you cannot easily correlate latency spikes with specific customer segments or business outcomes.
Thesis
New Relic’s custom attributes feature lets you attach arbitrary key‑value pairs to each APM transaction. Those attributes appear in the transaction trace UI, can be used for filtering, grouping, and alerting, and give you the business context you need to turn performance data into actionable insight.
1. Adding a custom attribute in a Java service
The New Relic Java agent (version 8.x or later) provides the TracedMethod API for adding attributes at runtime. The attribute is sent with the next harvest cycle and becomes visible on the transaction details page.
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.TracedMethod;
public class OrderService {
public void placeOrder(Order order, String userId) {
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
if (traced != null) {
// Low‑cardinality, business‑relevant keys
traced.addAttribute("userId", userId);
traced.addAttribute("orderValue", order.getTotalCents());
traced.addAttribute("featureFlag\"newCheckout\"", isNewCheckoutEnabled(userId));
}
// existing order processing logic
}
}
Place the snippet inside any method you want to trace (e.g., a controller method, service method, or async task). The agent automatically captures the attribute for the surrounding transaction.
2. Verifying the attribute in the UI
- Deploy the updated code to your environment.
- Exercise the instrumented path (e.g., place a test order).
- In New Relic go to APM → Transactions, select the transaction type (e.g.,
OrderService.placeOrder), and open a recent trace. - Under the Attributes section you should see the keys
userId,orderValue, andfeatureFlag_newCheckoutwith the values you set.
To confirm that the attribute can be used for filtering, open the query builder on the Transactions page and add a condition like attribute userId = '12345'. The resulting list should show only traces where that user ID was attached.
3. Using attributes for alerting and dashboards
Once the attribute is available, you can create NRQL alerts that fire when a specific business segment experiences high latency. Example NRQL:
SELECT duration FROM Transaction WHERE appName = 'OrderService' AND attribute userId = 'VIP_123' SINCE 5 minutes ago COMPARE WITH 5 minutes ago
You can also group charts by attribute orderValue to see how latency scales with order size, or create a dashboard that shows the percentage of transactions with featureFlag_newCheckout = true that exceed a latency threshold.
Trade‑offs and limitations
- Cardinality risk: High‑cardinality values (e.g., timestamps, UUIDs, or raw request IDs) cause the agent to generate many unique attribute combinations, which can hit New Relic’s custom‑attribute limits and increase ingestion costs. Stick to low‑cardinality, business‑relevant keys such as user IDs (if the user base is limited), order‑value buckets, or feature‑flag names.
- Overhead: Each attribute adds a small amount of CPU and memory overhead per transaction. In practice the impact is negligible for a handful of attributes, but profiling under load is recommended if you plan to add dozens.
- Data sensitivity: Avoid attaching personally identifiable information (PII) like email addresses, passwords, or raw credit‑card numbers. New Relic retains data according to its retention policies, and exposing PII could violate compliance requirements.
- Attribute name limit: The default account allows a few dozen distinct custom attribute names per application. Keep the set of names stable and review periodically to avoid unexpected drops in data granularity.
Actionable closing
To start using custom attributes today:
- Confirm your New Relic Java agent is version 8.x or later (
newrelic.ymlshowslicense_keyandapp_name). - Add the
TracedMethod.addAttributecalls for the business keys you need. - Deploy, generate traffic, and verify the attributes appear in the trace UI.
- Create a simple NRQL alert or dashboard chart that filters by one of the attributes to ensure the data is useful.
- Monitor attribute cardinality in the Metrics → Custom Attributes view and adjust keys if you see rapid growth.
By attaching low‑cardinality, business‑relevant key‑value pairs to each transaction, you turn raw performance data into a signal that directly connects latency to the experiences of your users and the outcomes of your business.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.