From 7158cf8a235025198309fa050ef4341ed0809bc4 Mon Sep 17 00:00:00 2001 From: Bob Evans Date: Fri, 11 Oct 2024 15:15:11 -0400 Subject: [PATCH] chore: fixed tests --- lib/db/parsed-statement.js | 10 ++++- lib/instrumentation/core/http-outbound.js | 32 ++++++++++--- lib/instrumentation/undici.js | 17 ++++--- lib/shim/datastore-shim.js | 2 +- lib/shim/message-shim/subscribe-consume.js | 2 +- lib/shim/transaction-shim.js | 22 +++++---- lib/shim/webframework-shim/middleware.js | 7 ++- lib/spans/span-event-aggregator.js | 11 +++-- lib/spans/span-event.js | 23 +++++----- lib/spans/streaming-span-event-aggregator.js | 4 +- lib/spans/streaming-span-event.js | 5 +-- lib/transaction/trace/index.js | 7 ++- lib/transaction/trace/segment.js | 2 + lib/transaction/tracer/index.js | 9 ++-- lib/util/cat.js | 8 +++- .../agent/serverless-harvest.tap.js | 8 +++- .../newrelic-response-handling.tap.js | 8 +++- test/unit/agent/agent.test.js | 16 ++++++- test/unit/db/trace.test.js | 24 ++++++++-- .../unit/llm-events/aws-bedrock/event.test.js | 8 ++-- test/unit/metrics-recorder/generic.test.js | 6 +-- .../metrics-recorder/http-external.test.js | 10 ++--- test/unit/metrics-recorder/http.test.js | 2 +- .../metrics-recorder/queue-time-http.test.js | 2 +- test/unit/parsed-statement.test.js | 20 ++++----- test/unit/shim/shim.test.js | 45 ++++++++++--------- test/unit/shim/transaction-shim.test.js | 32 ++++++------- test/unit/spans/span-event-aggregator.test.js | 12 ++--- test/unit/spans/span-event.test.js | 14 +++--- test/unit/spans/streaming-span-event.test.js | 14 +++--- 30 files changed, 235 insertions(+), 147 deletions(-) diff --git a/lib/db/parsed-statement.js b/lib/db/parsed-statement.js index 9b64dab35b..1e23e39b07 100644 --- a/lib/db/parsed-statement.js +++ b/lib/db/parsed-statement.js @@ -21,7 +21,7 @@ function ParsedStatement(type, operation, collection, raw) { } } -ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, transaction, scope) { +ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope, transaction) { const duration = segment.getDurationInMillis() const exclusive = segment.getExclusiveDurationInMillis() const type = transaction.isWeb() ? DB.WEB : DB.OTHER @@ -67,7 +67,13 @@ ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, transa } if (this.raw) { - transaction.agent.queries.add({ segment, transaction, type: this.type.toLowerCase(), query: this.raw, trace: this.trace }) + transaction.agent.queries.add({ + segment, + transaction, + type: this.type.toLowerCase(), + query: this.raw, + trace: this.trace + }) } } diff --git a/lib/instrumentation/core/http-outbound.js b/lib/instrumentation/core/http-outbound.js index f17bc434f6..1caa57d12a 100644 --- a/lib/instrumentation/core/http-outbound.js +++ b/lib/instrumentation/core/http-outbound.js @@ -145,10 +145,14 @@ module.exports = function instrumentOutbound(agent, opts, makeRequest) { * @param {string} params.hostname domain of outbound request * @param {string} params.port port of outbound request * @param {TraceSegment} segment outbound http segment - * @param {Transaction} transaction active tx + * @param {Transaction} transaction active tx * @returns {http.IncomingMessage} request actual http outbound request */ -function instrumentRequest({ agent, opts, makeRequest, host, port, hostname }, segment, transaction) { +function instrumentRequest( + { agent, opts, makeRequest, host, port, hostname }, + segment, + transaction +) { const outboundHeaders = Object.create(null) opts.headers = opts.headers || {} @@ -157,7 +161,15 @@ function instrumentRequest({ agent, opts, makeRequest, host, port, hostname }, s maybeAddDtCatHeaders(agent, transaction, outboundHeaders, opts?.headers) opts.headers = assignOutgoingHeaders(opts.headers, outboundHeaders) - const request = applySegment({ opts, makeRequest, hostname, host, port, segment, config: agent.config }) + const request = applySegment({ + opts, + makeRequest, + hostname, + host, + port, + segment, + config: agent.config + }) instrumentRequestEmit(agent, host, segment, request) @@ -268,7 +280,7 @@ function instrumentRequestEmit(agent, host, segment, request) { segment.end() handleError({ transaction, req: request, error: arg }) } else if (evnt === 'response') { - handleResponse({ agent, segment, host, res: arg }) + handleResponse({ agent, segment, transaction, host, res: arg }) } return boundEmit.apply(this, arguments) @@ -283,8 +295,11 @@ function instrumentRequestEmit(agent, host, segment, request) { * request object. * * @param {object} segment TraceSegment instance + * @param segment.transaction * @param {object} req http.ClientRequest * @param {Error} error If provided, unhandled error that occurred during request + * @param segment.req + * @param segment.error * @returns {boolean} True if the error will be collected by New Relic. */ function handleError({ transaction, req, error }) { @@ -301,12 +316,17 @@ function handleError({ transaction, req, error }) { /** * Ties the response object to the request segment. * + * @param segment.agent * @param {object} segment TraceSegment instance * @param {string} hostname host of the HTTP request * @param host * @param {object} res http.ServerResponse + * @param segment.segment + * @param segment.transaction + * @param segment.host + * @param segment.res */ -function handleResponse({ agent, segment, host, res }) { +function handleResponse({ agent, segment, transaction, host, res }) { // Add response attributes for spans segment.addSpanAttribute('http.statusCode', res.statusCode) segment.addSpanAttribute('http.statusText', res.statusMessage) @@ -315,7 +335,7 @@ function handleResponse({ agent, segment, host, res }) { if (agent.config.cross_application_tracer.enabled && !agent.config.distributed_tracing.enabled) { const { appData } = cat.extractCatHeaders(res.headers) const decodedAppData = cat.parseAppData(agent.config, appData) - cat.assignCatToSegment(decodedAppData, segment, host) + cat.assignCatToSegment({ appData: decodedAppData, segment, host, transaction }) } // Again a custom emit wrapper because we want to watch for the `end` event. diff --git a/lib/instrumentation/undici.js b/lib/instrumentation/undici.js index eea8a2d6fa..adfe2182f4 100644 --- a/lib/instrumentation/undici.js +++ b/lib/instrumentation/undici.js @@ -116,6 +116,7 @@ function addDTHeaders({ transaction, config, request }) { * @param {Shim} params.shim instance of shim * @param {object} params.request undici request object * @param {object} params.parentSegment current active, about to be parent of external segment + * @param params.segment */ function createExternalSegment({ shim, request, segment }) { const url = new URL(request.origin + request.path) @@ -160,9 +161,9 @@ function createExternalSegment({ shim, request, segment }) { function requestCreateHook(shim, { request }) { const { config } = shim.agent const { transaction, segment } = getParentContext(shim) - request[symbols.parentSegment] = segment - request[symbols.transaction] = transaction - if (!(segment || transaction) || (segment?.opaque)) { + request[symbols.parentSegment] = segment + request[symbols.transaction] = transaction + if (!(segment || transaction) || segment?.opaque) { logger.trace( 'Not capturing data for outbound request (%s) because parent segment opaque (%s)', request.path, @@ -193,6 +194,7 @@ function requestCreateHook(shim, { request }) { function requestHeadersHook(shim, { request, response }) { const { config } = shim.agent const activeSegment = request[symbols.segment] + const transaction = request[symbols.transaction] if (!activeSegment) { return } @@ -206,7 +208,12 @@ function requestHeadersHook(shim, { request, response }) { const decodedAppData = cat.parseAppData(config, appData) const attrs = activeSegment.getAttributes() const url = new URL(attrs.url) - cat.assignCatToSegment(decodedAppData, activeSegment, url.host) + cat.assignCatToSegment({ + appData: decodedAppData, + segment: activeSegment, + host: url.host, + transaction + }) } catch (err) { logger.warn(err, 'Cannot add CAT data to segment') } @@ -244,7 +251,7 @@ function endAndRestoreSegment(shim, { request, error }) { * Adds the error to the active transaction * * @param {Shim} shim instance of shim - * @param {Transaction} tx active transaction + * @param {Transaction} tx active transaction * @param {Error} error error from undici request */ function handleError(shim, tx, error) { diff --git a/lib/shim/datastore-shim.js b/lib/shim/datastore-shim.js index 8e2224a8a1..7875f19320 100644 --- a/lib/shim/datastore-shim.js +++ b/lib/shim/datastore-shim.js @@ -609,7 +609,7 @@ function _getSpec({ spec, shim, fn, fnName, args }) { */ function _recordQueryMetrics(parsed, segment, scope, transaction) { if (segment && transaction) { - parsed.recordMetrics(segment, transaction, scope) + parsed.recordMetrics(segment, scope, transaction) } } diff --git a/lib/shim/message-shim/subscribe-consume.js b/lib/shim/message-shim/subscribe-consume.js index 14581f97af..eead64968c 100644 --- a/lib/shim/message-shim/subscribe-consume.js +++ b/lib/shim/message-shim/subscribe-consume.js @@ -212,7 +212,7 @@ function createConsumerWrapper({ shim, spec, consumer }) { } } if (msgDesc.headers) { - shim.handleMqTracingHeaders(msgDesc.headers, tx.baseSegment, shim._transportType) + shim.handleMqTracingHeaders(msgDesc.headers, tx.baseSegment, tx, shim._transportType) } shim.logger.trace('Started message transaction %s named %s', tx.id, txName) diff --git a/lib/shim/transaction-shim.js b/lib/shim/transaction-shim.js index 157881e4cd..565d1efbf5 100644 --- a/lib/shim/transaction-shim.js +++ b/lib/shim/transaction-shim.js @@ -195,10 +195,11 @@ function setTransactionName(name) { * @param {TraceSegment} [segment] * The trace segment to associate the header data with. If no segment is * provided then the currently active segment is used. + * @param transaction * @param {string} [transportType] * The transport type that brought the headers. Usually `HTTP` or `HTTPS`. */ -function handleMqTracingHeaders(headers, segment, transportType) { +function handleMqTracingHeaders(headers, segment, transaction, transportType) { // TODO: replace functionality when CAT fully removed. if (!headers) { @@ -215,13 +216,11 @@ function handleMqTracingHeaders(headers, segment, transportType) { // Check that we're in an active transaction. const currentSegment = segment || this.getSegment() - if (!currentSegment || !currentSegment.transaction.isActive()) { + if (!currentSegment || !transaction.isActive()) { this.logger.trace('Not processing headers for CAT or DT, not in an active transaction.') return } - const transaction = currentSegment.transaction - if (config.distributed_tracing.enabled) { transaction.acceptDistributedTraceHeaders(transportType, headers) return @@ -237,7 +236,7 @@ function handleMqTracingHeaders(headers, segment, transportType) { ) cat.assignCatToTransaction(externalId, externalTransaction, transaction) const decodedAppData = cat.parseAppData(config, appData) - cat.assignCatToSegment(decodedAppData, currentSegment) + cat.assignCatToSegment({ appData: decodedAppData, segment: currentSegment, transaction }) // TODO: Handle adding ExternalTransaction metrics for this segment. } @@ -316,11 +315,11 @@ function insertCATReplyHeader(headers, useAlternateHeaderNames) { // Are we in a transaction? const segment = this.getSegment() - if (!segment || !segment.transaction.isActive()) { + const transaction = this.tracer.getTransaction() + if (!segment || !transaction?.isActive()) { this.logger.trace('Not adding CAT reply header, not in an active transaction.') return } - const tx = segment.transaction // Hunt down the content length. // NOTE: In AMQP, content-type and content-encoding are guaranteed fields, but @@ -334,11 +333,16 @@ function insertCATReplyHeader(headers, useAlternateHeaderNames) { } } - const { key, data } = cat.encodeAppData(config, tx, contentLength, useAlternateHeaderNames) + const { key, data } = cat.encodeAppData( + config, + transaction, + contentLength, + useAlternateHeaderNames + ) // Add the header. if (key && data) { headers[key] = data - this.logger.trace('Added outbound response CAT headers for transaction %s', tx.id) + this.logger.trace('Added outbound response CAT headers for transaction %s', transaction.id) } } diff --git a/lib/shim/webframework-shim/middleware.js b/lib/shim/webframework-shim/middleware.js index 2d412cbab5..6d1e99a5d7 100644 --- a/lib/shim/webframework-shim/middleware.js +++ b/lib/shim/webframework-shim/middleware.js @@ -340,10 +340,9 @@ module.exports._recordMiddleware = function _recordMiddleware(shim, middleware, * @returns {Function} recorder for middleware */ function _makeMiddlewareRecorder(_shim, metricName) { - return function middlewareMetricRecorder(segment, scope) { + return function middlewareMetricRecorder(segment, scope, transaction) { const duration = segment.getDurationInMillis() const exclusive = segment.getExclusiveDurationInMillis() - const transaction = segment.transaction if (scope) { transaction.measure(metricName, scope, duration, exclusive) @@ -454,7 +453,7 @@ function wrapNextFn({ shim, txInfo, nextDetails, segment }, nodule, property, is if (isError(shim, err)) { assignError(txInfo, err) } else if (!isFinal && !nextDetails.isErrorWare && nextDetails.appendPath) { - segment.transaction.nameState.popPath(nextDetails.route) + txInfo.transaction.nameState.popPath(nextDetails.route) } // The next call does not signify the end of the segment @@ -472,7 +471,7 @@ function wrapNextFn({ shim, txInfo, nextDetails, segment }, nodule, property, is // more work to do in that scope. return ret.then(function onNextFinish(v) { if (nextDetails.appendPath) { - segment.transaction.nameState.appendPath(nextDetails.route) + txInfo.transaction.nameState.appendPath(nextDetails.route) } txInfo.segmentStack.push(segment) diff --git a/lib/spans/span-event-aggregator.js b/lib/spans/span-event-aggregator.js index 5f1fd2e601..32d5f09b36 100644 --- a/lib/spans/span-event-aggregator.js +++ b/lib/spans/span-event-aggregator.js @@ -62,22 +62,21 @@ class SpanEventAggregator extends EventAggregator { * Attempts to add the given segment to the collection. * * @param {TraceSegment} segment - The segment to add. - * @param {string} [parentId=null] - The GUID of the parent span. + * @param {string} [parentId] - The GUID of the parent span. * @param isRoot * @returns {boolean} True if the segment was added, or false if it was discarded. */ - addSegment(segment, parentId, isRoot) { + addSegment({ segment, transaction, parentId, isRoot }) { // Check if the priority would be accepted before creating the event object. - const tx = segment.transaction - if (tx.priority < this._items.getMinimumPriority()) { + if (transaction.priority < this._items.getMinimumPriority()) { ++this.events.seen this._metrics.getOrCreateMetric(this._metricNames.SEEN).incrementCallCount() return false } - const span = SpanEvent.fromSegment(segment, parentId || null, isRoot) - return this.add(span, tx.priority) + const span = SpanEvent.fromSegment(segment, transaction, parentId || null, isRoot) + return this.add(span, transaction.priority) } /** diff --git a/lib/spans/span-event.js b/lib/spans/span-event.js index fcc04064e9..027fc67234 100644 --- a/lib/spans/span-event.js +++ b/lib/spans/span-event.js @@ -93,16 +93,17 @@ class SpanEvent { * category of the segment. * * @param {TraceSegment} segment - The segment to turn into a span event. + * @param transaction * @param {?string} [parentId] - The ID of the segment's parent. * @param isRoot * @returns {SpanEvent} The constructed event. */ - static fromSegment(segment, parentId = null, isRoot = false) { + static fromSegment(segment, transaction, parentId = null, isRoot = false) { const spanContext = segment.getSpanContext() // Since segments already hold span agent attributes and we want to leverage // filtering, we add to the segment attributes prior to processing. - if (spanContext.hasError && !segment.transaction.hasIgnoredErrorStatusCode()) { + if (spanContext.hasError && !transaction.hasIgnoredErrorStatusCode()) { const details = spanContext.errorDetails segment.addSpanAttribute('error.message', details.message) segment.addSpanAttribute('error.class', details.type) @@ -128,25 +129,23 @@ class SpanEvent { span.intrinsics[key] = value } - const tx = segment.transaction - - span.intrinsics.traceId = tx.traceId + span.intrinsics.traceId = transaction.traceId span.intrinsics.guid = segment.id span.intrinsics.parentId = parentId - span.intrinsics.transactionId = tx.id - span.intrinsics.sampled = tx.sampled - span.intrinsics.priority = tx.priority + span.intrinsics.transactionId = transaction.id + span.intrinsics.sampled = transaction.sampled + span.intrinsics.priority = transaction.priority span.intrinsics.name = segment.name if (isRoot) { - span.intrinsics.trustedParentId = tx.traceContext.trustedParentId - if (tx.traceContext.tracingVendors) { - span.intrinsics.tracingVendors = tx.traceContext.tracingVendors + span.intrinsics.trustedParentId = transaction.traceContext.trustedParentId + if (transaction.traceContext.tracingVendors) { + span.intrinsics.tracingVendors = transaction.traceContext.tracingVendors } } // Only set this if it will be `true`. Must be `null` otherwise. - if (tx.baseSegment === segment) { + if (transaction.baseSegment === segment) { span.intrinsics['nr.entryPoint'] = true } diff --git a/lib/spans/streaming-span-event-aggregator.js b/lib/spans/streaming-span-event-aggregator.js index 7c05c6f99c..5b2c7731c8 100644 --- a/lib/spans/streaming-span-event-aggregator.js +++ b/lib/spans/streaming-span-event-aggregator.js @@ -105,13 +105,13 @@ class StreamingSpanEventAggregator extends Aggregator { * @param isRoot * @returns {boolean} True if the segment was added, or false if it was discarded. */ - addSegment(segment, parentId, isRoot) { + addSegment({ segment, transaction, parentId, isRoot }) { if (!this.started) { logger.trace('Aggregator has not yet started, dropping span (%s).', segment.name) return } - const span = StreamingSpanEvent.fromSegment(segment, parentId, isRoot) + const span = StreamingSpanEvent.fromSegment(segment, transaction, parentId, isRoot) this.stream.write(span) } diff --git a/lib/spans/streaming-span-event.js b/lib/spans/streaming-span-event.js index 4d435be4e2..da7432bfef 100644 --- a/lib/spans/streaming-span-event.js +++ b/lib/spans/streaming-span-event.js @@ -114,12 +114,12 @@ class StreamingSpanEvent { } } - static fromSegment(segment, parentId = null, isRoot = false) { + static fromSegment(segment, transaction, parentId = null, isRoot = false) { const spanContext = segment.getSpanContext() // Since segments already hold span agent attributes and we want to leverage // filtering, we add to the segment attributes prior to processing. - if (spanContext.hasError && !segment.transaction.hasIgnoredErrorStatusCode()) { + if (spanContext.hasError && !transaction.hasIgnoredErrorStatusCode()) { const details = spanContext.errorDetails segment.addSpanAttribute('error.message', details.message) segment.addSpanAttribute('error.class', details.type) @@ -132,7 +132,6 @@ class StreamingSpanEvent { const customAttributes = spanContext.customAttributes.get(DESTINATIONS.SPAN_EVENT) - const transaction = segment.transaction const traceId = transaction.traceId let span = null diff --git a/lib/transaction/trace/index.js b/lib/transaction/trace/index.js index 83cb05f86e..7b11835a23 100644 --- a/lib/transaction/trace/index.js +++ b/lib/transaction/trace/index.js @@ -115,7 +115,12 @@ Trace.prototype.generateSpanEvents = function generateSpanEvents() { // Even though at some point we might want to stop adding events because all the priorities // should be the same, we need to count the spans as seen. - spanAggregator.addSegment(segment, segmentInfo.parentId, segmentInfo.isRoot) + spanAggregator.addSegment({ + segment, + transaction: this.transaction, + parentId: segmentInfo.parentId, + isRoot: segmentInfo.isRoot + }) const nodes = segment.getChildren() for (let i = 0; i < nodes.length; ++i) { diff --git a/lib/transaction/trace/segment.js b/lib/transaction/trace/segment.js index 0975c34279..16d9d53081 100644 --- a/lib/transaction/trace/segment.js +++ b/lib/transaction/trace/segment.js @@ -402,6 +402,8 @@ TraceSegment.prototype.toJSON = function toJSON() { while (segmentsToProcess.length !== 0) { const { segment, destination } = segmentsToProcess.pop() + // TODO: how can we get the relevant transaction?? + // this is processed i _think_ once the tx ends, maybe we have to pass it through const start = segment.timer.startedRelativeTo(segment.transaction.trace.root.timer) const duration = segment.getDurationInMillis() diff --git a/lib/transaction/tracer/index.js b/lib/transaction/tracer/index.js index ef77b737ac..1b0ae441b3 100644 --- a/lib/transaction/tracer/index.js +++ b/lib/transaction/tracer/index.js @@ -50,7 +50,7 @@ function getContext() { } function getTransaction() { - const ctx = this.getContext() + const ctx = this.getContext() if (ctx?.transaction && ctx?.transaction?.isActive()) { return ctx.transaction } @@ -120,14 +120,15 @@ function transactionProxy(handler) { // don't nest transactions, reuse existing ones const segment = tracer.getSegment() + const currentTx = tracer.getTransaction() if (segment) { - if (segment.transaction.traceStacks) { + if (currentTx.traceStacks) { segment.probe('!!! Nested transaction creation !!!') - segment.transaction.traceFlag = true // Will log the stacks when it ends. + currentTx.traceFlag = true // Will log the stacks when it ends. } logger.warn( { - transaction: { id: segment.transaction.id, name: segment.transaction.getName() }, + transaction: { id: currentTx.id, name: currentTx.getName() }, segment: segment.name }, 'Active transaction when creating non-nested transaction' diff --git a/lib/util/cat.js b/lib/util/cat.js index 78cb15d0cc..f89c6a5ba5 100644 --- a/lib/util/cat.js +++ b/lib/util/cat.js @@ -273,11 +273,15 @@ cat.parseAppData = function parseAppData(config, obfAppData) { * Assigns the CAT id, transaction to segment and adds `transaction_guid` when it exists. * It also renames the segment name based on the newly decoded app data when host is present * + * @param appData.appData * @param {Array} appData decodes CAT app data * @param {TraceSegment} segment * @param {string} [host] if host is present it will rename segment with app data and host + * @param appData.segment + * @param appData.host + * @param appData.transaction */ -cat.assignCatToSegment = function assignCatToSegment(appData, segment, host) { +cat.assignCatToSegment = function assignCatToSegment({ appData, segment, host, transaction }) { if (!Array.isArray(appData) || typeof appData[0] !== 'string') { logger.trace(`Unknown format for CAT header ${HTTP_CAT_APP_DATA_HEADER}.`) return @@ -297,7 +301,7 @@ cat.assignCatToSegment = function assignCatToSegment(appData, segment, host) { } logger.trace( 'Got inbound response CAT headers in transaction %s from %s', - segment.transaction.id, + transaction.id, transactionGuid ) } diff --git a/test/integration/agent/serverless-harvest.tap.js b/test/integration/agent/serverless-harvest.tap.js index 0e1767f219..402db0a0b3 100644 --- a/test/integration/agent/serverless-harvest.tap.js +++ b/test/integration/agent/serverless-harvest.tap.js @@ -336,7 +336,13 @@ tap.test('Serverless mode harvest', (t) => { const expectedSql = 'select pg_sleep(1)' - agent.queries.add(tx.trace.root, 'postgres', expectedSql, 'FAKE STACK') + agent.queries.add({ + transaction: tx, + segment: tx.trace.root, + type: 'postgres', + query: expectedSql, + trace: 'FAKE STACK' + }) tx.end() agent.once('harvestFinished', () => { diff --git a/test/integration/newrelic-response-handling.tap.js b/test/integration/newrelic-response-handling.tap.js index 2dbc37bc36..c9e358241d 100644 --- a/test/integration/newrelic-response-handling.tap.js +++ b/test/integration/newrelic-response-handling.tap.js @@ -324,7 +324,13 @@ function createTestData(agent, callback) { helper.runInTransaction(agent, (transaction) => { const segment = transaction.trace.add('MySegment') segment.overwriteDurationInMillis(1) - agent.queries.add(segment, 'mysql', 'select * from foo', new Error().stack) + agent.queries.add({ + segment, + transaction, + type: 'mysql', + query: 'select * from foo', + trace: new Error().stack + }) transaction.finalizeNameFromUri('/some/test/url', 200) transaction.end() diff --git a/test/unit/agent/agent.test.js b/test/unit/agent/agent.test.js index 5f52c078cd..342199084e 100644 --- a/test/unit/agent/agent.test.js +++ b/test/unit/agent/agent.test.js @@ -655,7 +655,13 @@ test('when connected', async (t) => { const tx = new helper.FakeTransaction(agent, '/path/to/fake') tx.metrics = { apdexT: 0 } const segment = new helper.FakeSegment(tx, 2_000) - agent.queries.add(segment, 'mysql', 'select * from foo', 'Stack\nFrames') + agent.queries.add({ + transaction: tx, + segment, + type: 'mysql', + query: 'select * from foo', + trace: 'Stack\nFrames' + }) agent.spanEventAggregator.add(segment) agent.transactionEventAggregator.add(tx) agent.customEventAggregator.add({ key: 'value' }) @@ -694,7 +700,13 @@ test('when connected', async (t) => { const tx = new helper.FakeTransaction(agent, '/path/to/fake') tx.metrics = { apdexT: 0 } const segment = new helper.FakeSegment(tx, 2_000) - agent.queries.add(segment, 'mysql', 'select * from foo', 'Stack\nFrames') + agent.queries.add({ + transaction: tx, + segment, + type: 'mysql', + query: 'select * from foo', + trace: 'Stack\nFrames' + }) agent.spanEventAggregator.add(segment) agent.transactionEventAggregator.add(tx) agent.customEventAggregator.add({ key: 'value' }) diff --git a/test/unit/db/trace.test.js b/test/unit/db/trace.test.js index 361fa978e4..87e18b7c86 100644 --- a/test/unit/db/trace.test.js +++ b/test/unit/db/trace.test.js @@ -39,7 +39,13 @@ test('SQL trace attributes', async (t) => { const payload = tx._createDistributedTracePayload().text() tx.isDistributedTrace = null tx._acceptDistributedTracePayload(payload) - agent.queries.add(tx.trace.root, 'postgres', 'select pg_sleep(1)', 'FAKE STACK') + agent.queries.add({ + transaction: tx, + segment: tx.trace.root, + type: 'postgres', + query: 'select pg_sleep(1)', + trace: 'FAKE STACK' + }) agent.queries.prepareJSON((err, samples) => { const sample = samples[0] const attributes = sample[sample.length - 1] @@ -62,7 +68,13 @@ test('SQL trace attributes', async (t) => { const { agent } = t.nr helper.runInTransaction(agent, function (tx) { const query = 'select pg_sleep(1)' - agent.queries.add(tx.trace.root, 'postgres', query, 'FAKE STACK') + agent.queries.add({ + transaction: tx, + segment: tx.trace.root, + type: 'postgres', + query, + trace: 'FAKE STACK' + }) const sampleObj = agent.queries.samples.values().next().value const sample = agent.queries.prepareJSONSync()[0] assert.equal(sample[0], tx.getFullName()) @@ -85,7 +97,13 @@ test('SQL trace attributes', async (t) => { agent.config.account_id = 1 agent.config.simple_compression = true helper.runInTransaction(agent, function (tx) { - agent.queries.add(tx.trace.root, 'postgres', 'select pg_sleep(1)', 'FAKE STACK') + agent.queries.add({ + transaction: tx, + segment: tx.trace.root, + type: 'postgres', + query: 'select pg_sleep(1)', + trace: 'FAKE STACK' + }) agent.queries.prepareJSON((err, samples) => { const sample = samples[0] const attributes = sample[sample.length - 1] diff --git a/test/unit/llm-events/aws-bedrock/event.test.js b/test/unit/llm-events/aws-bedrock/event.test.js index 1d062b0bee..a613a0f18b 100644 --- a/test/unit/llm-events/aws-bedrock/event.test.js +++ b/test/unit/llm-events/aws-bedrock/event.test.js @@ -39,11 +39,11 @@ test.beforeEach((ctx) => { } } + ctx.nr.transaction = { + traceId: 'trace-1' + } ctx.nr.segment = { - id: 'segment-1', - transaction: { - traceId: 'trace-1' - } + id: 'segment-1' } ctx.nr.bedrockResponse = { diff --git a/test/unit/metrics-recorder/generic.test.js b/test/unit/metrics-recorder/generic.test.js index 35d9e5d687..50af5bcbe7 100644 --- a/test/unit/metrics-recorder/generic.test.js +++ b/test/unit/metrics-recorder/generic.test.js @@ -27,7 +27,7 @@ function record(options) { const transaction = options.transaction transaction.finalizeNameFromUri(options.url, options.code) - recordGeneric(segment, options.transaction.name) + recordGeneric(segment, options.transaction.name, options.transaction) } test('recordGeneric', async function (t) { @@ -50,7 +50,7 @@ test('recordGeneric', async function (t) { exclusive: 0 }) assert.doesNotThrow(function () { - recordGeneric(segment, undefined) + recordGeneric(segment, undefined, trans) }) }) @@ -61,7 +61,7 @@ test('recordGeneric', async function (t) { duration: 5, exclusive: 5 }) - recordGeneric(segment, undefined) + recordGeneric(segment, undefined, trans) const result = [[{ name: 'placeholder' }, [1, 0.005, 0.005, 0.005, 0.005, 0.000025]]] diff --git a/test/unit/metrics-recorder/http-external.test.js b/test/unit/metrics-recorder/http-external.test.js index 8ccdcc52ee..e5f4c7059f 100644 --- a/test/unit/metrics-recorder/http-external.test.js +++ b/test/unit/metrics-recorder/http-external.test.js @@ -10,8 +10,8 @@ const helper = require('../../lib/agent_helper') const generateRecorder = require('../../../lib/metrics/recorders/http_external') const Transaction = require('../../../lib/transaction') -function recordExternal(segment, scope) { - return generateRecorder('test.example.com', 'http')(segment, scope) +function recordExternal(segment, scope, transaction) { + return generateRecorder('test.example.com', 'http')(segment, scope, transaction) } function makeSegment(options) { @@ -31,7 +31,7 @@ function record(options) { const transaction = options.transaction transaction.finalizeNameFromUri(options.url, options.code) - recordExternal(segment, options.transaction.name) + recordExternal(segment, options.transaction.name, options.transaction) } test('recordExternal', async function (t) { @@ -56,7 +56,7 @@ test('recordExternal', async function (t) { exclusive: 0 }) assert.doesNotThrow(function () { - recordExternal(segment, undefined) + recordExternal(segment, undefined, trans) }) }) @@ -67,7 +67,7 @@ test('recordExternal', async function (t) { duration: 0, exclusive: 0 }) - recordExternal(segment, undefined) + recordExternal(segment, undefined, trans) const result = [ [{ name: 'External/test.example.com/http' }, [1, 0, 0, 0, 0, 0]], diff --git a/test/unit/metrics-recorder/http.test.js b/test/unit/metrics-recorder/http.test.js index afacf786ed..890fb2e45f 100644 --- a/test/unit/metrics-recorder/http.test.js +++ b/test/unit/metrics-recorder/http.test.js @@ -29,7 +29,7 @@ function record(options) { transaction.finalizeNameFromUri(options.url, options.code) segment.markAsWeb(options.url) - recordWeb(segment, options.transaction.name) + recordWeb(segment, options.transaction.name, options.transaction) } function beforeEach(ctx) { diff --git a/test/unit/metrics-recorder/queue-time-http.test.js b/test/unit/metrics-recorder/queue-time-http.test.js index adb9aa16e8..07647353f5 100644 --- a/test/unit/metrics-recorder/queue-time-http.test.js +++ b/test/unit/metrics-recorder/queue-time-http.test.js @@ -30,7 +30,7 @@ function record(options) { transaction.finalizeNameFromUri(options.url, options.code) transaction.queueTime = options.queueTime segment.markAsWeb(options.url) - recordWeb(segment, options.transaction.name) + recordWeb(segment, options.transaction.name, options.transaction) } test('when recording queueTime', async (t) => { diff --git a/test/unit/parsed-statement.test.js b/test/unit/parsed-statement.test.js index 33b9569699..379e44622d 100644 --- a/test/unit/parsed-statement.test.js +++ b/test/unit/parsed-statement.test.js @@ -32,7 +32,7 @@ test('recording database metrics', async (t) => { transaction.type = Transaction.TYPES.BG segment.setDurationInMillis(333) - ps.recordMetrics(segment, 'TEST') + ps.recordMetrics(segment, 'TEST', transaction) transaction.end() ctx.nr.metrics = transaction.metrics @@ -100,7 +100,7 @@ test('recording database metrics', async (t) => { transaction.type = Transaction.TYPES.BG segment.setDurationInMillis(333) - ps.recordMetrics(segment, 'TEST') + ps.recordMetrics(segment, 'TEST', transaction) transaction.end() ctx.nr.metrics = transaction.metrics @@ -165,7 +165,7 @@ test('recording database metrics', async (t) => { transaction.type = Transaction.TYPES.BG segment.setDurationInMillis(333) - ps.recordMetrics(segment, null) + ps.recordMetrics(segment, null, transaction) transaction.end() ctx.nr.metrics = transaction.metrics @@ -228,7 +228,7 @@ test('recording database metrics', async (t) => { transaction.type = Transaction.TYPES.BG segment.setDurationInMillis(333) - ps.recordMetrics(segment, null) + ps.recordMetrics(segment, null, transaction) transaction.end() ctx.nr.metrics = transaction.metrics @@ -297,13 +297,13 @@ test('recording slow queries', async (t) => { ctx.nr.segment = segment segment.setDurationInMillis(503) - ps.recordMetrics(segment, 'TEST') + ps.recordMetrics(segment, 'TEST', transaction) const ps2 = new ParsedStatement('MySql', 'select', 'foo', 'select * from foo where b=2') const segment2 = transaction.trace.add('test') segment2.setDurationInMillis(501) - ps2.recordMetrics(segment2, 'TEST') + ps2.recordMetrics(segment2, 'TEST', transaction) transaction.end() }) @@ -358,13 +358,13 @@ test('recording slow queries', async (t) => { ctx.nr.segment = segment segment.setDurationInMillis(503) - ps.recordMetrics(segment, 'TEST') + ps.recordMetrics(segment, 'TEST', transaction) const ps2 = new ParsedStatement('MySql', 'select', null, 'select * from foo where b=2') const segment2 = transaction.trace.add('test') segment2.setDurationInMillis(501) - ps2.recordMetrics(segment2, 'TEST') + ps2.recordMetrics(segment2, 'TEST', transaction) transaction.end() }) @@ -427,13 +427,13 @@ test('recording slow queries', async (t) => { ctx.nr.segment = segment segment.setDurationInMillis(503) - ps.recordMetrics(segment, 'TEST') + ps.recordMetrics(segment, 'TEST', transaction) const ps2 = new ParsedStatement('MySql', 'select', null, null) const segment2 = transaction.trace.add('test') segment2.setDurationInMillis(501) - ps2.recordMetrics(segment2, 'TEST') + ps2.recordMetrics(segment2, 'TEST', transaction) transaction.end() }) diff --git a/test/unit/shim/shim.test.js b/test/unit/shim/shim.test.js index bb8740aabf..b87c69999d 100644 --- a/test/unit/shim/shim.test.js +++ b/test/unit/shim/shim.test.js @@ -1920,22 +1920,22 @@ test('Shim', async function (t) { await t.test('#getActiveSegment', async function (t) { t.beforeEach(function (ctx) { beforeEach(ctx) - ctx.nr.segment = { - probe: function () {}, - transaction: { - active: true, - isActive: function () { - return this.active - } + ctx.nr.transaction = { + agent: {}, + active: true, + isActive: function () { + return this.active } } + ctx.nr.segment = new TraceSegment(ctx.nr.transaction, 'test') }) t.afterEach(afterEach) await t.test( 'should return the segment a function is bound to when transaction is active', function (t) { - const { segment, shim } = t.nr + const { segment, shim, transaction, tracer } = t.nr + tracer.setSegment({ transaction }) const bound = shim.bindSegment(function () {}, segment) assert.equal(shim.getActiveSegment(bound), segment) } @@ -1944,8 +1944,8 @@ test('Shim', async function (t) { await t.test( 'should return the current segment if the function is not bound when transaction is active', function (t) { - const { tracer, segment, shim } = t.nr - tracer.setSegment({ segment }) + const { segment, shim, tracer, transaction } = t.nr + tracer.setSegment({ segment, transaction }) assert.equal( shim.getActiveSegment(function () {}), segment @@ -1956,8 +1956,8 @@ test('Shim', async function (t) { await t.test( 'should return the current segment if no object is provided when transaction is active', function (t) { - const { tracer, segment, shim } = t.nr - tracer.setSegment({ segment }) + const { segment, shim, tracer, transaction } = t.nr + tracer.setSegment({ segment, transaction }) assert.equal(shim.getActiveSegment(), segment) } ) @@ -1965,9 +1965,10 @@ test('Shim', async function (t) { await t.test( 'should return null for a bound function when transaction is not active', function (t) { - const { segment, shim } = t.nr - segment.transaction.active = false - const bound = shim.bindSegment(function () {}, segment) + const { segment, shim, transaction, tracer } = t.nr + transaction.active = false + tracer.setSegment({ transaction }) + const bound = shim.bindSegment(function () {}, { segment }) assert.equal(shim.getActiveSegment(bound), null) } ) @@ -1975,9 +1976,9 @@ test('Shim', async function (t) { await t.test( 'should return null if the function is not bound when transaction is not active', function (t) { - const { tracer, segment, shim } = t.nr - segment.transaction.active = false - tracer.setSegment({ segment }) + const { tracer, segment, shim, transaction } = t.nr + transaction.active = false + tracer.setSegment({ segment, transaction }) assert.equal( shim.getActiveSegment(function () {}), null @@ -1988,9 +1989,9 @@ test('Shim', async function (t) { await t.test( 'should return null if no object is provided when transaction is not active', function (t) { - const { tracer, segment, shim } = t.nr - segment.transaction.active = false - tracer.setSegment({ segment }) + const { tracer, segment, shim, transaction } = t.nr + transaction.active = false + tracer.setSegment({ segment, transaction }) assert.equal(shim.getActiveSegment(), null) } ) @@ -2230,7 +2231,7 @@ test('Shim', async function (t) { const { segment, shim, wrappable } = t.nr shim.applySegment(wrappable.getActiveSegment, segment, true) assert.equal(segment.timer.touched, true) - assert.equal(segment.timer.state, 2) + assert.equal(segment.timer.state, 2) }) await t.test('should not change the active segment if `segment` is `null`', function (t) { diff --git a/test/unit/shim/transaction-shim.test.js b/test/unit/shim/transaction-shim.test.js index 06766ff21e..be55f5bbd1 100644 --- a/test/unit/shim/transaction-shim.test.js +++ b/test/unit/shim/transaction-shim.test.js @@ -441,7 +441,7 @@ test('TransactionShim', async function (t) { assert.ok(!segment.catTransaction) assert.ok(!segment.getAttributes().transaction_guid) - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx) assert.ok(!tx.incomingCatId) assert.ok(!tx.referringTransactionGuid) @@ -465,7 +465,7 @@ test('TransactionShim', async function (t) { assert.ok(!segment.catTransaction) assert.ok(!segment.getAttributes().transaction_guid) - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx) assert.ok(!tx.incomingCatId) assert.ok(!tx.referringTransactionGuid) @@ -488,7 +488,7 @@ test('TransactionShim', async function (t) { assert.ok(!segment.getAttributes().transaction_guid) assert.doesNotThrow(function () { - shim.handleMqTracingHeaders(null, segment) + shim.handleMqTracingHeaders(null, segment, tx) }) assert.ok(!tx.incomingCatId) @@ -516,7 +516,7 @@ test('TransactionShim', async function (t) { helper.runInTransaction(agent, shim.BG, function (tx2) { assert.notEqual(tx2, tx) - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx) }) assert.equal(tx.incomingCatId, '9876#id') @@ -541,7 +541,7 @@ test('TransactionShim', async function (t) { assert.ok(!tx.tripId) assert.ok(!tx.referringPathHash) - shim.handleMqTracingHeaders(headers) + shim.handleMqTracingHeaders(headers, null, tx) assert.equal(tx.incomingCatId, '9876#id') assert.equal(tx.referringTransactionGuid, 'trans id') @@ -568,7 +568,7 @@ test('TransactionShim', async function (t) { helper.runInTransaction(agent, shim.BG, function (tx2) { assert.notEqual(tx2, tx) - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx) }) assert.equal(tx.incomingCatId, '9876#id') @@ -592,7 +592,7 @@ test('TransactionShim', async function (t) { helper.runInTransaction(agent, function (tx) { const headers = { traceparent, tracestate } const segment = shim.getSegment() - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx) const outboundHeaders = {} tx.insertDistributedTraceHeaders(outboundHeaders) @@ -615,7 +615,7 @@ test('TransactionShim', async function (t) { helper.runInTransaction(agent, function (tx) { const headers = { traceparent } const segment = shim.getSegment() - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx) const outboundHeaders = {} tx.insertDistributedTraceHeaders(outboundHeaders) @@ -638,7 +638,7 @@ test('TransactionShim', async function (t) { helper.runInTransaction(agent, function (tx) { const headers = { traceparent, tracestate } const segment = shim.getSegment() - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx) const outboundHeaders = {} tx.insertDistributedTraceHeaders(outboundHeaders) @@ -660,7 +660,7 @@ test('TransactionShim', async function (t) { helper.runInTransaction(agent, function (tx) { const headers = { traceparent, tracestate } const segment = shim.getSegment() - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx) const outboundHeaders = {} tx.insertDistributedTraceHeaders(outboundHeaders) @@ -687,7 +687,7 @@ test('TransactionShim', async function (t) { helper.runInTransaction(agent, shim.BG, function (tx2) { assert.notEqual(tx2, tx) - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx2) }) assert.equal(segment.catId, '6789#app') @@ -702,7 +702,7 @@ test('TransactionShim', async function (t) { 'should attach the CAT info to current segment if not provided - DT disabled, app data is provided', function (t, end) { const { agent, shim } = t.nr - helper.runInTransaction(agent, function () { + helper.runInTransaction(agent, function (tx) { const headers = createCATHeaders(agent.config) const segment = shim.getSegment() delete headers['X-NewRelic-Id'] @@ -712,7 +712,7 @@ test('TransactionShim', async function (t) { assert.ok(!segment.catTransaction) assert.ok(!segment.getAttributes().transaction_guid) - shim.handleMqTracingHeaders(headers) + shim.handleMqTracingHeaders(headers, null, tx) assert.equal(segment.catId, '6789#app') assert.equal(segment.catTransaction, 'app data transaction name') @@ -738,7 +738,7 @@ test('TransactionShim', async function (t) { helper.runInTransaction(agent, shim.BG, function (tx2) { assert.notEqual(tx2, tx) - shim.handleMqTracingHeaders(headers, segment) + shim.handleMqTracingHeaders(headers, segment, tx2) }) assert.equal(segment.catId, '6789#app') @@ -753,7 +753,7 @@ test('TransactionShim', async function (t) { 'should not attach any CAT data to the segment, app data is for an untrusted application', function (t, end) { const { agent, shim } = t.nr - helper.runInTransaction(agent, function () { + helper.runInTransaction(agent, function (tx) { const headers = createCATHeaders(agent.config) const segment = shim.getSegment() delete headers['X-NewRelic-Id'] @@ -764,7 +764,7 @@ test('TransactionShim', async function (t) { assert.ok(!segment.catTransaction) assert.ok(!segment.getAttributes().transaction_guid) - shim.handleMqTracingHeaders(headers) + shim.handleMqTracingHeaders(headers, null, tx) assert.ok(!segment.catId) assert.ok(!segment.catTransaction) diff --git a/test/unit/spans/span-event-aggregator.test.js b/test/unit/spans/span-event-aggregator.test.js index 6d5da42061..c506739326 100644 --- a/test/unit/spans/span-event-aggregator.test.js +++ b/test/unit/spans/span-event-aggregator.test.js @@ -60,7 +60,7 @@ test('SpanAggregator', async (t) => { assert.equal(spanEventAggregator.length, 0) - spanEventAggregator.addSegment(segment, 'p') + spanEventAggregator.addSegment({ segment, transaction: tx, parentId: 'p' }) assert.equal(spanEventAggregator.length, 1) const event = spanEventAggregator.getEvents()[0] @@ -84,7 +84,7 @@ test('SpanAggregator', async (t) => { const segment = agent.tracer.getSegment() assert.equal(spanEventAggregator.length, 0) - spanEventAggregator.addSegment(segment) + spanEventAggregator.addSegment({ segment, transaction: tx }) assert.equal(spanEventAggregator.length, 1) const event = spanEventAggregator.getEvents()[0] @@ -134,20 +134,20 @@ test('SpanAggregator', async (t) => { assert.equal(spanEventAggregator.seen, 0) // First segment is added regardless of priority. - assert.equal(spanEventAggregator.addSegment(segment), true) + assert.equal(spanEventAggregator.addSegment({ segment, transaction: tx }), true) assert.equal(spanEventAggregator.length, 1) assert.equal(spanEventAggregator.seen, 1) // Higher priority should be added. tx.priority = 100 - assert.equal(spanEventAggregator.addSegment(segment), true) + assert.equal(spanEventAggregator.addSegment({ segment, transaction: tx }), true) assert.equal(spanEventAggregator.length, 1) assert.equal(spanEventAggregator.seen, 2) const event1 = spanEventAggregator.getEvents()[0] // Lower priority should not be added. tx.priority = 1 - assert.equal(spanEventAggregator.addSegment(segment), false) + assert.equal(spanEventAggregator.addSegment({ segment, transaction: tx }), false) assert.equal(spanEventAggregator.length, 1) assert.equal(spanEventAggregator.seen, 3) const event2 = spanEventAggregator.getEvents()[0] @@ -173,7 +173,7 @@ test('SpanAggregator', async (t) => { setTimeout(() => { const segment = agent.tracer.getSegment() - spanEventAggregator.addSegment(segment) + spanEventAggregator.addSegment({ segment, transaction: tx }) const payload = spanEventAggregator._toPayloadSync() diff --git a/test/unit/spans/span-event.test.js b/test/unit/spans/span-event.test.js index 2629bf42e8..81e1cfa1ca 100644 --- a/test/unit/spans/span-event.test.js +++ b/test/unit/spans/span-event.test.js @@ -70,7 +70,7 @@ test('fromSegment()', async (t) => { const spanContext = segment.getSpanContext() spanContext.addCustomAttribute('Span Lee', 'no prize') - const span = SpanEvent.fromSegment(segment, 'parent') + const span = SpanEvent.fromSegment(segment, transaction, 'parent') // Should have all the normal properties. assert.ok(span) @@ -136,7 +136,7 @@ test('fromSegment()', async (t) => { res.resume() res.on('end', () => { const segment = agent.tracer.getTransaction().trace.root.children[0] - const span = SpanEvent.fromSegment(segment, 'parent') + const span = SpanEvent.fromSegment(segment, transaction, 'parent') // Should have all the normal properties. assert.ok(span) @@ -238,7 +238,7 @@ test('fromSegment()', async (t) => { dsConn.myDbOp(longQuery, () => { transaction.end() const segment = transaction.trace.root.children[0] - const span = SpanEvent.fromSegment(segment, 'parent') + const span = SpanEvent.fromSegment(segment, transaction, 'parent') // Should have all the normal properties. assert.ok(span) @@ -303,7 +303,7 @@ test('fromSegment()', async (t) => { setTimeout(() => { const segment = agent.tracer.getSegment() - const span = SpanEvent.fromSegment(segment, 'parent') + const span = SpanEvent.fromSegment(segment, transaction, 'parent') const serializedSpan = span.toJSON() const [intrinsics] = serializedSpan @@ -336,7 +336,7 @@ test('fromSegment()', async (t) => { spanContext.addIntrinsicAttribute('intrinsic.1', 1) spanContext.addIntrinsicAttribute('intrinsic.2', 2) - const span = SpanEvent.fromSegment(segment, 'parent') + const span = SpanEvent.fromSegment(segment, transaction, 'parent') const serializedSpan = span.toJSON() const [intrinsics] = serializedSpan @@ -360,7 +360,7 @@ test('fromSegment()', async (t) => { const segment = transaction.trace.root.children[0] assert.ok(segment.name.startsWith('Truncated')) - const span = SpanEvent.fromSegment(segment) + const span = SpanEvent.fromSegment(segment, transaction) assert.ok(span) assert.ok(span instanceof SpanEvent) assert.ok(span instanceof SpanEvent.HttpSpanEvent) @@ -379,7 +379,7 @@ test('fromSegment()', async (t) => { assert.ok(segment.name.startsWith('Truncated')) - const span = SpanEvent.fromSegment(segment) + const span = SpanEvent.fromSegment(segment, transaction) assert.ok(span) assert.ok(span instanceof SpanEvent) assert.ok(span instanceof SpanEvent.DatastoreSpanEvent) diff --git a/test/unit/spans/streaming-span-event.test.js b/test/unit/spans/streaming-span-event.test.js index 4c63ce144c..096aaba9f7 100644 --- a/test/unit/spans/streaming-span-event.test.js +++ b/test/unit/spans/streaming-span-event.test.js @@ -66,7 +66,7 @@ test('fromSegment()', async (t) => { segment.addSpanAttribute('host', 'my-host') segment.addSpanAttribute('port', 22) - const span = StreamingSpanEvent.fromSegment(segment, 'parent') + const span = StreamingSpanEvent.fromSegment(segment, transaction, 'parent') // Should have all the normal properties. assert.ok(span) @@ -131,7 +131,7 @@ test('fromSegment()', async (t) => { res.resume() res.on('end', () => { const segment = agent.tracer.getTransaction().trace.root.children[0] - const span = StreamingSpanEvent.fromSegment(segment, 'parent') + const span = StreamingSpanEvent.fromSegment(segment, transaction, 'parent') // Should have all the normal properties. assert.ok(span) @@ -238,7 +238,7 @@ test('fromSegment()', async (t) => { dsConn.myDbOp(longQuery, () => { transaction.end() const segment = transaction.trace.root.children[0] - const span = StreamingSpanEvent.fromSegment(segment, 'parent') + const span = StreamingSpanEvent.fromSegment(segment, transaction, 'parent') // Should have all the normal properties. assert.ok(span) @@ -329,7 +329,7 @@ test('fromSegment()', async (t) => { const spanContext = agent.tracer.getSpanContext() spanContext.addCustomAttribute('customKey', 'customValue') - const span = StreamingSpanEvent.fromSegment(segment, 'parent') + const span = StreamingSpanEvent.fromSegment(segment, transaction, 'parent') const serializedSpan = span.toStreamingFormat() const { @@ -366,7 +366,7 @@ test('fromSegment()', async (t) => { spanContext.addIntrinsicAttribute('intrinsic.1', 1) spanContext.addIntrinsicAttribute('intrinsic.2', 2) - const span = StreamingSpanEvent.fromSegment(segment, 'parent') + const span = StreamingSpanEvent.fromSegment(segment, transaction, 'parent') const serializedSpan = span.toStreamingFormat() const { intrinsics } = serializedSpan @@ -390,7 +390,7 @@ test('fromSegment()', async (t) => { const segment = transaction.trace.root.children[0] assert.ok(segment.name.startsWith('Truncated')) - const span = StreamingSpanEvent.fromSegment(segment) + const span = StreamingSpanEvent.fromSegment(segment, transaction) assert.ok(span) assert.ok(span instanceof StreamingSpanEvent) @@ -412,7 +412,7 @@ test('fromSegment()', async (t) => { assert.ok(segment.name.startsWith('Truncated')) - const span = StreamingSpanEvent.fromSegment(segment) + const span = StreamingSpanEvent.fromSegment(segment, transaction) assert.ok(span) assert.ok(span instanceof StreamingSpanEvent)