Skip to content

feat: Added support for OTEL logs API #3228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jsumners-nr
Copy link
Contributor

@jsumners-nr jsumners-nr commented Jul 15, 2025

This PR resolves #3229.

Copy link

codecov bot commented Jul 15, 2025

Codecov Report

Attention: Patch coverage is 97.57085% with 6 lines in your changes missing coverage. Please review.

Project coverage is 97.62%. Comparing base (19c0c70) to head (b185dca).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
lib/otel/logs/no-op-exporter.js 76.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3228      +/-   ##
==========================================
- Coverage   97.67%   97.62%   -0.05%     
==========================================
  Files         340      344       +4     
  Lines       51436    51683     +247     
==========================================
+ Hits        50239    50458     +219     
- Misses       1197     1225      +28     
Flag Coverage Δ
integration-tests-cjs-18.x 73.86% <88.66%> (+0.26%) ⬆️
integration-tests-cjs-20.x 73.85% <88.66%> (+0.26%) ⬆️
integration-tests-cjs-22.x 73.90% <88.66%> (+0.27%) ⬆️
integration-tests-cjs-24.x 74.64% <88.66%> (+0.28%) ⬆️
integration-tests-esm-18.x 49.52% <59.91%> (+0.05%) ⬆️
integration-tests-esm-20.x 49.53% <59.91%> (+0.05%) ⬆️
integration-tests-esm-22.x 49.59% <59.91%> (+0.05%) ⬆️
integration-tests-esm-24.x 51.28% <59.91%> (+0.04%) ⬆️
unit-tests-18.x 88.32% <78.54%> (-0.05%) ⬇️
unit-tests-20.x 88.32% <78.54%> (-0.05%) ⬇️
unit-tests-22.x 88.33% <78.54%> (-0.05%) ⬇️
unit-tests-24.x 88.33% <78.54%> (-0.05%) ⬇️
versioned-tests-18.x 79.97% <61.94%> (-0.26%) ⬇️
versioned-tests-20.x 80.08% <61.94%> (-0.26%) ⬇️
versioned-tests-22.x 80.09% <61.94%> (-0.26%) ⬇️
versioned-tests-24.x 79.99% <61.94%> (-0.26%) ⬇️

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.

@jsumners-nr jsumners-nr marked this pull request as ready for review July 15, 2025 14:32
@bizob2828 bizob2828 self-assigned this Jul 15, 2025
assert.equal(nrShippedLogs.length, 1)
assert.equal(nrShippedLogs[0].common.attributes['entity.guid'], 'guid-123456')
const log = nrShippedLogs[0].logs[0]
assert.equal(log['entity.guid'], 'guid-123456')
Copy link
Member

Choose a reason for hiding this comment

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

The common attributes should not exist on the logs as well. I'd also add a test that runs this in a transaction so it can add the trace.id and span.id which should exist on the individual logs

// TODO: if we decide to support local decorating, implement it here

if (isLogForwardingEnabled(agent.config, agent) === true) {
const meta = agent.getLinkingMetadata()
Copy link
Member

Choose a reason for hiding this comment

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

if you pass in true this will omit the service level linking which should be done to avoid logging entity.guid, service etc in every log line

Copy link
Member

Choose a reason for hiding this comment

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

Also, you may want to add some versioned tests for an otel js contrib library. Looking at their instrumentation they add trace.id, span.id and traceFlags so there will be some overlap

const fakeCert = require('#testlib/fake-cert.js')
const helper = require('#testlib/agent_helper.js')

test.beforeEach(async (ctx) => {
Copy link
Member

Choose a reason for hiding this comment

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

you should add tests that disable application logging metrics and log forwarding and assert the proper data

@jsumners-nr jsumners-nr marked this pull request as draft July 15, 2025 19:29
isLogForwardingEnabled,
isMetricsEnabled,
incrementLoggingLinesMetrics
} = require('#agentlib/util/application-logging.js')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to point this out earlier: I'm using the #agentlib alias here. I think this will be a good case for testing the usage of that alias within the actual agent code. Currently, we only utilize it in test code. Team members are wanting to utilize it agent code, and this whole feature is in-development, which I think provides a good testing ground.

Copy link
Member

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

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

few comments

@@ -17,5 +17,10 @@ exports.config = {
detect_azure: false,
detect_gcp: false,
detect_docker: false
}
},
instrumentation: {
Copy link
Member

Choose a reason for hiding this comment

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

i'd move this to the test that relies on this being disabled

const agent = helper.instrumentMockedAgent({
opentelemetry_bridge: {
enabled: true,
logs: { enabled: true }
Copy link
Member

Choose a reason for hiding this comment

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

you need to also enable traces in otel bridge at the moment. this is because the context manager and trace propagator are registered there. The reason you aren't seeing any logs on tx is because of the lack of assigning the global context manager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs PR Review
Development

Successfully merging this pull request may close these issues.

Add support for OTEL logs API
2 participants