How to use the newrelic.createTracer function in newrelic

To help you get started, we’ve selected a few newrelic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lifechurch / melos / feature-server.js View on Github external
import reactCookie from 'react-cookie'
import bodyParser from 'body-parser'
import { tokenAuth } from '@youversion/js-api'
import { IntlProvider } from 'react-intl'
import moment from 'moment'
import Raven from 'raven'

import planLocales from './locales/config/planLocales.json'
import revManifest from './rev-manifest.json'

const urlencodedParser = bodyParser.json()
const router = express.Router()
const availableLocales = require('./locales/config/availableLocales.json');
const localeList = require('./locales/config/localeList.json');

const getAssetPath = nr.createTracer('fnGetAssetPath', (path) => {
	const IS_PROD = process.env.NODE_ENV === 'production';
	if (IS_PROD) {
		return revManifest[path];
	} else {
		return path;
	}
})

const checkAuth = nr.createTracer('fnCheckAuth', (auth) => {
	return new Promise((resolve, reject) => {
		if (typeof auth === 'object' && typeof auth.token === 'string') {
			// We have a token
			try {
				const token = auth.token
				const tokenData = tokenAuth.decodeToken(token)
				const sessionData = tokenAuth.decryptToken(tokenData.token)
github lifechurch / melos / feature-server.js View on Github external
const urlencodedParser = bodyParser.json()
const router = express.Router()
const availableLocales = require('./locales/config/availableLocales.json');
const localeList = require('./locales/config/localeList.json');

const getAssetPath = nr.createTracer('fnGetAssetPath', (path) => {
	const IS_PROD = process.env.NODE_ENV === 'production';
	if (IS_PROD) {
		return revManifest[path];
	} else {
		return path;
	}
})

const checkAuth = nr.createTracer('fnCheckAuth', (auth) => {
	return new Promise((resolve, reject) => {
		if (typeof auth === 'object' && typeof auth.token === 'string') {
			// We have a token
			try {
				const token = auth.token
				const tokenData = tokenAuth.decodeToken(token)
				const sessionData = tokenAuth.decryptToken(tokenData.token)

				resolve({
					token,
					isLoggedIn: true,
					isWorking: false,
					userData: sessionData,
					user: sessionData.email,
					password: null,
					errors: {
github meetup / meetup-web-platform / packages / mwp-core / src / renderers / server-render.jsx View on Github external
store =>
				// create tracer and immediately invoke the resulting function.
				// trace should start before rendering, finish after rendering
				newrelic.createTracer('serverRender', getRouterRenderer)({
					routes,
					store,
					location: url,
					basename,
					scripts,
					cssLinks,
					userAgent,
				}) // immediately invoke callback
		);
github lifechurch / melos / feature-server.js View on Github external
return Object.assign({}, defaultConfig, config)
})

const loadData = nr.createTracer('fnLoadData', (feature, params, startingState, sessionData, store, Locale) => {
	return new Promise(nr.createTracer('fnLoadData::promise', (resolve) => {
		let fn = null
		try {
			fn = require(`./app/standalone/${feature}/loadData`).default
			resolve(fn(params, startingState, sessionData, store, Locale))
		} catch (ex) {
			resolve()
		}
	}))
})

const getLocale = nr.createTracer('fnGetLocale', (languageTag) => {
	let final = {}

	if (typeof languageTag === 'undefined' || languageTag === null || languageTag === '' || typeof availableLocales[languageTag] === 'undefined') {
		final = { locale: availableLocales['en-US'], source: 'default' }
	} else {
		final = { locale: availableLocales[languageTag], source: 'param' }
	}

	// Get the appropriate set of localized strings for this locale
	final.messages = require(`./locales/${final.locale}.json`);

	for (const lc of localeList) {
		if (lc.locale === final.locale) {
			final.locale2 = lc.locale2
			final.locale3 = lc.locale3
			final.momentLocale = lc.momentLocale
github meetup / meetup-web-platform / packages / mwp-core / src / renderers / server-render.jsx View on Github external
store =>
							// create tracer and immediately invoke the resulting function.
							// trace should start before rendering, finish after rendering
							newrelic.createTracer('serverRender', getRouterRenderer)({
								request,
								h,
								appContext,
								routes: resolvedRoutes,
								store,
								scripts,
								cssLinks,
							}) // immediately invoke callback
					);
github lifechurch / melos / feature-server.js View on Github external
if (lc.locale === final.locale) {
			final.locale2 = lc.locale2
			final.locale3 = lc.locale3
			final.momentLocale = lc.momentLocale
			final.planLocale = planLocales[lc.locale]
		}
	}
	// Get the appropriate react-intl locale data for this locale
	const localeData = require(`react-intl/locale-data/${final.locale2}`);
	final.data = localeData;

	moment.locale(final.momentLocale)
	return final;
})

const getRenderProps = nr.createTracer('fnGetRenderProps', (feature, url) => {
	return new Promise(nr.createTracer('fnGetRenderProps::promsie', (resolve) => {
		if (url !== null && typeof url === 'string' && url.length > 0) {
			let getRoutes = null
			try {
				getRoutes = require(`./app/standalone/${feature}/routes.js`).default
				const routes = getRoutes(null)
				match({ routes, location: url }, (error, redirectLocation, renderProps) => {
					if (!error && !redirectLocation && renderProps) {
						resolve(renderProps)
					}
				})
			} catch (ex) {
				// We expect MODULE_NOT_FOUND errors because some features don't use routing
				//  but we want to capture any other exceptions here
				if (ex.code !== 'MODULE_NOT_FOUND') {
					Raven.captureException(ex)
github lifechurch / melos / feature-server.js View on Github external
} catch (ex) {
		Raven.captureException(ex)
	}
	return rootComponent
})

const mapStateToParams = nr.createTracer('fnMapStateToParams', (feature, state, params) => {
	try {
		const fn = require(`./app/standalone/${feature}/mapParamsToState`).default
		return fn(state, params)
	} catch (ex) {
		return state
	}
})

const getConfig = nr.createTracer('fnGetConfig', (feature) => {
	const defaultConfig = { linkCss: true }
	let config = {}
	try {
		config = require(`./app/standalone/${feature}/config`).default
	} catch (ex) { }
	return Object.assign({}, defaultConfig, config)
})

const loadData = nr.createTracer('fnLoadData', (feature, params, startingState, sessionData, store, Locale) => {
	return new Promise(nr.createTracer('fnLoadData::promise', (resolve) => {
		let fn = null
		try {
			fn = require(`./app/standalone/${feature}/loadData`).default
			resolve(fn(params, startingState, sessionData, store, Locale))
		} catch (ex) {
			resolve()
github lifechurch / melos / feature-server.js View on Github external
defaultState = require('./app/defaultState').default
	}
	return defaultState
})

const getStore = nr.createTracer('fnGetStore', (feature, startingState, history, logger) => {
	let configureStore = {}
	try {
		configureStore = require(`./app/standalone/${feature}/store`).default
	} catch (ex) {
		configureStore = require('./app/store/configureStore').default
	}
	return configureStore(startingState, history, logger)
})

const getRootComponent = nr.createTracer('fnGetRootComponent', (feature) => {
	let rootComponent = null
	try {
		rootComponent = require(`./app/standalone/${feature}/rootComponent`).default
	} catch (ex) {
		Raven.captureException(ex)
	}
	return rootComponent
})

const mapStateToParams = nr.createTracer('fnMapStateToParams', (feature, state, params) => {
	try {
		const fn = require(`./app/standalone/${feature}/mapParamsToState`).default
		return fn(state, params)
	} catch (ex) {
		return state
	}
github lifechurch / melos / feature-server.js View on Github external
configureStore = require('./app/store/configureStore').default
	}
	return configureStore(startingState, history, logger)
})

const getRootComponent = nr.createTracer('fnGetRootComponent', (feature) => {
	let rootComponent = null
	try {
		rootComponent = require(`./app/standalone/${feature}/rootComponent`).default
	} catch (ex) {
		Raven.captureException(ex)
	}
	return rootComponent
})

const mapStateToParams = nr.createTracer('fnMapStateToParams', (feature, state, params) => {
	try {
		const fn = require(`./app/standalone/${feature}/mapParamsToState`).default
		return fn(state, params)
	} catch (ex) {
		return state
	}
})

const getConfig = nr.createTracer('fnGetConfig', (feature) => {
	const defaultConfig = { linkCss: true }
	let config = {}
	try {
		config = require(`./app/standalone/${feature}/config`).default
	} catch (ex) { }
	return Object.assign({}, defaultConfig, config)
})
github lifechurch / melos / feature-server.js View on Github external
const loadData = nr.createTracer('fnLoadData', (feature, params, startingState, sessionData, store, Locale) => {
	return new Promise(nr.createTracer('fnLoadData::promise', (resolve) => {
		let fn = null
		try {
			fn = require(`./app/standalone/${feature}/loadData`).default
			resolve(fn(params, startingState, sessionData, store, Locale))
		} catch (ex) {
			resolve()
		}
	}))
})