Skip to content

Add include/exclude settings for Hybrid Agent tracers#1681

Merged
lrafeei merged 23 commits intomainfrom
hybrid-agent-tracer-include-exclude
Mar 30, 2026
Merged

Add include/exclude settings for Hybrid Agent tracers#1681
lrafeei merged 23 commits intomainfrom
hybrid-agent-tracer-include-exclude

Conversation

@lrafeei
Copy link
Copy Markdown
Contributor

@lrafeei lrafeei commented Mar 9, 2026

This PR adds the following settings:

  • opentelemetry.traces.include (config file) or NEW_RELIC_OPENTELEMETRY_TRACES_INCLUDE (environment variable)
  • opentelemetry.traces.exclude (config file) or NEW_RELIC_OPENTELEMETRY_TRACES_EXCLUDE (environment variable)

Because these settings have been added, the default behavior of the agent with conflicting instrumentation has now changed. If New Relic and OpenTelemetry both support a framework, the Hybrid Agent will only use the OpenTelemetry instrumentation library if it is explicitly included in the include list. The only frameworks that are enabled by default when OpenTelemetry is enabled are those that are only supported by OpenTelemetry and not New Relic.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 9, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ ACTION actionlint 8 0 0 0.91s
✅ MARKDOWN markdownlint 7 0 0 0 1.47s
✅ PYTHON ruff 1030 0 0 0 1.07s
✅ PYTHON ruff-format 1030 0 0 0 0.44s
✅ YAML prettier 19 0 0 0 1.74s
✅ YAML v8r 19 0 0 5.13s
✅ YAML yamllint 19 0 0 0.76s

See detailed reports in MegaLinter artifacts

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@mergify mergify Bot added the tests-failing Tests failing in CI. label Mar 9, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 10, 2026

Codecov Report

❌ Patch coverage is 78.57143% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.88%. Comparing base (7343f58) to head (f43dde4).

Files with missing lines Patch % Lines
newrelic/hooks/hybridagent_opentelemetry.py 50.00% 4 Missing and 3 partials ⚠️
newrelic/api/opentelemetry.py 84.61% 0 Missing and 2 partials ⚠️
newrelic/core/config.py 77.77% 1 Missing and 1 partial ⚠️
newrelic/config.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1681      +/-   ##
==========================================
+ Coverage   81.85%   81.88%   +0.03%     
==========================================
  Files         214      214              
  Lines       25683    25702      +19     
  Branches     4076     4075       -1     
==========================================
+ Hits        21022    21047      +25     
+ Misses       3264     3262       -2     
+ Partials     1397     1393       -4     

☔ 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.

@lrafeei lrafeei marked this pull request as ready for review March 10, 2026 17:32
@lrafeei lrafeei requested a review from a team as a code owner March 10, 2026 17:32
@mergify mergify Bot added the merge-conflicts Merge conflicts detected. label Mar 10, 2026
@mergify mergify Bot removed the merge-conflicts Merge conflicts detected. label Mar 11, 2026
Comment thread newrelic/api/opentelemetry.py Outdated
Comment thread newrelic/api/opentelemetry.py Outdated
Comment thread newrelic/api/opentelemetry.py
Comment thread newrelic/core/config.py
Comment thread newrelic/hooks/hybridagent_opentelemetry.py Outdated
Comment thread newrelic/hooks/hybridagent_opentelemetry.py Outdated
Comment thread newrelic/hooks/hybridagent_opentelemetry.py Outdated
Comment thread newrelic/config.py
Comment thread newrelic/api/opentelemetry.py
@mergify mergify Bot removed the tests-failing Tests failing in CI. label Mar 18, 2026
@lrafeei lrafeei requested a review from hmstepanek March 26, 2026 17:25
Copy link
Copy Markdown
Contributor

@hmstepanek hmstepanek left a comment

Choose a reason for hiding this comment

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

A couple minor things and I had a question about the tests-I want to make sure we are validating the include and the exclude functionality.

Comment thread newrelic/core/config.py Outdated

def _environ_as_comma_separated_set(name, default=""):
value = os.environ.get(name, default)
if value in [None, ""]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the if not string inside the parser will catch both of these already so this is redundant.

Suggested change
if value in [None, ""]:

Comment thread newrelic/core/config.py Outdated
def _environ_as_comma_separated_set(name, default=""):
value = os.environ.get(name, default)
if value in [None, ""]:
return set()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return set()

Comment thread newrelic/config.py Outdated
internal included defaults, to determine which tracers
should be used.
"""
if not _settings.opentelemetry.enabled or not _is_installed("opentelemetry-api"):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this check is already present in the _process_opentelemetry_instrumentation_entry_points that calls this so this one might not be necessary. Also _is_installed may be a bit slow in some cases so it's better to call this as little as possible.

Suggested change
if not _settings.opentelemetry.enabled or not _is_installed("opentelemetry-api"):

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.

Good call--this only gets called from _process_opentelemetry_instrumentation_entry_points so we're good on that front.

Comment thread newrelic/config.py Outdated
should be used.
"""
if not _settings.opentelemetry.enabled or not _is_installed("opentelemetry-api"):
return
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return

@@ -22,7 +22,7 @@
"debug.log_data_collector_payloads": True,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should have some tests that validate the exclude in here too. Unless we do have them and I missed them?

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.

It's a little hard to tell, but the exclude tests are here: https://github.com/newrelic/newrelic-python-agent/pull/1681/changes#diff-435c3f1f807ec58cefd29e84a328657aa6f0f188b28586eb1e650e4999ba9042R99

Using the tests in the OpenTelemetry frameworks that are also supported in New Relic seemed to be the way to go for testing the include functionality while the exclude tests were done on custom tracers.

@lrafeei lrafeei requested a review from hmstepanek March 27, 2026 17:14
@lrafeei lrafeei merged commit a884f0e into main Mar 30, 2026
63 checks passed
@lrafeei lrafeei deleted the hybrid-agent-tracer-include-exclude branch March 30, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants