Skip to content

Commit

Permalink
wip: fixed attr issues with using real otel libs
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 committed Feb 13, 2025
1 parent b85111c commit 72f52ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/otel/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ module.exports = {
*
* @example 200
*/
ATTR_HTTP_STATUS_CODE: 'http.response.status_code',
ATTR_HTTP_RES_STATUS_CODE: 'http.response.status_code',
ATTR_HTTP_STATUS_CODE: 'http.status_code',

/**
* The http response status text
Expand Down
14 changes: 9 additions & 5 deletions lib/otel/span-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
ATTR_HTTP_ROUTE,
ATTR_HTTP_STATUS_CODE,
ATTR_HTTP_STATUS_TEXT,
ATTR_HTTP_RES_STATUS_CODE,
ATTR_NET_PEER_NAME,
ATTR_NET_PEER_PORT,
ATTR_NET_HOST_NAME,
Expand Down Expand Up @@ -82,7 +83,10 @@ module.exports = class NrSpanProcessor {

// End the corresponding transaction for the entry point server span.
// We do then when the span ends to ensure all data has been processed
// for the correspondig server span.
// for the corresponding server span.
if (transaction.statusCode) {
transaction.finalizeNameFromUri(transaction.parsedUrl, transaction.statusCode)
}
transaction.end()
}

Expand All @@ -93,14 +97,14 @@ module.exports = class NrSpanProcessor {
if (key === ATTR_HTTP_ROUTE) {
// TODO: can we get the route params?
transaction.nameState.appendPath(sanitized)
} else if (key === ATTR_HTTP_STATUS_CODE) {
transaction.finalizeNameFromUri(transaction.parsedUrl, sanitized)
transaction.trace.attributes.addAttribute(DESTINATIONS.TRANS_COMMON, 'http.statusCode', sanitized)
} else if (key === ATTR_HTTP_STATUS_CODE || key === ATTR_HTTP_RES_STATUS_CODE) {
key = 'http.statusCode'
transaction.statusCode = sanitized
transaction.trace.attributes.addAttribute(DESTINATIONS.TRANS_COMMON, key, sanitized)
// Not using const as it is not in semantic-conventions
} else if (key === ATTR_HTTP_STATUS_TEXT) {
transaction.trace.attributes.addAttribute(DESTINATIONS.TRANS_COMMON, 'http.statusText', sanitized)
key = 'http.statusText'
transaction.trace.attributes.addAttribute(DESTINATIONS.TRANS_COMMON, key, sanitized)
} else if (key === ATTR_SERVER_PORT || key === ATTR_NET_HOST_PORT) {
key = 'port'
} else if (key === ATTR_SERVER_ADDRESS || key === ATTR_NET_HOST_NAME) {
Expand Down
1 change: 0 additions & 1 deletion lib/shim/message-shim/subscribe-consume.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ function createConsumerWrapper({ shim, spec, consumer }) {
* finalizes transaction name and ends transaction
*/
function endTransaction() {
tx.finalizeName(null) // Use existing partial name.
tx.end()
}
}
Expand Down

0 comments on commit 72f52ca

Please sign in to comment.