Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: wrapped up db 1.17 rules, wrapped up http client rules, need t…
…o do rpc client and fallback
  • Loading branch information
bizob2828 committed May 30, 2025
commit c0bca69fcfa366e17885b6e356ce58668feeabf4
2 changes: 1 addition & 1 deletion lib/otel/segment-synthesis.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SegmentSynthesizer {
}

case 'external': {
return createHttpExternalSegment(this.agent, otelSpan)
return createHttpExternalSegment(this.agent, otelSpan, rule.name)
}

case 'internal': {
Expand Down
13 changes: 10 additions & 3 deletions lib/otel/segments/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ module.exports = function createDbSegment(agent, otelSpan, rule) {
const { segment: segmentTransformation } = transformationRule
const system = otelSpan.attributes[segmentTransformation?.type]
const statement = otelSpan.attributes[segmentTransformation?.statement]
const operation = otelSpan.attributes[segmentTransformation?.operation]
const collection = otelSpan.attributes[segmentTransformation?.collection]
let operation = otelSpan.attributes[segmentTransformation?.operation]
let name, recorder
if (statement) {
const parsed = parseSql({ sql: statement })
if (statement || (operation && collection)) {
let parsed
if (collection && operation) {
parsed = { operation, collection }
} else {
parsed = parseSql({ sql: statement })
}
const queryRecorded =
agent.config.transaction_tracer.record_sql === 'raw' ||
agent.config.transaction_tracer.record_sql === 'obfuscated'
Expand All @@ -36,6 +42,7 @@ module.exports = function createDbSegment(agent, otelSpan, rule) {
name = transformTemplate(segmentTransformation.name.template, parsedStatement)
recorder = getRecorder({ operation: false, parsed: parsedStatement, system })
} else if (operation) {
;[operation] = operation.split(' ')
name = transformTemplate(segmentTransformation.name.template, { type: system, operation })
recorder = getRecorder({ operation: true, system })
}
Expand Down
26 changes: 13 additions & 13 deletions lib/otel/segments/http-external.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@

'use strict'

const NAMES = require('../../metrics/names')
const recordExternal = require('../../metrics/recorders/http_external')
const urltils = require('../../util/urltils')
const {
UNKNOWN
} = require('../constants')
const { httpAttr } = require('../attr-mapping/http')
const transformationRules = require('../transformation-rules')
const { transformTemplate } = require('./utils')
const { UNKNOWN } = require('../constants')

module.exports = function createHttpExternalSegment(agent, otelSpan) {
module.exports = function createHttpExternalSegment(agent, otelSpan, rule) {
const context = agent.tracer.getContext()
const method = httpAttr({ key: 'method', span: otelSpan })
const host = httpAttr({ key: 'clientHost', span: otelSpan }) ?? UNKNOWN
const transformationRule = transformationRules.find((tRule) => tRule.name === rule)
const { segment: segmentTransformation } = transformationRule

const url = httpAttr({ key: 'clientUrl', span: otelSpan })
let name = NAMES.EXTERNAL.PREFIX + host
const method = otelSpan?.attributes[segmentTransformation?.method]
const host = otelSpan?.attributes[segmentTransformation?.host] ?? UNKNOWN
const url = otelSpan?.attributes[segmentTransformation?.url]
let parsedUrl
let obfuscatedPath
let obfuscatedPath = `/${UNKNOWN}`
if (url) {
parsedUrl = new URL(url)
obfuscatedPath = urltils.obfuscatePath(agent.config, parsedUrl.pathname)
name += obfuscatedPath
}

const name = transformTemplate(segmentTransformation?.name?.template, { host, path: obfuscatedPath })

const segment = agent.tracer.createSegment({
id: otelSpan?.spanContext()?.spanId,
name,
Expand All @@ -47,5 +47,5 @@ module.exports = function createHttpExternalSegment(agent, otelSpan) {
queryParams: Object.fromEntries(parsedUrl.searchParams.entries())
})
}
return { segment, transaction: context.transaction }
return { segment, transaction: context.transaction, rule }
}
38 changes: 6 additions & 32 deletions lib/otel/span-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const {
SPAN_STATUS_CODE
} = require('./constants')
const { dbAttr } = require('./attr-mapping/db')
const { clientMapper, httpAttr } = require('./attr-mapping/http')
const { msgAttr, producerMapper } = require('./attr-mapping/messaging')
const { httpAttr } = require('./attr-mapping/http')
const { msgAttr } = require('./attr-mapping/messaging')
const { faasAttr } = require('./attr-mapping/faas')
const { exceptionAttr } = require('./attr-mapping/exceptions')
const urlRules = {
Expand Down Expand Up @@ -89,26 +89,16 @@ module.exports = class NrSpanProcessor {
}

reconcileAttributes({ segment, span, transaction, transformationRule }) {
const { transaction: txTransformation, attributes: attributesMapper } = transformationRule
this.mapAttributes({ segment, span, transaction, attributesMapper })

if (span.kind === SpanKind.SERVER || span.kind === SpanKind.CONSUMER) {
this.reconcileServerConsumerAttributes({ segment, span, transaction, transformationRule })
} else if (span.kind === SpanKind.CLIENT && dbAttr({ key: 'system', span })) {
this.reconcileDbAttributes({ segment, span, transformationRule })
} else if (span.kind === SpanKind.PRODUCER) {
this.reconcileProducerAttributes({ segment, span })
} else if (span.kind === SpanKind.CLIENT && httpAttr({ key: 'method', span })) {
this.reconcileHttpExternalAttributes({ segment, span })
} else {
this.#reconciler.reconcile({ segment, otelSpan: span })
this.finalizeTransaction({ segment, span, transaction, txTransformation })
}

this.addAWSLinkingAttributes({ segment, span })
}

reconcileHttpExternalAttributes({ segment, span }) {
const mapper = clientMapper({ segment })
this.#reconciler.reconcile({ segment, otelSpan: span, mapper })
}

mapAttributes({ segment, span, transaction, attributesMapper }) {
const mapper = {}
attributesMapper.forEach((attr) => {
Expand Down Expand Up @@ -209,22 +199,6 @@ module.exports = class NrSpanProcessor {
}
}

reconcileServerConsumerAttributes({ segment, span, transaction, transformationRule }) {
const { transaction: txTransformation, attributes: attributesMapper } = transformationRule
this.mapAttributes({ segment, span, transaction, attributesMapper })
this.finalizeTransaction({ segment, span, transaction, txTransformation })
}

reconcileDbAttributes({ segment, span, transformationRule }) {
const { attributes: attributesMapper } = transformationRule
this.mapAttributes({ segment, span, attributesMapper })
}

reconcileProducerAttributes({ segment, span }) {
const mapper = producerMapper({ segment })
this.#reconciler.reconcile({ segment, otelSpan: span, mapper })
}

addAWSLinkingAttributes({ segment, span }) {
const accountId = this.agent?.config?.cloud?.aws?.account_id
const region = faasAttr({ key: 'region', span })
Expand Down
Loading