Skip to content

chore: Don't create OpenAI segments if ai_monitoring is disabled#3625

Merged
amychisholm03 merged 1 commit intonewrelic:mainfrom
amychisholm03:NR-3622/disabled-openai-spans
Dec 30, 2025
Merged

chore: Don't create OpenAI segments if ai_monitoring is disabled#3625
amychisholm03 merged 1 commit intonewrelic:mainfrom
amychisholm03:NR-3622/disabled-openai-spans

Conversation

@amychisholm03
Copy link
Contributor

Description

OpenAI instrumentation should not create segments if ai_monitoring.enabled === false. This PR adds this missing logic and tests to assert it.

How to Test

npm run versioned:major openai

Related Issues

Closes #3622

@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.71%. Comparing base (d1e90e4) to head (a8e0444).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3625      +/-   ##
==========================================
+ Coverage   89.39%   97.71%   +8.32%     
==========================================
  Files         437      438       +1     
  Lines       57537    57568      +31     
  Branches        1        1              
==========================================
+ Hits        51435    56254    +4819     
+ Misses       6102     1314    -4788     
Flag Coverage Δ
integration-tests-cjs-20.x 73.48% <5.88%> (?)
integration-tests-cjs-22.x 73.52% <5.88%> (-0.03%) ⬇️
integration-tests-cjs-24.x 74.25% <5.88%> (?)
integration-tests-esm-20.x 52.66% <5.88%> (?)
integration-tests-esm-22.x 52.71% <5.88%> (?)
integration-tests-esm-24.x 53.80% <5.88%> (?)
unit-tests-20.x 89.06% <5.88%> (?)
unit-tests-22.x 89.09% <5.88%> (?)
unit-tests-24.x 89.10% <5.88%> (?)
versioned-tests-20.x 80.81% <100.00%> (-0.31%) ⬇️
versioned-tests-22.x 80.82% <100.00%> (-0.32%) ⬇️
versioned-tests-24.x 80.75% <100.00%> (-0.31%) ⬇️

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.

@amychisholm03 amychisholm03 marked this pull request as ready for review December 24, 2025 00:53
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect there's a better way of handling this than to replicate checks in multiple methods across multiple implementations. Perhaps something like:

class Subscriber {
	enable() {
		if (this.shouldEnable === false) {
			this.logger.trace(
				{ packageName: this.packageName },
				'Not subscribing to channel events. Instrumentation is disabled.'
			)
			return
		}

		// do the real stuff
	}
}

Copy link
Contributor Author

@amychisholm03 amychisholm03 Dec 29, 2025

Choose a reason for hiding this comment

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

Ideally, this would be enough. However, because collect_ai / ai_monitoring can be changed serverside, we have to check the config values after the subscribers have been setup/enabled.

Also, I wanted to maintain parity with the other AIM subscribers, and I'll likely refactor this ai_monitoring check logic in #3487

@amychisholm03 amychisholm03 merged commit b4f0010 into newrelic:main Dec 30, 2025
27 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 Dec 30, 2025
@amychisholm03 amychisholm03 deleted the NR-3622/disabled-openai-spans branch December 30, 2025 15:22
@github-actions github-actions bot mentioned this pull request Jan 8, 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.

OpenAI instrumentation should not create spans when AIM is disabled

2 participants

Comments