forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate baggage<->Context api from Baggage Propagator (open-telemetr…
- Loading branch information
Showing
3 changed files
with
63 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "opentelemetry/baggage/baggage.h" | ||
#include "opentelemetry/context/context.h" | ||
#include "opentelemetry/nostd/shared_ptr.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
|
||
namespace baggage | ||
{ | ||
|
||
static const std::string kBaggageHeader = "baggage"; | ||
|
||
inline nostd::shared_ptr<opentelemetry::baggage::Baggage> GetBaggage( | ||
const opentelemetry::context::Context &context) | ||
{ | ||
context::ContextValue context_value = context.GetValue(kBaggageHeader); | ||
if (nostd::holds_alternative<nostd::shared_ptr<opentelemetry::baggage::Baggage>>(context_value)) | ||
{ | ||
return nostd::get<nostd::shared_ptr<opentelemetry::baggage::Baggage>>(context_value); | ||
} | ||
static nostd::shared_ptr<opentelemetry::baggage::Baggage> empty_baggage{ | ||
new opentelemetry::baggage::Baggage()}; | ||
return empty_baggage; | ||
} | ||
|
||
inline context::Context SetBaggage(opentelemetry::context::Context &context, | ||
nostd::shared_ptr<opentelemetry::baggage::Baggage> baggage) | ||
{ | ||
return context.SetValue(kBaggageHeader, baggage); | ||
} | ||
|
||
} // namespace baggage | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters