Skip to content

Conversation

hmstepanek
Copy link
Contributor

Overview

Add support for w3c traceparent sampled flag. See agent spec for details.

Copy link

github-actions bot commented Aug 13, 2025

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ ACTION actionlint 6 0 0 0.72s
✅ MARKDOWN markdownlint 7 0 0 0 1.24s
✅ MARKDOWN markdown-link-check 7 0 0 15.56s
✅ PYTHON ruff 937 0 0 0 0.92s
✅ PYTHON ruff-format 937 0 0 0 0.32s
✅ YAML prettier 13 0 0 0 1.32s
✅ YAML v8r 13 0 0 5.87s
✅ YAML yamllint 13 0 0 0.63s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

@mergify mergify bot added the tests-failing Tests failing in CI. label Aug 13, 2025
@codecov-commenter
Copy link

codecov-commenter commented Aug 13, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.01%. Comparing base (b6631c8) to head (302749a).

Files with missing lines Patch % Lines
newrelic/api/transaction.py 90.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1448      +/-   ##
==========================================
- Coverage   80.33%   79.01%   -1.33%     
==========================================
  Files         209      209              
  Lines       23709    23737      +28     
  Branches     3740     3745       +5     
==========================================
- Hits        19047    18755     -292     
- Misses       3437     3768     +331     
+ Partials     1225     1214      -11     

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

@hmstepanek hmstepanek force-pushed the add-w3c-traceparent-header-support branch 2 times, most recently from 9df984c to 8a24ae6 Compare August 19, 2025 00:20
@hmstepanek hmstepanek force-pushed the add-w3c-traceparent-header-support branch from 8a24ae6 to bd981c4 Compare August 19, 2025 00:21
@hmstepanek hmstepanek marked this pull request as ready for review August 19, 2025 00:21
@hmstepanek hmstepanek requested a review from a team as a code owner August 19, 2025 00:21
@mergify mergify bot removed the tests-failing Tests failing in CI. label Aug 19, 2025
@hmstepanek hmstepanek force-pushed the add-w3c-traceparent-header-support branch from 3be0999 to 971ede6 Compare August 19, 2025 17:08
Comment on lines 416 to 432
@pytest.mark.parametrize(
"sampled,remote_parent_sampled,remote_parent_not_sampled,expected_sampled,expected_priority,expected_adaptive_sampling_algo_called",
(
(True, 'default', 'default', None, None, True), # Uses sampling algo.
(True, 'always_on', 'default', True, 2, False), # Always sampled.
(True, 'always_off', 'default', False, 0, False), # Never sampled.
(False, 'default', 'default', None, None, True), # Uses sampling algo.
(False, 'always_on', 'default', None, None, True), # Uses sampling alog.
(False, 'always_off', 'default', None, None, True), # Uses sampling algo.
(True, 'default', 'always_on', None, None, True), # Uses sampling algo.
(True, 'default', 'always_off', None, None, True), # Uses sampling algo.
(False, 'default', 'always_on', True, 2, False), # Always sampled.
(False, 'default', 'always_off', False, 0, False), # Never sampled.
)
)
def test_distributed_trace_w3cparent_sampling_decision(sampled, remote_parent_sampled, remote_parent_not_sampled, expected_sampled, expected_priority, expected_adaptive_sampling_algo_called, wrap_sampling_algo_compute_sampled_and_priority):
required_intrinsics = []
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this should potentially be ported to the cross agent tests and standarized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a really good point! It doesn't look like we have any but I'll create a ticket for myself to add some-then maybe we can get rid of this one in leu of the cross agent test.

Comment on lines 464 to 475
@pytest.fixture
def wrap_sampling_algo_compute_sampled_and_priority():
global was_called
was_called = False

def _wrap_sampling_algo_compute_sampled_and_priority(wrapped, instance, args, kwargs):
global was_called
was_called = True
return wrapped(*args, **kwargs)

return _wrap_sampling_algo_compute_sampled_and_priority

Copy link
Contributor

Choose a reason for hiding this comment

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

The code here in this fixture and the code that's applying this as a wrapper should be a validator and go in the validators folder. This should be using a transient function wrapper that auto applies and unapplies this wrapping to the sampling_algo... function when the test runs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're looking for validate_function_called

@hmstepanek hmstepanek requested a review from TimPansino August 21, 2025 23:26
@mergify mergify bot added the tests-failing Tests failing in CI. label Aug 21, 2025
Copy link
Contributor

@TimPansino TimPansino left a comment

Choose a reason for hiding this comment

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

There's a bunch of places where the imports are screwed up now due to moving that validator, I'll stop reviewing there and let you re-check those.

@@ -15,7 +15,7 @@
import django
import pytest
import webtest
from testing_support.fixtures import function_not_called, override_generic_settings
from testing_support.validators.validate_function_not_called import validate_function_not_called, override_generic_settings
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from testing_support.validators.validate_function_not_called import validate_function_not_called, override_generic_settings
from testing_support.fixtures import override_generic_settings
from testing_support.validators.validate_function_not_called import validate_function_not_called

Comment on lines 19 to 20
from testing_support.fixtures import (
function_not_called,
validate_function_not_called,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from testing_support.fixtures import (
function_not_called,
validate_function_not_called,
from testing_support.fixture.validate_function_not_called import validate_function_not_called
from testing_support.fixtures import (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests-failing Tests failing in CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants