-
Notifications
You must be signed in to change notification settings - Fork 440
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
Add composite propagator #597
Conversation
Codecov Report
@@ Coverage Diff @@
## main #597 +/- ##
==========================================
+ Coverage 94.33% 94.39% +0.05%
==========================================
Files 189 191 +2
Lines 8964 9023 +59
==========================================
+ Hits 8456 8517 +61
+ Misses 508 506 -2
|
Co-authored-by: Reiley Yang <reyang@microsoft.com>
class CompositePropagator : public TextMapPropagator<T> | ||
{ | ||
public: | ||
CompositePropagator(std::vector<std::shared_ptr<TextMapPropagator<T>>> &propagators) |
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.
A few minor nitpicks:
- Should
CompositePropagator
own the propagators? i.e. use unique_ptr over shared_ptr? - Pass by value and
std::move
? - Would it help to add a method to add a propagator to composite propagator?
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.
- Should
CompositePropagator
own the propagators? i.e. use unique_ptr over shared_ptr?- Pass by value and
std::move
?
Very valid points. I can't think of scenario where we need to share Propagator across. Will fix this, unless someone further comments with some scenario.
- Would it help to add a method to add a propagator to composite propagator?
This should help if we need to add propagator after creating the initial composite object. Specs ( https://github.com/open-telemetry/opentelemetry-specification/blob/14d123c121b6caa53bffd011292c42a181c9ca26/specification/context/api-propagators.md#composite-propagator ) doesn't ask for it explicitly so would keep it as it for now. We can add later if required.
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.
First two points are implemented now.
#include "opentelemetry/context/context.h" | ||
#include "opentelemetry/nostd/shared_ptr.h" | ||
#include "opentelemetry/nostd/span.h" | ||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/trace/default_span.h" | ||
#include "opentelemetry/trace/noop.h" | ||
#include "opentelemetry/trace/span.h" | ||
#include "opentelemetry/trace/span_context.h" | ||
#include "opentelemetry/trace/trace_id.h" | ||
#include "opentelemetry/trace/tracer.h" |
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.
Are all of these includes needed or only some of 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.
Not all, will remove.
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.
done
{ | ||
return nostd::string_view(it->second); | ||
} | ||
return ""; |
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 return nullptr
here?
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.
This will need change across all propagators. We can do it separately if needed, not in current scope of this PR.
{ | ||
for (auto &p : propagators_) | ||
{ | ||
context = p->Extract(getter, carrier, context); |
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.
There seems no need to assign all intermediate extracted context to input context. Probably create temp context::Context
to hold the extracted context and return the last one?
Is it possible to get empty propagators_
list, then return the input parameter context? Do we need initialize the context to empty in such case?
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.
There seems no need to assign all intermediate extracted context to input context. Probably create temp
context::Context
to hold the extracted context and return the last one?
Good point - I did implement this initially, but then later discovered that all other languages implementations are modifying the input context and so reverted. Specs doesn't say anything about it, so was unsure. Have changed it back as you suggested now. Let me know if you see any concerns here :)
Is it possible to get empty propagators_ list, then return the input parameter context? Do we need initialize the context to empty in such case?
Yes it's possible to get empty list, and we should be returning the input context unchanged it that case.
Fixes #541
Changes
Add composite propagator as per specs:
https://github.com/open-telemetry/opentelemetry-specification/blob/14d123c121b6caa53bffd011292c42a181c9ca26/specification/context/api-propagators.md#composite-propagator
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes