Skip to content
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

NH-30870 calculate_attributes adds existing attrs earlier #102

Merged
merged 10 commits into from
Jan 17, 2023

Conversation

tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Jan 11, 2023

Bugfix: custom sampler's calculate_attributes now adds existing attributes earlier. This is important for scenarios where the customer uses the SDK to start spans with custom attributes, e.g.

  with tracer.start_as_current_span(
      "manual_instrumentation_django_a",
      attributes={"foo-django-a": "bar-django-a"},
  ):
    # do stuff

Example trace with this fix: https://my.na-01.st-ssp.solarwinds.com/136444677275740160/traces/6D23EB224226CC4A59FA70D95C0BB1BE/892E8BFFDE370C5D/details/789BCA3EB9F3A9A0/rawData which was created using this WIP testbed update: https://github.com/appoptics/solarwinds-apm-python-testbed/pull/45

Add a unit tests. All are passing.

@tammy-baylis-swi tammy-baylis-swi requested review from cheempz and a team January 11, 2023 22:51
Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

Thanks for catching this @tammy-baylis-swi! The fix itself works, but has opened a small can of worms in my mind on how it relates to the setting of our sw.tracestate_parent_id attribute ;p

if sw_value and self._SW_TRACESTATE_ROOT_KEY not in new_attributes:
new_attributes[
self._SW_TRACESTATE_ROOT_KEY
] = W3CTransformer.span_id_from_sw(sw_value)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering now why this else is predicated on whether there is attributes... is it because we're using the presence of attributes to determine that "this is a root span for the service" (i.e. root span with no parent context or with a remote parent context) -- to just set the tracestate attr once per trace?

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 was hoping you knew, and the unit tests around this are so brittle. 🙃 The presence of attributes to check for that kinda makes sense, but why wouldn't it it just check for those contexts instead? If it was younger Tammy writing her very first sample that could be an excuse... I'll look more into this!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In b56c871, c26c7ea I've changed the condition to add sw.w3c.tracestate to attributes if the value is available from the parent and the parent is_remote, not based on existing attributes. This I think better matches scenario 5 in W3C Acceptance Criteria:

service root span reports KV sw.w3c.tracestate set to value of the inbound tracestate header as-is

Unit tests all pass. Trace still exports (example), though it's through ConsoleSpanExporter that I could see that the server span for Django B's home_b/ route is the only one in the Django A-B distributed trace that has sw.w3c.tracestate set (e.g. attributes > "sw.w3c.tracestate": "sw=f452fc038dc44249-01").

As to why this has been based on injected/existing attributes this whole time, I couldn't find it in my old manual test docs!

if attributes:
# Copy existing MappingProxyType KV into new_attributes for modification.
# These attributes may have other vendor info, customer-entered
# info from manual SDK calls, etc
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, if attributes is passed directly from the start trace --> sampler --> here, it seems it would only carry attributes set either by an instrumentation library, or by a manual SDK call. Not sure if there would be other vendor info?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Fixed the comment in 4fd8050

@tammy-baylis-swi
Copy link
Contributor Author

tammy-baylis-swi commented Jan 14, 2023

Thanks @cheempz for checking the fix and asking about that weeeeird sw.w3c.tracestate sw.tracestate_parent_id condition! Please could you have another look when you have a moment.

@tammy-baylis-swi
Copy link
Contributor Author

Hi again @cheempz ! Thank you for pointing out my wording of sw.w3c.tracestate instead of sw.tracestate_parent_id -- yikes!

As we chatted, the logic was still correct in that sw.tracestate_parent_id is set as the parent span ID if it exists. I've enhanced some unit tests in b52a857, and updated comment and changelog in 9585d5c and 5b99a1c. Also adjusted logging in f4344a3.

Please let me know what you think this time!

Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

👍 thanks for the revisit @tammy-baylis-swi!

@tammy-baylis-swi tammy-baylis-swi merged commit 82113ae into main Jan 17, 2023
@tammy-baylis-swi tammy-baylis-swi deleted the NH-30870-bugfix-update-attributes branch January 17, 2023 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants