-
Notifications
You must be signed in to change notification settings - Fork 410
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
Context api dummy methods #155
Closed
Closed
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4128a69
added context header with dummy methods
satac2 cba6d5f
Build and CMake files
satac2 b2e876e
auto formatted
satac2 a7480c8
changed variable name from attributes to values
satac2 96cd32f
Update api/include/opentelemetry/context/context.h
satac2 5f0634b
changed to follow the spec and added context_value type
satac2 5d77daf
Merge branch 'context_api_dummy_methods' of github.com:satac2/opentel…
satac2 68a1a70
removed tests for this PR
satac2 5e68574
removed line
satac2 16a492e
removed unnecessary include
satac2 497eb67
changed a function to pass by reference
satac2 479dead
formatted
satac2 2a78c48
Added tests.
satac2 f51748f
avoiding ABI compatibility issues
satac2 7d73219
Merge branch 'master' into context_api_dummy_methods
maxgolov 3f85aa5
added throw capture
satac2 0ec83e8
Merge branch 'context_api_dummy_methods' of github.com:satac2/opentel…
satac2 21ea872
minor exception syntax error
satac2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
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,72 @@ | ||
#pragma once | ||
|
||
#include "opentelemetry/common/attribute_value.h" | ||
#include "opentelemetry/context/context_value.h" | ||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/trace/key_value_iterable_view.h" | ||
|
||
#include <map> | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace context | ||
{ | ||
|
||
// The context class provides a context identifier. | ||
// This is a dummy class that is meant to be overridden, | ||
// the methods return default values. | ||
class Context | ||
{ | ||
|
||
public: | ||
Context() = default; | ||
|
||
// Contructor, creates a context object from a map of keys | ||
// and identifiers. | ||
template <class T, nostd::enable_if_t<trace::detail::is_key_value_iterable<T>::value> * = nullptr> | ||
Context(const T &keys_and_values) | ||
{ | ||
trace::KeyValueIterableView<T> iterable{keys_and_values}; | ||
iterable.ForEachKeyValue([&](nostd::string_view key, context::ContextValue value) noexcept { | ||
context_map_[std::string(key)] = value; | ||
return true; | ||
}); | ||
} | ||
|
||
// Accepts a key and a value and then returns a new context that | ||
// contains both the original pairs and the new pair. | ||
template <class T> | ||
Context SetValue(nostd::string_view key, T &value) noexcept | ||
{ | ||
std::map<std::string, context::ContextValue> context_map_copy = context_map_; | ||
context_map_copy[std::string(key)] = value; | ||
return Context(context_map_copy); | ||
} | ||
|
||
// Accepts a new iterable and then returns a new context that | ||
// contains both the original pairs and the new pair. | ||
template <class T, nostd::enable_if_t<trace::detail::is_key_value_iterable<T>::value> * = nullptr> | ||
Context SetValues(T &keys_and_values) noexcept | ||
{ | ||
std::map<std::string, context::ContextValue> context_map_copy = context_map_; | ||
trace::KeyValueIterableView<T> iterable{keys_and_values}; | ||
|
||
iterable.ForEachKeyValue([&](nostd::string_view key, context::ContextValue value) noexcept { | ||
context_map_copy[std::string(key)] = value; | ||
return true; | ||
}); | ||
|
||
return Context(context_map_copy); | ||
} | ||
|
||
// Returns the value associated with the passed in key. | ||
context::ContextValue GetValue(nostd::string_view key) { return context_map_[std::string(key)]; } | ||
|
||
// Copy Constructors. | ||
Context(const Context &other) = default; | ||
Context &operator=(const Context &other) = default; | ||
|
||
private: | ||
std::map<std::string, context::ContextValue> context_map_; | ||
}; | ||
} // namespace context | ||
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
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.
What would happen if a library (compilation unit A) is making a call to this method, while the context object was constructed by another binary (compilation unit B), while A and B are using different version of STL?
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 solved the issue by putting the map into a KeyValueIterableView, and then copying the data over.