1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
6 #include <initializer_list>
9 #include "opentelemetry/context/propagation/text_map_propagator.h"
11 OPENTELEMETRY_BEGIN_NAMESPACE
17 class CompositePropagator
: public TextMapPropagator
20 CompositePropagator(std::vector
<std::unique_ptr
<TextMapPropagator
>> propagators
)
21 : propagators_(std::move(propagators
))
25 * Run each of the configured propagators with the given context and carrier.
26 * Propagators are run in the order they are configured, so if multiple
27 * propagators write the same carrier key, the propagator later in the list
30 * @param carrier Carrier into which context will be injected
31 * @param context Context to inject
35 void Inject(TextMapCarrier
&carrier
, const context::Context
&context
) noexcept override
37 for (auto &p
: propagators_
)
39 p
->Inject(carrier
, context
);
44 * Run each of the configured propagators with the given context and carrier.
45 * Propagators are run in the order they are configured, so if multiple
46 * propagators write the same context key, the propagator later in the list
49 * @param carrier Carrier from which to extract context
50 * @param context Context to add values to
52 context::Context
Extract(const TextMapCarrier
&carrier
,
53 context::Context
&context
) noexcept override
56 context::Context tmp_context
;
57 for (auto &p
: propagators_
)
61 tmp_context
= p
->Extract(carrier
, context
);
66 tmp_context
= p
->Extract(carrier
, tmp_context
);
69 return propagators_
.size() ? tmp_context
: context
;
73 * Invoke callback with fields set to carrier by `inject` method for all the
74 * configured propagators
75 * Returns true if all invocation return true
77 bool Fields(nostd::function_ref
<bool(nostd::string_view
)> callback
) const noexcept override
80 for (auto &p
: propagators_
)
82 status
= status
&& p
->Fields(callback
);
88 std::vector
<std::unique_ptr
<TextMapPropagator
>> propagators_
;
90 } // namespace propagation
91 } // namespace context
92 OPENTELEMETRY_END_NAMESPACE
;