Skip to content

chore: Added audit logging for OTEL metrics#4018

Merged
jsumners-nr merged 6 commits into
newrelic:mainfrom
jsumners-nr:issue-4015
May 27, 2026
Merged

chore: Added audit logging for OTEL metrics#4018
jsumners-nr merged 6 commits into
newrelic:mainfrom
jsumners-nr:issue-4015

Conversation

@jsumners-nr
Copy link
Copy Markdown
Contributor

@jsumners-nr jsumners-nr commented May 21, 2026

This PR resolves #4015.

Technically, we are supposed to log the URI for every outgoing request. But we can't access the transport. So the best we'd be able to do is to log the URL that we pass in for configuration. I omitted that because I don't see the benefit.

Additionally, I brought up the fact that we can't access the transport in our Slack channel and had a discussion about the "MUST" requirements in the spec PR. The consensus is that some agents may not be able to meet those requirements, and should be able to make a best effort. We can't meet any of the "MUST" requirements as they are outlined, so this is our best effort.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.33%. Comparing base (c5fd80a) to head (8b96954).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4018      +/-   ##
==========================================
- Coverage   97.35%   97.33%   -0.02%     
==========================================
  Files         507      513       +6     
  Lines       61530    61610      +80     
  Branches        1        1              
==========================================
+ Hits        59903    59970      +67     
- Misses       1627     1640      +13     
Flag Coverage Δ
integration-tests-cjs-22.x 73.56% <84.02%> (+0.21%) ⬆️
integration-tests-cjs-24.x 74.17% <84.02%> (+0.20%) ⬆️
integration-tests-esm-22.x 53.99% <75.00%> (+0.24%) ⬆️
integration-tests-esm-24.x 55.16% <75.00%> (+0.24%) ⬆️
unit-tests-22.x 89.09% <100.00%> (+0.42%) ⬆️
unit-tests-24.x 89.09% <100.00%> (+0.42%) ⬆️
versioned-tests-22.x 80.42% <50.51%> (-0.47%) ⬇️
versioned-tests-24.x 79.87% <59.79%> (-0.85%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread lib/util/logger.js
Comment on lines +215 to +222
loggingFunctions.audit = function audit(...args) {
if (this.options.auditLogging === true) {
return this.info.apply(this, args)
}
if (this.traceEnabled() === true) {
return this.trace.apply(this, args)
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because the only place I could find where we use config.audit_log is at

// If trace level is not explicitly enabled check to see if the audit log is
// enabled.
if (
logConfig != null &&
logConfig.level !== 'trace' &&
auditLog.enabled &&
(auditLog.endpoints.length === 0 || auditLog.endpoints.indexOf(this.name) > -1)
) {
level = 'info'
}

I thought it would be rather silly to duplicate the above logic multiple times in this new code. So I centralized it in the logger.

@jsumners-nr jsumners-nr marked this pull request as ready for review May 21, 2026 19:53
@jsumners-nr jsumners-nr requested a review from bizob2828 May 26, 2026 12:43
@bizob2828 bizob2828 self-assigned this May 26, 2026
Comment thread lib/otel/metrics/nr-proxying-serializer.js
Comment thread lib/otel/metrics/nr-proxying-serializer.js
Comment thread lib/otel/metrics/nr-proxying-serializer.js
Comment thread lib/util/logger.js
Comment thread lib/otel/metrics/nr-exporter.js Outdated
Comment thread lib/otel/metrics/nr-exporter.js Outdated
Comment thread test/unit/lib/otel/metrics/nr-proxying-serializer.test.js
@jsumners-nr jsumners-nr merged commit 494c836 into newrelic:main May 27, 2026
26 of 29 checks passed
@github-project-automation github-project-automation Bot moved this from Needs PR Review to Done: Issues recently completed in Node.js Engineering Board May 27, 2026
@jsumners-nr jsumners-nr deleted the issue-4015 branch May 27, 2026 15:58
This was referenced Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done: Issues recently completed

Development

Successfully merging this pull request may close these issues.

Add audit logging support to OTEL metrics feature

3 participants