Configure New Relic
This topic describes the integration that lets you associate an Optimizely feature flag, variation, or experiment with New Relic performance data.
You can track and monitor New Relic data and additionally segment the experiences delivered by Optimizely.
Using Optimizely’s notification listeners, you can forward events that occur in the SDK using your New Relic custom attributes.
In the example code below, we add a call to New Relic in the activate callback function. This can be placed directly after initializing the Optimizely client. This assumes a New Relic object is in scope.
todo: is this PYTHON code sample actually correct? I just mocked it up as POC -felliott
(I didn't touch the javascript example)
const optimizely = require('@optimizely/optimizely-sdk');
const optimizelyEnums = require('@optimizely/optimizely-sdk/lib/utils/enums');
const newrelic = require('newrelic');
function onActivate(activateObject) {
newrelic.addCustomAttributes({
'optimizely_segment': activateObject.experiment['key']);
});
}
// Add a ACTIVATE notification listener
let activateId = optly.notificationCenter.addNotificationListener(
optimizelyEnums.NOTIFICATION_TYPES.ACTIVATE,
onActivate
);
from optimizely.notification_center import NotificationCenter
from optimizely.helpers import enums
import newrelic
def on_decision(decision_type, user_id, attributes, decision_info):
# send only decisions that resulted in impressions
if decision_type == 'flag' and decision_info.get('decision_event_dispatched') == true:
newrelic_obj.agent.add_custom_parameter(‘optimizely_segment’, variation)
opt_obj.notification_center.add_notification_listener(enums.NotificationTypes.DECISION, on_decision)
Updated 2 months ago