new TransactionShim(shimName, agent, moduleName, resolvedName, shimName, pkgVersion)
Constructs a transaction managing shim.
Name | Type | Description |
---|---|---|
shimName | A helper class for working with transactions. | |
agent | Agent | The agent the shim will use. |
moduleName | string | The name of the module being instrumented. |
resolvedName | string | The full path to the loaded module. |
shimName | string | Used to persist shim ids across different shim instances. |
pkgVersion | string | version of module |
Extends
Members
(readonly) agent :Agent
The agent associated with this shim.
- Agent
- Inherited From
- Source
(readonly) logger :Logger
The logger for this shim.
- Logger
- Inherited From
- Source
(readonly) tracer :Tracer
The transaction tracer in use by the agent for the shim.
- Tracer
- Inherited From
- Source
Methods
applySegment(func, segment, full, context, args, inContextCBopt) → {*}
Sets the given segment as the active one for the duration of the function's execution.
applySegment(func, segment, full, context, args[, inContextCB])
Name | Type | Attributes | Description |
---|---|---|---|
func | function | The function to execute in the context of the given segment. | |
segment | TraceSegment | The segment to make active for the duration of the function. | |
full | boolean | Indicates if the full lifetime of the segment is bound to this function. | |
context | * | The | |
args | Array.<*> | The arguments to be passed into the function. | |
inContextCB | function | <optional> | The function used to do more instrumentation work. This function is guaranteed to be executed with the segment associated with. |
- Inherited From
- Source
Whatever value func
returned.
- Type:
- *
argsToArray() → {Array}
Like Shim#toArray
, but converts arguments
to an array.
This is the preferred function, when used with .apply
, for converting the arguments
object into an actual Array
as it will not cause deopts.
- Inherited From
- Source
An array containing the elements of arguments
.
- Type:
- Array
assignId(shimName)
Assigns id to shim instance. If shimName is present it will reuse an id otherwise it'll create a unique id.
Name | Type | Description |
---|---|---|
shimName | string | Used to persist shim ids across different instances. |
- Inherited From
- Source
assignOriginal(wrapped, original, forceOrig)
Assigns the shim id and original on the wrapped item. TODO: Once all wrapping is converted to proxies, we won't need to set this property as the trap on 'get' will return the original for symbols.original. For now, we have to prevent setting this on original.
Name | Type | Description |
---|---|---|
wrapped | * | wrapped item |
original | * |
|
forceOrig | boolean | flag to indicate to overwrite original function |
- Inherited From
- Source
bindCallbackSegment(spec, args, cbIdx, parentSegmentopt)
Replaces the callback in an arguments array with one that has been bound to the given segment.
bindCallbackSegment(spec, args, cbIdx [, segment])
bindCallbackSegment(spec, obj, property [, segment])
Name | Type | Attributes | Description |
---|---|---|---|
spec | Spec | spec to original wrapped function, used to call after method with arguments passed to callback | |
args | Array | | The arguments array to pull the cb from. | |
cbIdx | number | | The index of the callback. | |
parentSegment | TraceSegment | <optional> | The segment to use as the callback segment's parent. Defaults to the currently active segment. |
- Inherited From
- Source
bindCreateTransaction(nodule, propertyopt, spec) → {object|function}
Wraps one or more functions such that new transactions are created when invoked.
bindCreateTransaction(nodule, property, spec)
bindCreateTransaction(func, spec)
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source for the property to wrap, or a single function to wrap. | |
property | string | <optional> | The property to wrap. If omitted, the |
spec | TransactionSpec | The spec for creating the transaction. |
The first parameter to this function, after wrapping it or its property.
- Type:
- object |
function
bindPromise(promisenon-null, segmentnon-null) → {Promise}
Binds the given segment to the completion of the Promise. Updates segment timing and resets opaque state.
Name | Type | Description |
---|---|---|
promise | Promise | The Promise to bind. |
segment | TraceSegment | The segment to bind to the Promise. |
- Inherited From
- Source
The promise to continue with.
- Type:
- Promise
bindSegment(nodule, propertyopt, segmentopt, nullable, fullopt) → {object|function}
Binds the execution of a function to a single segment.
bindSegment(nodule , property [, segment [, full]])
bindSegment(func [, segment [, full]])
If called with a nodule
and a property, the wrapped property will be put back on the nodule. Otherwise, the wrapped function is just returned.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source for the property or a single function to bind to a segment. | |
property | string | <optional> | The property to bind. If omitted, the |
segment | TraceSegment | <optional> <nullable> | The segment to bind the execution of the function to. If omitted or |
full | boolean | <optional> | Indicates if the full lifetime of the segment is bound to this function. |
- Inherited From
- Source
The first parameter after wrapping.
- Type:
- object |
function
copySegmentParameters(segment, parameters)
Copies the given parameters onto the segment, respecting the current agent configuration.
Name | Type | Description |
---|---|---|
segment | TraceSegment | The segment to copy the parameters onto. |
parameters | object | The parameters to copy. |
- Inherited From
- Source
createSegment(name, recorderopt, nullable, parentopt) → (nullable) {TraceSegment}
Creates a new segment.
createSegment(opts)
createSegment(name [, recorder] [, parent])
Name | Type | Attributes | Description |
---|---|---|---|
name | string | The name to give the new segment. | |
recorder | function | <optional> <nullable> | Optional. A function which will record the segment as a metric. Default is to not record the segment. |
parent | TraceSegment | <optional> | Optional. The segment to use as the parent. Default is to use the currently active segment. |
- Inherited From
- Source
A new trace segment if a transaction is active, else null
is returned.
- Type:
- TraceSegment
defineProperties(obj, props)
Adds several properties to the given object.
Name | Type | Description |
---|---|---|
obj | object | The object to add the properties to. |
props | object | A mapping of properties to values to add. |
- Inherited From
- Source
defineProperty(obj, name, value)
Defines a read-only property on the given object.
Name | Type | Description |
---|---|---|
obj | object | The object to add the property to. |
name | string | The name of the property to add. |
value | * | | The value to set. If a function is given, it is used as a getter, otherwise the value is directly set as an unwritable property. |
- Inherited From
- Source
execute(nodule, spec)
Entry point for executing a spec.
Name | Type | Description |
---|---|---|
nodule | object | | Class or module containing the function to wrap. |
spec | Spec |
|
- Inherited From
- Source
getActiveSegment(objopt) → (nullable) {TraceSegment}
Retrieves the segment associated with the given object, or the currently active segment if no object is given.
getActiveSegment([obj])
An active segment is one whose transaction is still active (e.g. has not ended yet).
Name | Type | Attributes | Description |
---|---|---|---|
obj | * | <optional> | The object to retrieve a segment from. |
- Inherited From
- Source
The trace segment associated with the given object or the currently active segment if no object is provided or no segment is associated with the object.
- Type:
- TraceSegment
getName(obj) → {string}
Determine the name of an object.
Name | Type | Description |
---|---|---|
obj | * | The object to get a name for. |
- Inherited From
- Source
The name of the object if it has one, else <anonymous>
.
- Type:
- string
getOriginal(nodule, propertyopt) → {object|function}
Retrieves the original method for a wrapped function.
getOriginal(nodule, property)
getOriginal(func)
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source of the property to get the original of, or a function to unwrap. | |
property | string | <optional> | A property on |
- Inherited From
- Source
The original value for the given item.
- Type:
- object |
function
getOriginalOnce(nodule, propertyopt) → {object|function}
Retrieves the value of symbols.original on the wrapped function. Unlike getOriginal
this just looks in the direct wrapped function
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source of the property to get the original of, or a function to unwrap. | |
property | string | <optional> | A property on |
- Inherited From
- Source
The original value for the given item.
- Type:
- object |
function
getSegment(objopt) → (nullable) {TraceSegment}
Retrieves the segment associated with the given object, or the current segment if no object is given.
getSegment([obj])
Name | Type | Attributes | Description |
---|---|---|---|
obj | * | <optional> | The object to retrieve a segment from. |
- Inherited From
- Source
The trace segment associated with the given object or the current segment if no object is provided or no segment is associated with the object.
- Type:
- TraceSegment
insertCATReplyHeader(headers, useAlternateHeaderNamesopt)
Adds CAT headers for an outbound response.
insertCATReplyHeaders(headers [, useAlternateHeaderNames])
Name | Type | Attributes | Description |
---|---|---|---|
headers | object | The outbound response headers object to inject our CAT headers into. | |
useAlternateHeaderNames | boolean | <optional> | Indicates if HTTP-style headers should be used or alternate style. Some transport protocols are more strict on the characters allowed in headers and this option can be used to toggle use of pure-alpha header names. |
insertCATRequestHeaders(headers, useAlternateHeaderNamesopt)
Adds CAT headers for an outbound request.
insertCATRequestHeaders(headers [, useAlternateHeaderNames])
Name | Type | Attributes | Description |
---|---|---|---|
headers | object | The outbound request headers object to inject our CAT headers into. | |
useAlternateHeaderNames | boolean | <optional> | Indicates if HTTP-style headers should be used or alternate style. Some transport protocols are more strict on the characters allowed in headers and this option can be used to toggle use of pure-alpha header names. |
interceptPromise(prom, cb) → {Promise}
Executes the given callback when the promise is finalized, whether it is resolved or rejected.
Name | Type | Description |
---|---|---|
prom | Promise | Some kind of promise. Must have a |
cb | function | A function to call when the promise resolves. |
- Inherited From
- Source
A new promise to replace the original one.
- Type:
- Promise
isArray(obj) → {boolean}
Determines if the given object exists and is an array.
Name | Type | Description |
---|---|---|
obj | * | The object to check. |
- Inherited From
- Source
True if the object is an array, else false.
- Type:
- boolean
isAsyncFunction(fn, (function)) → {boolean}
Determines if function is an async function. Note it does not test if the return value of function is a promise or async function
Name | Type | Description |
---|---|---|
fn | ||
(function) | function to test if async |
- Inherited From
- Source
True if the function is an async function
- Type:
- boolean
isBoolean(obj) → {boolean}
Determines if the given object is a boolean literal.
Name | Type | Description |
---|---|---|
obj | * | The object to check. |
- Inherited From
- Source
True if the object is a boolean literal, else false.
- Type:
- boolean
isFunction(obj) → {boolean}
Determines if the given object exists and is a function.
Name | Type | Description |
---|---|---|
obj | * | The object to check. |
- Inherited From
- Source
True if the object is a function, else false.
- Type:
- boolean
isNull(val) → {boolean}
Determines if the given value is null.
Name | Type | Description |
---|---|---|
val | * | The value to check. |
- Inherited From
- Source
True if the value is null, else false.
- Type:
- boolean
isNumber(obj) → {boolean}
Determines if the given object is a number literal.
Name | Type | Description |
---|---|---|
obj | * | The object to check. |
- Inherited From
- Source
True if the object is a number literal, else false.
- Type:
- boolean
isObject(obj) → {boolean}
Determines if the given object is an Object.
Name | Type | Description |
---|---|---|
obj | * | The object to check. |
- Inherited From
- Source
True if the object is an Object, else false.
- Type:
- boolean
isPromise(obj) → {boolean}
Determines if the given object is a promise instance.
Name | Type | Description |
---|---|---|
obj | * | The object to check. |
- Inherited From
- Source
True if the object is a promise, else false.
- Type:
- boolean
isString(obj) → {boolean}
Determines if the given object exists and is a string.
Name | Type | Description |
---|---|---|
obj | * | The object to check. |
- Inherited From
- Source
True if the object is a string, else false.
- Type:
- boolean
isWrapped(nodule, propertyopt) → {boolean}
Determines if the specified function or property exists and is wrapped.
isWrapped(nodule, property)
isWrapped(func)
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source for the property or a single function to check. | |
property | string | <optional> | The property to check. If omitted, the |
- Inherited From
- Source
True if the item exists and has been wrapped.
- Type:
- boolean
normalizeIndex(arrayLength, idx) → (nullable) {number}
Ensures the given index is a valid index inside the array.
A negative index value is converted to a positive one by adding it to the array length before checking it.
Name | Type | Description |
---|---|---|
arrayLength | number | The length of the array this index is for. |
idx | number | The index to normalize. |
- Inherited From
- Source
The adjusted index value if it is valid, else null
.
- Type:
- number
once(fn) → {function}
Wraps a function such that it will only be executed once.
Name | Type | Description |
---|---|---|
fn | function | The function to wrap in an execution guard. |
- Inherited From
- Source
A function which will execute fn
at most once.
- Type:
- function
popTransactionName(pathSegmentopt)
Pops one or more elements off the transaction naming stack.
popTransactionName([pathSegment])
Ideally it is not necessary to ever provide the pathSegment
parameter for this function, but we do not live in an ideal world.
Name | Type | Attributes | Description |
---|---|---|---|
pathSegment | string | <optional> | Optional. Path segment to pop the stack repeatedly until a segment matching |
prefixRouteParameters(params) → {object|undefined}
Method for prefixing Route (aka URL) parameters with request.parameters.route
Many web frameworks support adding parameters to routes when defining your API structure, and this function updates those parameters names to be prefixed by request.parameters.route
. This is to avoid collision with reserved attribute names, as parameters used to be blindly stored on router span attributes (see https://github.com/newrelic/node-newrelic/issues/1574) in addition to being prefixed by request.parameters
.
Route parameters used to be stored under request.parameters.*
just like query parameters pre v10, but we now prefix with request.parameter.route
to avoid collision in the event an application uses the same name for a query and route parameter. Additionally, we now store the same key on the attributes of the base segment, trace, and router span.
Exported on shim to be used in our Next.js instrumentation, as that instrumentation does not follow the same pattern as all the other web frameworks we support.
Name | Type | Description |
---|---|---|
params | object | Object containing route/url parameter key/value pairs |
- Inherited From
- Source
the updated object, key
will now be request.parameters.route.key
, value remains untouched
- Type:
- object |
undefined
proxy(source, properties, dest)
Proxies all set/get actions for each given property on dest
onto source
.
Name | Type | Description |
---|---|---|
source | * | The object on which all the set/get actions will actually occur. |
properties | string | | All of the properties to proxy. |
dest | * | The object which is proxying the source's properties. |
- Inherited From
- Source
pushTransactionName(pathSegment)
Pushes a new path segment onto the transaction naming stack.
pushTransactionName(pathSegment)
Transactions are named for the middlware that sends the response. Some web frameworks are capable of mounting middlware in complex routing stacks. In order to maintain the correct name, transactions keep a stack of mount points for each middlware/router/app/whatever. The instrumentation should push on the mount path for wrapped things when route resolution enters and pop it back off when resolution exits the item.
Name | Type | Description |
---|---|---|
pathSegment | string | The path segment to add to the naming stack. |
record(nodule, propertiesopt, recordNamer) → {object|function}
Wraps a function with segment creation and binding.
record(nodule, properties, recordNamer)
record(func, recordNamer)
This is shorthand for calling Shim#wrap
and manually creating a segment.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source for the properties to record, or a single function to record. | |
properties | string | | <optional> | One or more properties to record. If omitted, the |
recordNamer | RecorderFunction | A function which returns a record descriptor that gives the name and type of record we'll make. |
- Inherited From
- Source
The first parameter, possibly wrapped.
- Type:
- object |
function
setActiveSegment(segment) → {TraceSegment}
Explicitly sets the active segment to the one passed in. This method should only be used if there is no function to tie a segment's timing to.
setActiveSegment(segment)
Name | Type | Description |
---|---|---|
segment | TraceSegment | The segment to set as the active segment. |
- Inherited From
- Source
- The segment set as active on the context.
- Type:
- TraceSegment
setDefaults(objnullable, defaults) → {object}
Performs a shallow copy of each property from defaults
only if obj
does not already have that property, or the value of the key on obj
is null
.
Name | Type | Attributes | Description |
---|---|---|---|
obj | object | <nullable> | The object to copy the defaults onto. |
defaults | object | A mapping of keys to default values. |
- Inherited From
- Source
The obj
with the default values copied onto it. If obj
was falsey, then a new object with the defaults copied onto it is returned instead.
- Type:
- object
setTransactionName(name)
Sets the name to be used for this transaction.
setTransactionName(name)
Either this or the naming stack should be used. Do not use them together.
Name | Type | Description |
---|---|---|
name | string | The name to use for the transaction. |
shimRequire(filePath) → (nullable) {*}
Loads a node module from the instrumented library's own root directory.
Name | Type | Description |
---|---|---|
filePath | string | A relative path inside the module's directory. |
- Inherited From
- Source
The result of loading the given module. If the module fails to load, null
is returned instead.
- Type:
- *
storeSegment(objnon-null, segmentopt)
Associates a segment with the given object.
storeSegment(obj [, segment])
If no segment is provided, the currently active segment is used.
Name | Type | Attributes | Description |
---|---|---|---|
obj | * | The object to retrieve a segment from. | |
segment | TraceSegment | <optional> | The segment to link the object to. |
- Inherited From
- Source
toArray(obj) → {Array.<*>}
Converts an array-like object into an array.
Name | Type | Description |
---|---|---|
obj | * | The array-like object (i.e. |
- Inherited From
- Source
An instance of Array
containing the elements of the array-like.
- Type:
- Array.<*>
unwrap(nodule, propertiesopt) → {object|function}
Unwraps one item, revealing the underlying value. If item is wrapped multiple times, the unwrap will not occur as we cannot safely unwrap.
unwrap(nodule, property)
unwrap(func)
If called with a nodule
and properties, the unwrapped value will be put back on the nodule. Otherwise, the unwrapped function is just returned.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source for the properties to unwrap, or a single function to unwrap. | |
properties | string | | <optional> | One or more properties to unwrap. If omitted, the |
- Overrides
- Source
The first parameter after unwrapping.
- Type:
- object |
function
wrap(nodule, propertiesopt, spec, argsopt) → {object|function}
Executes the provided spec on one or more objects.
wrap(nodule, properties, spec [, args])
wrap(func, spec [, args])
When called with a nodule
and one or more properties, the spec will be executed on each property listed and the return value put back on the nodule
.
When called with just a function, the spec will be executed on the function and the return value of the spec simply passed back.
The wrapped version will have the same prototype as the original method.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source for the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
spec | Spec | | The spec for wrapping these items. | |
args | Array.<*> | <optional> | Optional extra arguments to be sent to the spec when executing it. |
- Inherited From
- Source
- See
The first parameter to this function, after wrapping it or its properties.
- Type:
- object |
function
wrapClass(nodule, propertiesopt, spec, argsopt) → {object|function}
Wraps a class constructor using a subclass with pre- and post-construction hooks.
wrapClass(nodule, properties, spec [, args])
wrapClass(func, spec [, args])
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source for the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
spec | ClassWrapSpec | | The spec for wrapping the returned value from the properties or a post hook. | |
args | Array.<*> | <optional> | Optional extra arguments to be sent to the spec when executing it. |
- Inherited From
- Source
- See
The first parameter to this function, after wrapping it or its properties.
- Type:
- object |
function
wrapExport(nodule, spec) → {*}
Wraps the actual module being instrumented to change what require
returns.
wrapExport(nodule, spec)
Name | Type | Description |
---|---|---|
nodule | * | The original export to replace with our new one. |
spec | WrapFunction | A wrapper function. The return value from this spec is what will replace the export. |
- Inherited From
- Source
The return value from spec
.
- Type:
- *
wrapReturn(nodule, propertiesopt, spec, argsopt) → {object|function}
Executes the provided spec with the return value of the given properties.
wrapReturn(nodule, properties, spec [, args])
wrapReturn(func, spec [, args])
If the wrapper is executed with new
then the wrapped function will also be called with new
. This feature should only be used with factory methods disguised as classes. Normally Shim#wrapClass
should be used to wrap constructors instead.
Name | Type | Attributes | Description |
---|---|---|---|
nodule | object | | The source for the properties to wrap, or a single function to wrap. | |
properties | string | | <optional> | One or more properties to wrap. If omitted, the |
spec | Spec | | The spec for wrapping the returned value from the properties. | |
args | Array.<*> | <optional> | Optional extra arguments to be sent to the spec when executing it. |
- Inherited From
- Source
- See
The first parameter to this function, after wrapping it or its properties.
- Type:
- object |
function