-
Notifications
You must be signed in to change notification settings - Fork 48
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
Conversation
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's strange
then(tracer.getBaggage(KEY_1).get()).isNull(); | ||
then(tracer.getBaggage(OBSERVATION_BAGGAGE_KEY).get()).isNull(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course
|
||
private static List<String> remoteFields(List<String> tagFields, List<String> remoteFields) { | ||
List<String> combined = new ArrayList<>(tagFields); | ||
combined.addAll(remoteFields); |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
for (String remoteField : tracer.getBaggageFields()) { | ||
lowerCaseRemoteFields.add(remoteField.toLowerCase()); | ||
} | ||
Set<KeyValue> baggageKeyValues = new HashSet<>(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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 |
Currently looking at the changes in boot. Looks like the So this is the only required change in Boot? ===================================================================
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfiguration.java
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfiguration.java (revision 5141045f6f64b1ec265aeba2b9bdb647f655fc21)
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/BraveAutoConfiguration.java (date 1723454089310)
@@ -155,7 +155,10 @@
@ConditionalOnMissingBean(io.micrometer.tracing.Tracer.class)
BraveTracer braveTracerBridge(brave.Tracer tracer, CurrentTraceContext currentTraceContext) {
return new BraveTracer(tracer, new BraveCurrentTraceContext(currentTraceContext),
- new BraveBaggageManager(this.tracingProperties.getBaggage().getTagFields()));
+ new BraveBaggageManager(
+ this.tracingProperties.getBaggage().getTagFields(),
+ this.tracingProperties.getBaggage().getRemoteFields()
+ ));
}
@Bean So we need to change the propagation somehow? https://github.com/spring-projects/spring-boot/blob/4b0bed23b054e400c33589d27812c0ad686421e7/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/BravePropagationConfigurations.java#L113 and https://github.com/spring-projects/spring-boot/blob/a0a804cfdf05f3e15bcc119c06ac3a85939c4ba0/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryPropagationConfigurations.java#L73 ? |
@mhalbritter I think that's it, since I don't think propagators should be changed since they are using the baggages after they are set (this change sets them from the If you want to play with this or write tests to see that Boot's auto-configuration results in the right behavior, here's a test example with OTel, Brave should only differ in the "configuration" part of the test: https://docs.micrometer.io/tracing/reference/1.4-SNAPSHOT/api.html#_baggage_with_micrometer_observation_api |
Thanks @jonatan-ivanov ! |
It's on |
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:
related #455