New Relic agent APIs

Extend agent functionality, collect custom data, and control asset behavior

The New Relic APM, Browser, and Mobile agents each include a variety of APIs for custom data reporting. Since the New Relic agents are included as part of your code, these APIs are immediately available to all New Relic users.

The following demonstrates core APIs and syntax for doing common activities like creating custom attributes and events via the agents, but note that each agent has a rich set of capabilities to control behavior and track data.

APM - Go: 

// Add custom attributes
txn.AddAttribute("MyCustomAttribute", "Example");

// Add custom events
app.RecordCustomEvent("my_custom_event", map[string]interface{}{
  "MyStringAttribute": "hello",
  "MyFloatAttribute":   0.603,
  "MyIntAttribute":     123,
  "MyBoolAttribute":    true,

APM - Java: 

// Add custom attributes
NewRelic.addCustomParameter("MyStringAttribute", "Example");
NewRelic.addCustomParameter("MyNumberAttribute", 2.4);

// Add custom events
Map<String, Object> eventAttributes = new HashMap<String, Object>();
NewRelic.getAgent().getInsights().recordCustomEvent("MyCustomEvent", eventAttributes);

APM - .NET: 

// Add custom attributes
NewRelic.Api.Agent.AddCustomParameter("MyStringAttribute", "Example);
NewRelic.Api.Agent.AddCustomParameter("MyNumberAttribute", (Single)2.4);

// Add custom events
var eventAttributes = new Dictionary<String, Object>();
NewRelic.Api.Agent.NewRelic.RecordCustomEvent("MyCustomEvent", eventAttributes);

APM - Node.js: 

// Add custom attributes
  "MyStringAttribute": "Example",
  "MyNumberAttribute": 2.4

// Add custom events
recordCustomEvent("MyCustomEvent", {
  "MyStringAttribute": "Example",
  "MyNumberAttribute": 2.4


// Add custom attributes
newrelic_add_custom_parameter ('MyCustomAttribute', 'Example')

// Add custom events
newrelic_record_custom_event("MyCustomEvent", array("color"=>"red", "weight"=>12.5));

APM - Python: 

# Add custom attributes
newrelic.agent.add_custom_parameter('MyCustomAttribute', 'Example')

# Add custom events
newrelic.agent.record_custom_event('MyCustomEvent', params, application=None)

APM - Ruby: 

# Add custom attributes v3.12.0 and above
::NewRelic::Agent.add_custom_attributes({ my_custom_attribute: 'Example' })

# Add custom events
::NewRelic::Agent.record_custom_event('MyCustomEvent', color: 'red', weight: 12.5)


// Add custom attributes
newrelic.setCustomAttribute('MyCustomAttribute', 'Example');

// Add custom events (note that Browser uses a single event type 'page action instead of the raw custom event
newrelic.addPageAction('my_custom_page_action', { color: 'red' });

Mobile - Android: 

// Add custom attributes
NewRelic.setAttribute(“MyCustomAttribute”, "Example");

// Add custom events
Map attributes = new HashMap();
boolean eventRecorded = NewRelic.recordCustomEvent("MyCustomEvent", attributes);

Mobile - Objective-C: 

// Add custom attributes
BOOL attributeSet = [NewRelic setAttribute:@"MyCustomAttribute" value:@"Example"];

// Add custom events
BOOL eventRecorded = [NewRelic recordCustomEvent:@"MyCustomEvent"
attributes:@{@"color1": @"red1", @"weight": @2.4}];

Mobile - Swift: 

// Add custom attributes
var attributeSet = NewRelic.setAttribute("MyCustomAttribute", value: "Example");

// Add custom events
let eventRecorded = NewRelic.recordCustomEvent("MyCustomEvent", attributes: ["color" : "red", "weight": 2.4])

Learn more and start building

Group 7 Created with Sketch.


For an overview of all New Relic agent APIs, see Introduction to New Relic APIs, which links to the documentation for each product and agent.

Group 9 Created with Sketch.

NRU Tutorials

To learn how to make the most of our developer resources, check out New Relic University.

Group 8 Created with Sketch.

Community Forum

Connect with other developers in the New Relic Explorers Hub


For examples of integrations and other technologies, see our GitHub repo.