Skip to content

Added a threadsafe recordable#9

Open
kmanghat wants to merge 7 commits into
kmanghat/data-aggregatorfrom
Threadsafe_recordable
Open

Added a threadsafe recordable#9
kmanghat wants to merge 7 commits into
kmanghat/data-aggregatorfrom
Threadsafe_recordable

Conversation

@kmanghat
Copy link
Copy Markdown
Owner

No description provided.

@kmanghat kmanghat requested a review from liadavid July 20, 2020 17:50
@kmanghat kmanghat requested a review from jajanet July 20, 2020 17:56
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/sdk/trace/span_data.h"
#include "opentelemetry/ext/zpages/threadsafe_span_data.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please sort the includes alphabetically.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I got rid of this change, I'll add it in the next PR to switch form span data to threadsafe span data

std::string status_desc_;
std::unordered_map<std::string, SpanDataAttributeValue> attributes_;
AttributeConverter converter_;
mutable std::mutex mutex_;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The mutex should be declared before the variables. Otherwise it will be destructed before the variables it "guards".

start_time_ = start_time;
}

void SetDuration(std::chrono::nanoseconds duration) noexcept override { duration_ = duration; }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing lock?

Copy link
Copy Markdown
Collaborator

@jajanet jajanet left a comment

Choose a reason for hiding this comment

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

General lock stuff discussed from the standup

* @return the trace id for this span
*/
opentelemetry::trace::TraceId GetTraceId() const noexcept {
std::unique_lock<std::mutex> lock(mutex_);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would change all the getter functions to use shared_lock for spicy concurrent reads. Those are thread safe and helps speed up the span for whenever getters are called simultaneously

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If you aren't using shared_lock, I think lock_guard is better than unique_lock for most cases since it's lighter and simpler. Any reason in particular on why you prefer unique?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

shared_lock makes sense only if the mutex is shared, this allows the concurrent behavior that you are talking about. I changed them to lock_guard.

Comment thread ext/include/opentelemetry/ext/zpages/threadsafe_span_data.h
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.

3 participants