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

Added an option to have baggage through Observation API #688

Merged
merged 5 commits into from
May 20, 2024

Conversation

marcingrzejszczak
Copy link
Contributor

@marcingrzejszczak marcingrzejszczak commented May 7, 2024

whenever a key-value matches a preconfigured baggage config and an Observation started a scope then automatically baggages will also be started

fixes gh-455

TODO:

  • docs
  • boot autoconfig to set up baggage on baggagemanagers

related #455

whenever a key-value matches a preconfigured baggage config and an Observation started a scope then automatically baggages will also be started

fixes gh-455

private static List<String> remoteFields(List<String> tagFields, List<String> remoteFields) {
List<String> combined = new ArrayList<>(tagFields);
combined.addAll(remoteFields);
Copy link
Member

Choose a reason for hiding this comment

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

Why are these combined? It looks like the other baggage managers don't combine them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So when you have tag fields it means that it's baggage that additionally will be tagged. Inc case of Brave we never had a constructor that accepts just remote fields and I can't introduce one cause we have a constructor for tag fields already. So it does make sense to combine them. Of course I should combine those for other baggage managers too - I'll look into that, thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to create a unique set of fields?
The values seem to be used in the handler for contains, so in the end, it doesn't need to be unique here, but just for clarity.

Copy link
Member

Choose a reason for hiding this comment

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

I think I'm still confused. The assumption seems to be that all tagFields are remote baggage. Is local baggage that should also be tagged not possible? In the test code, it looks like the baggage key to be tagged is local baggage:

.add(BaggagePropagationConfig.SingleBaggageField.local(BaggageField.create(TAG_KEY)))

So shouldn't that not be combined with remote fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the point of view of a baggage manager there is no concept of local fields. That is really brave specific and has to be configured via propagation configuration. I understand that this might be confusing. We can rename this from remoteFields to baggageFields and that way that will mean all baggage regardless of whether it's local or remote. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good.

*/
public BraveBaggageManager(List<String> tagFields) {
public BraveBaggageManager(List<String> tagFields, List<String> remoteFields) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we introduce a new ctor?
Can any of these be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't - type inference is the same. They can't be null, we have non null api by default. We can pass empty collections

* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
Copy link
Member

Choose a reason for hiding this comment

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

The license format is different for other files.

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 strange

Comment on lines +286 to +287
then(tracer.getBaggage(KEY_1).get()).isNull();
then(tracer.getBaggage(OBSERVATION_BAGGAGE_KEY).get()).isNull();
Copy link
Member

Choose a reason for hiding this comment

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

Can we do these check before opening the scope too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course

@marcingrzejszczak marcingrzejszczak marked this pull request as ready for review May 8, 2024 08:01

private static List<String> remoteFields(List<String> tagFields, List<String> remoteFields) {
List<String> combined = new ArrayList<>(tagFields);
combined.addAll(remoteFields);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to create a unique set of fields?
The values seem to be used in the handler for contains, so in the end, it doesn't need to be unique here, but just for clarity.

}

private static List<KeyValue> matchingBaggageKeyValues(Tracer tracer, ContextView context) {
List<String> lowerCaseRemoteFields = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to make it a Set for being used with contains for small performance optimization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've applied both suggestions

@marcingrzejszczak marcingrzejszczak added this to the 1.4.0-M1 milestone May 9, 2024
for (String remoteField : tracer.getBaggageFields()) {
lowerCaseRemoteFields.add(remoteField.toLowerCase());
}
Set<KeyValue> baggageKeyValues = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Different from the lowerCaseRemoteFields variable, this baggageKeyValues variable (and the return type of this method, etc) might be better to keep as List. That way, creating BaggageInScope is always in a predictable order which might give an easier debug experience, just in case. If the ordering doesn't really matter, then Set is ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I fixed that

@marcingrzejszczak
Copy link
Contributor Author

cc @mhalbritter once we merge this, the constructors for baggagemanagers changed (non breaking change) so in boot we could start using the remote fields property to set the baggage fields on the baggage managers

@marcingrzejszczak marcingrzejszczak merged commit 4b2a93e into main May 20, 2024
6 checks passed
@marcingrzejszczak marcingrzejszczak deleted the baggage_through_observation branch May 20, 2024 15:50
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.

Propagating values from Observation.Context to Trace's Baggage
4 participants