Skip to content

Commit

Permalink
feat: Removed children from segments. (#2689)
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 committed Oct 31, 2024
1 parent 58aaf88 commit ef91b23
Show file tree
Hide file tree
Showing 127 changed files with 1,501 additions and 1,413 deletions.
13 changes: 0 additions & 13 deletions lib/instrumentation/nextjs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,3 @@ utils.isMiddlewareInstrumentationSupported = function isMiddlewareInstrumentatio
semver.gte(version, MIN_MW_SUPPORTED_VERSION) && semver.lte(version, MAX_MW_SUPPORTED_VERSION)
)
}

/**
* Depending on the Next.js version the segment tree varies as it adds setTimeout segments.
* This util will find the segment that has `getServerSideProps` in the name
*
* @param {object} rootSegment trace root
* @returns {object} getServerSideProps segment
*/
utils.getServerSidePropsSegment = function getServerSidePropsSegment(rootSegment) {
return rootSegment.children[0].children.find((segment) =>
segment.name.includes('getServerSideProps')
)
}
2 changes: 1 addition & 1 deletion lib/metrics/recorders/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const NAMES = require('../names')

function record(segment, scope, transaction) {
const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis(transaction.trace)
const name = NAMES.CUSTOM + NAMES.ACTION_DELIMITER + segment.name

if (scope) {
Expand Down
3 changes: 1 addition & 2 deletions lib/metrics/recorders/database-operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const metrics = require('../names')
*/
function recordOperationMetrics(segment, scope, transaction) {
const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const transaction = segment.transaction
const exclusive = segment.getExclusiveDurationInMillis(transaction.trace)
const type = transaction.isWeb() ? 'allWeb' : 'allOther'
const operation = segment.name

Expand Down
10 changes: 8 additions & 2 deletions lib/metrics/recorders/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { DESTINATIONS } = require('../../config/attribute-filter')

function recordQueryMetrics(segment, scope, transaction) {
const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis(transaction.trace)
const type = transaction.isWeb() ? DB.WEB : DB.OTHER
const thisTypeSlash = this.type + '/'
const operation = DB.OPERATION + '/' + thisTypeSlash + this.operation
Expand Down Expand Up @@ -60,7 +60,13 @@ function recordQueryMetrics(segment, scope, transaction) {
}

if (this.raw) {
segment.transaction.agent.queries.add(segment, this.type.toLowerCase(), this.raw, this.trace)
transaction.agent.queries.add({
segment,
transaction,
type: this.type.toLowerCase(),
query: this.raw,
trace: this.trace
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/recorders/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

function record(segment, scope, transaction) {
const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis(transaction.trace)

if (scope) {
transaction.measure(segment.name, scope, duration, exclusive)
Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/recorders/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function recordWeb(segment, scope, tx) {

const duration = segment.getDurationInMillis()
const totalTime = tx.trace.getTotalTimeDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis(tx.trace)
const partial = segment.partialName
const config = tx.agent.config
// named / key transaction support requires per-name apdexT
Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/recorders/http_external.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const EXTERNAL = require('../../metrics/names').EXTERNAL
function recordExternal(host, library) {
return function externalRecorder(segment, scope, transaction) {
const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis(transaction.trace)
const metricName = EXTERNAL.PREFIX + host + '/' + library
const rollupType = transaction.isWeb() ? EXTERNAL.WEB : EXTERNAL.OTHER
const rollupHost = EXTERNAL.PREFIX + host + '/all'
Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/recorders/message-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function recordMessageTransaction(segment, scope, tx) {
}

const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis(tx.trace)
const totalTime = tx.trace.getTotalTimeDurationInMillis()

if (scope) {
Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/recorders/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
function makeMiddlewareRecorder(_shim, metricName) {
return function middlewareMetricRecorder(segment, scope, transaction) {
const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis(transaction.trace)

if (scope) {
transaction.measure(metricName, scope, duration, exclusive)
Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/recorders/other.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function recordBackground(segment, scope, tx) {
}

const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis(tx.trace)
const totalTime = tx.trace.getTotalTimeDurationInMillis()
const name = segment.partialName

Expand Down
3 changes: 1 addition & 2 deletions lib/shim/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1325,8 +1325,7 @@ function createSegment(name, recorder, parent) {
* @param {Shim} params.shim instance of shim
* @param {Transaction} params.transaction active transaction
* @param {TraceSegment} params.parent the segment that will be the parent of the newly created segment
* @param params.spec
* @param {string|specs.SegmentSpec} spec options for creating segment
* @param {string|specs.SegmentSpec} params.spec options for creating segment
* @returns {?TraceSegment} A new trace segment if a transaction is active, else
* `null` is returned.
*/
Expand Down
6 changes: 4 additions & 2 deletions lib/transaction/trace/exclusive-time-calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
'use strict'

class ExclusiveCalculator {
constructor(root) {
constructor(root, trace) {
this.trace = trace
this.id = root.id
this.toProcess = [root]
// use a second stack to do a post-order traversal
this.parentStack = []
Expand All @@ -19,7 +21,7 @@ class ExclusiveCalculator {
process() {
while (this.toProcess.length) {
const segment = this.toProcess.pop()
const children = segment.getChildren()
const children = this.trace.getChildren(segment.id)
// when we hit a leaf, calc the exclusive time and report the time
// range to the parent
if (children.length === 0) {
Expand Down
Loading

0 comments on commit ef91b23

Please sign in to comment.