newrelic 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NEWS.md +22 -0
- package/api.js +81 -0
- package/lib/config/index.js +7 -0
- package/lib/spans/span-event.js +1 -1
- package/lib/transaction/handle.js +11 -0
- package/lib/transaction/index.js +14 -2
- package/lib/transaction/trace/segment.js +10 -0
- package/package.json +2 -2
- package/stub_api.js +8 -0
package/NEWS.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
### 6.2.0 (2019-11-25):
|
|
2
|
+
|
|
3
|
+
* Upgraded `tap` to resolve `handlebars` audit warnings.
|
|
4
|
+
|
|
5
|
+
* Added `getLinkingMetadata()` method to the API.
|
|
6
|
+
|
|
7
|
+
This new method can be used to retrieve the identifying information for the
|
|
8
|
+
agent and current active span and trace. Please consult [the documentation](https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/nodejs-agent-api#getLinkingMetadata)
|
|
9
|
+
for more information.
|
|
10
|
+
|
|
11
|
+
* Added `getTraceMetadata()` to the agent API.
|
|
12
|
+
|
|
13
|
+
This new method can be used to retrieve the current active Distributed Tracing
|
|
14
|
+
span and trace ids. Please consult [the documentation](https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/nodejs-agent-api#getTraceMetadata)
|
|
15
|
+
for more information.
|
|
16
|
+
|
|
17
|
+
* Added an `isSampled()` method to `Transaction` and `TransactionHandle`.
|
|
18
|
+
|
|
19
|
+
This new method can be used to retrieve the sampling decision made for a given
|
|
20
|
+
transaction. Please consult [the documentation](https://docs.newrelic.com/docs/agents/nodejs-agent/api-guides/nodejs-agent-api#transaction-handle-isSampled)
|
|
21
|
+
for more information.
|
|
22
|
+
|
|
1
23
|
### 6.1.0 (2019-11-05):
|
|
2
24
|
|
|
3
25
|
* `@newrelic/native-metrics` module is defaulted to disabled in serverless mode.
|
package/api.js
CHANGED
|
@@ -128,6 +128,57 @@ API.prototype.getTransaction = function getTransaction() {
|
|
|
128
128
|
return new TransactionHandle(transaction)
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/**
|
|
132
|
+
* This method returns an object with the following keys/data:
|
|
133
|
+
* - `trace.id`: The current trace ID
|
|
134
|
+
* - `span.id`: The current span ID
|
|
135
|
+
* - `entity.name`: The application name specified in the connect request as
|
|
136
|
+
* app_name. If multiple application names are specified this will only be
|
|
137
|
+
* the first name
|
|
138
|
+
* - `entity.type`: The string "SERVICE"
|
|
139
|
+
* - `entity.guid`: The entity ID returned in the connect reply as entity_guid
|
|
140
|
+
* - `hostname`: The hostname as specified in the connect request as
|
|
141
|
+
* utilization.full_hostname. If utilization.full_hostname is null or empty,
|
|
142
|
+
* this will be the hostname specified in the connect request as host.
|
|
143
|
+
*
|
|
144
|
+
* @returns {LinkingMetadata} The linking object with the data above
|
|
145
|
+
*/
|
|
146
|
+
API.prototype.getLinkingMetadata = function getLinkingMetadata(omitSupportability) {
|
|
147
|
+
if (omitSupportability !== true) {
|
|
148
|
+
const metric = this.agent.metrics.getOrCreateMetric(
|
|
149
|
+
NAMES.SUPPORTABILITY.API + '/getLinkingMetadata'
|
|
150
|
+
)
|
|
151
|
+
metric.incrementCallCount()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const agent = this.agent
|
|
155
|
+
|
|
156
|
+
const segment = agent.tracer.getSegment()
|
|
157
|
+
const config = agent.config
|
|
158
|
+
|
|
159
|
+
const linkingMetadata = {
|
|
160
|
+
'entity.name': config.applications()[0],
|
|
161
|
+
'entity.type': 'SERVICE',
|
|
162
|
+
'hostname': config.getHostnameSafe()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (config.distributed_tracing.enabled && segment) {
|
|
166
|
+
linkingMetadata['trace.id'] = segment.transaction.getTraceId()
|
|
167
|
+
const spanId = segment.getSpanId()
|
|
168
|
+
if (spanId) {
|
|
169
|
+
linkingMetadata['span.id'] = spanId
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
logger.debug('getLinkingMetadata with no active transaction')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (config.entity_guid) {
|
|
176
|
+
linkingMetadata['entity.guid'] = config.entity_guid
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return linkingMetadata
|
|
180
|
+
}
|
|
181
|
+
|
|
131
182
|
/**
|
|
132
183
|
* Specify the `Dispatcher` and `Dispatcher Version` environment values.
|
|
133
184
|
* A dispatcher is typically the service responsible for brokering
|
|
@@ -1327,6 +1378,36 @@ function instrumentMessages(moduleName, onRequire, onError) {
|
|
|
1327
1378
|
shimmer.registerInstrumentation(opts)
|
|
1328
1379
|
}
|
|
1329
1380
|
|
|
1381
|
+
/**
|
|
1382
|
+
* Returns the current trace and span id.
|
|
1383
|
+
*
|
|
1384
|
+
* @returns {*} The object containing the current trace and span ids
|
|
1385
|
+
*/
|
|
1386
|
+
API.prototype.getTraceMetadata = function getTraceMetadata() {
|
|
1387
|
+
var metric = this.agent.metrics.getOrCreateMetric(
|
|
1388
|
+
NAMES.SUPPORTABILITY.API + '/getTraceMetadata'
|
|
1389
|
+
)
|
|
1390
|
+
metric.incrementCallCount()
|
|
1391
|
+
|
|
1392
|
+
const metadata = {}
|
|
1393
|
+
|
|
1394
|
+
const segment = this.agent.tracer.getSegment()
|
|
1395
|
+
if (!segment) {
|
|
1396
|
+
logger.debug("No transaction found when calling API#getTraceMetadata")
|
|
1397
|
+
} else if (!this.agent.config.distributed_tracing.enabled) {
|
|
1398
|
+
logger.debug("Distributed tracing disabled when calling API#getTraceMetadata")
|
|
1399
|
+
} else {
|
|
1400
|
+
metadata.traceId = segment.transaction.getTraceId()
|
|
1401
|
+
|
|
1402
|
+
const spanId = segment.getSpanId()
|
|
1403
|
+
if (spanId) {
|
|
1404
|
+
metadata.spanId = spanId
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
return metadata
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1330
1411
|
/**
|
|
1331
1412
|
* Shuts down the agent.
|
|
1332
1413
|
*
|
package/lib/config/index.js
CHANGED
|
@@ -138,6 +138,8 @@ function Config(config) {
|
|
|
138
138
|
// this value is arbitrary
|
|
139
139
|
this.max_trace_segments = 900
|
|
140
140
|
|
|
141
|
+
this.entity_guid = null
|
|
142
|
+
|
|
141
143
|
// feature level of this account
|
|
142
144
|
this.product_level = 0
|
|
143
145
|
// product-level related
|
|
@@ -547,6 +549,11 @@ Config.prototype._fromServer = function _fromServer(params, key) {
|
|
|
547
549
|
)
|
|
548
550
|
break
|
|
549
551
|
|
|
552
|
+
// Entity GUID
|
|
553
|
+
case 'entity_guid':
|
|
554
|
+
this.entity_guid = params[key]
|
|
555
|
+
break
|
|
556
|
+
|
|
550
557
|
// These settings aren't supported by the agent (yet).
|
|
551
558
|
case 'sampling_rate':
|
|
552
559
|
case 'episodes_file':
|
package/lib/spans/span-event.js
CHANGED
|
@@ -88,7 +88,7 @@ class SpanEvent {
|
|
|
88
88
|
|
|
89
89
|
const tx = segment.transaction
|
|
90
90
|
|
|
91
|
-
span.intrinsics.traceId = tx.
|
|
91
|
+
span.intrinsics.traceId = tx.getTraceId()
|
|
92
92
|
span.intrinsics.guid = segment.id
|
|
93
93
|
span.intrinsics.parentId = parentId
|
|
94
94
|
span.intrinsics.transactionId = tx.id
|
|
@@ -35,6 +35,13 @@ module.exports = class TransactionHandle {
|
|
|
35
35
|
this._transaction.setForceIgnore(true)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Return whether this Transaction is being sampled
|
|
40
|
+
*/
|
|
41
|
+
isSampled() {
|
|
42
|
+
return this._transaction.isSampled()
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
/**
|
|
39
46
|
*
|
|
40
47
|
* Proxy method for Transaction#createDistrubtedTracePayload.
|
|
@@ -70,6 +77,10 @@ module.exports.Stub = class TransactionHandleStub {
|
|
|
70
77
|
logger.debug("No transaction found when calling Transaction.ignore")
|
|
71
78
|
}
|
|
72
79
|
|
|
80
|
+
isSampled() {
|
|
81
|
+
logger.debug("No transaction found when calling Transaction.isSampled")
|
|
82
|
+
}
|
|
83
|
+
|
|
73
84
|
createDistributedTracePayload() {
|
|
74
85
|
logger.debug(
|
|
75
86
|
"No transaction found when calling Transaction.createDistributedTracePayload"
|
package/lib/transaction/index.js
CHANGED
|
@@ -971,7 +971,7 @@ function createDistributedTracePayload() {
|
|
|
971
971
|
ac: accountId,
|
|
972
972
|
ap: appId,
|
|
973
973
|
tx: this.id,
|
|
974
|
-
tr: this.
|
|
974
|
+
tr: this.getTraceId(),
|
|
975
975
|
pr: this.priority,
|
|
976
976
|
sa: this.sampled,
|
|
977
977
|
ti: Date.now()
|
|
@@ -999,7 +999,7 @@ function addDistributedTraceIntrinsics(attrs) {
|
|
|
999
999
|
this._calculatePriority()
|
|
1000
1000
|
|
|
1001
1001
|
// *always* add these if DT flag is enabled.
|
|
1002
|
-
attrs.traceId = this.
|
|
1002
|
+
attrs.traceId = this.getTraceId()
|
|
1003
1003
|
attrs.guid = this.id
|
|
1004
1004
|
attrs.priority = this.priority
|
|
1005
1005
|
|
|
@@ -1027,6 +1027,11 @@ function addDistributedTraceIntrinsics(attrs) {
|
|
|
1027
1027
|
}
|
|
1028
1028
|
}
|
|
1029
1029
|
|
|
1030
|
+
Transaction.prototype.isSampled = function isSampled() {
|
|
1031
|
+
this._calculatePriority()
|
|
1032
|
+
return this.sampled
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1030
1035
|
/**
|
|
1031
1036
|
* Generates a priority for the transaction if it does not have one already.
|
|
1032
1037
|
*/
|
|
@@ -1073,4 +1078,11 @@ function addRequestParameters(requestParameters) {
|
|
|
1073
1078
|
}
|
|
1074
1079
|
}
|
|
1075
1080
|
|
|
1081
|
+
/**
|
|
1082
|
+
* Gets the current distributed trace traceId
|
|
1083
|
+
*/
|
|
1084
|
+
Transaction.prototype.getTraceId = function getTraceId() {
|
|
1085
|
+
return this.traceId || this.id
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1076
1088
|
module.exports = Transaction
|
|
@@ -90,6 +90,16 @@ TraceSegment.prototype.getAttributes = function getAttributes() {
|
|
|
90
90
|
return this.attributes.get(DESTINATIONS.TRANS_SEGMENT)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
TraceSegment.prototype.getSpanId = function getSpanId() {
|
|
94
|
+
const conf = this.transaction.agent.config
|
|
95
|
+
const enabled = conf.span_events.enabled && conf.distributed_tracing.enabled
|
|
96
|
+
if (enabled) {
|
|
97
|
+
return this.id
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return null
|
|
101
|
+
}
|
|
102
|
+
|
|
93
103
|
/**
|
|
94
104
|
* @param {string} host
|
|
95
105
|
* The name of the host of the database. This will be normalized if the string
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "newrelic",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"author": "New Relic Node.js agent team <nodejs@newrelic.com>",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"contributors": [
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
"rimraf": "^2.6.3",
|
|
174
174
|
"should": "*",
|
|
175
175
|
"sinon": "^4.5.0",
|
|
176
|
-
"tap": "^14.
|
|
176
|
+
"tap": "^14.10.1",
|
|
177
177
|
"temp": "^0.8.1",
|
|
178
178
|
"through": "^2.3.6",
|
|
179
179
|
"when": "*"
|
package/stub_api.js
CHANGED
|
@@ -36,6 +36,7 @@ Stub.prototype.getTransaction = getTransaction
|
|
|
36
36
|
Stub.prototype.getBrowserTimingHeader = getBrowserTimingHeader
|
|
37
37
|
Stub.prototype.shutdown = shutdown
|
|
38
38
|
Stub.prototype.setLambdaHandler = setLambdaHandler
|
|
39
|
+
Stub.prototype.getTraceMetadata = getTraceMetadata
|
|
39
40
|
|
|
40
41
|
// This code gets injected into HTML templates
|
|
41
42
|
// and we don't want it to return undefined/null.
|
|
@@ -61,6 +62,13 @@ function startSegment(name, record, handler, callback) {
|
|
|
61
62
|
return null
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
function getTraceMetadata() {
|
|
66
|
+
return {
|
|
67
|
+
traceId: '',
|
|
68
|
+
spanId: ''
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
64
72
|
function startWebTransaction(url, callback) {
|
|
65
73
|
logger.debug('Not calling startWebTransaction because New Relic is disabled.')
|
|
66
74
|
if (typeof callback === 'function') {
|