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

Add composite propagator #597

Merged
merged 9 commits into from
Mar 9, 2021
Merged

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented Mar 5, 2021

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
  • Unit tests have been added
  • Changes in public API reviewed

@lalitb lalitb requested a review from a team March 5, 2021 11:16
@codecov
Copy link

codecov bot commented Mar 5, 2021

Codecov Report

Merging #597 (59be748) into main (b8a08eb) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
...telemetry/trace/propagation/composite_propagator.h 100.00% <100.00%> (ø)
...est/trace/propagation/composite_propagator_test.cc 100.00% <100.00%> (ø)
sdk/include/opentelemetry/sdk/metrics/controller.h 96.66% <0.00%> (+6.66%) ⬆️

Co-authored-by: Reiley Yang <reyang@microsoft.com>
class CompositePropagator : public TextMapPropagator<T>
{
public:
CompositePropagator(std::vector<std::shared_ptr<TextMapPropagator<T>>> &propagators)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Comment on lines 1 to 10
#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"
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not all, will remove.

Copy link
Member Author

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 "";
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 return nullptr here?

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

@lalitb lalitb Mar 9, 2021

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.

@lalitb lalitb merged commit 58a1e8c into open-telemetry:main Mar 9, 2021
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.

Implement Composite Propagator
4 participants