-
Notifications
You must be signed in to change notification settings - Fork 423
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 SpanContext (and TraceState) to Recordable #667
Merged
lalitb
merged 3 commits into
open-telemetry:main
from
eyjohn:661/add_trace_state_to_recordable
Apr 13, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -33,7 +33,7 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable | |
opentelemetry::trace::TraceId GetTraceId() const noexcept | ||
{ | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
return trace_id_; | ||
return span_context_.trace_id(); | ||
} | ||
|
||
/** | ||
|
@@ -43,7 +43,17 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable | |
opentelemetry::trace::SpanId GetSpanId() const noexcept | ||
{ | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
return span_id_; | ||
return span_context_.span_id(); | ||
} | ||
|
||
/** | ||
* Get the span context for this span | ||
* @return the span context for this span | ||
*/ | ||
const opentelemetry::trace::SpanContext &GetSpanContext() const noexcept | ||
{ | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
return span_context_; | ||
} | ||
|
||
/** | ||
|
@@ -110,20 +120,18 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable | |
* Get the attributes for this span | ||
* @return the attributes for this span | ||
*/ | ||
const std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue> | ||
GetAttributes() const noexcept | ||
std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue> GetAttributes() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we have to copy for thread safety, the copy doesn't need to be const |
||
const noexcept | ||
{ | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
return attributes_; | ||
} | ||
|
||
void SetIds(opentelemetry::trace::TraceId trace_id, | ||
opentelemetry::trace::SpanId span_id, | ||
opentelemetry::trace::SpanId parent_span_id) noexcept override | ||
void SetIdentity(const opentelemetry::trace::SpanContext &span_context, | ||
opentelemetry::trace::SpanId parent_span_id) noexcept override | ||
{ | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
trace_id_ = trace_id; | ||
span_id_ = span_id; | ||
span_context_ = span_context; | ||
parent_span_id_ = parent_span_id; | ||
} | ||
|
||
|
@@ -195,8 +203,7 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable | |
private: | ||
ThreadsafeSpanData(const ThreadsafeSpanData &threadsafe_span_data, | ||
const std::lock_guard<std::mutex> &) | ||
: trace_id_(threadsafe_span_data.trace_id_), | ||
span_id_(threadsafe_span_data.span_id_), | ||
: span_context_(threadsafe_span_data.span_context_), | ||
parent_span_id_(threadsafe_span_data.parent_span_id_), | ||
start_time_(threadsafe_span_data.start_time_), | ||
duration_(threadsafe_span_data.duration_), | ||
|
@@ -209,8 +216,7 @@ class ThreadsafeSpanData final : public opentelemetry::sdk::trace::Recordable | |
{} | ||
|
||
mutable std::mutex mutex_; | ||
opentelemetry::trace::TraceId trace_id_; | ||
opentelemetry::trace::SpanId span_id_; | ||
opentelemetry::trace::SpanContext span_context_{false, false}; | ||
opentelemetry::trace::SpanId parent_span_id_; | ||
core::SystemTimestamp start_time_; | ||
std::chrono::nanoseconds duration_{0}; | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Initially considered using kv_properties for trace state, during which I hit redeclarations due to this being missing