-
Notifications
You must be signed in to change notification settings - Fork 444
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 resource to Recordable, make room for InstrumentationLibrary #580
Changes from all commits
ea6a0b8
c37058b
f286918
9d9246c
ea996eb
474a0a5
8528f64
34a7bf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,17 @@ void PopulateRequest(const nostd::span<std::unique_ptr<sdk::trace::Recordable>> | |
{ | ||
auto resource_span = request->add_resource_spans(); | ||
auto instrumentation_lib = resource_span->add_instrumentation_library_spans(); | ||
|
||
bool has_resource = false; | ||
for (auto &recordable : spans) | ||
{ | ||
auto rec = std::unique_ptr<Recordable>(static_cast<Recordable *>(recordable.release())); | ||
// We assume all the spans are for the same resource. | ||
if (!has_resource) | ||
{ | ||
// *resource_span->mutable_resource() = std::move(rec->resource()); | ||
*resource_span->mutable_resource() = rec->resource(); | ||
has_resource = true; | ||
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. nit: we can 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. Or we could assert the later found resource equals the first one. 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. We can't. I'm using the loop that adds the spans to add the resource. IF we |
||
} | ||
*instrumentation_lib->add_spans() = std::move(rec->span()); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include "opentelemetry/core/timestamp.h" | ||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/sdk/common/empty_attributes.h" | ||
#include "opentelemetry/sdk/resource/resource.h" | ||
#include "opentelemetry/trace/canonical_code.h" | ||
#include "opentelemetry/trace/span.h" | ||
#include "opentelemetry/trace/span_context.h" | ||
|
@@ -41,6 +42,19 @@ class Recordable | |
opentelemetry::trace::SpanId span_id, | ||
opentelemetry::trace::SpanId parent_span_id) noexcept = 0; | ||
|
||
/** | ||
* Sets the resource associated with a span. | ||
* | ||
* <p> The resource is guaranteed to have a lifetime longer than this recordable. It is | ||
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.
I'm not sure if we can make this statement as is. I'm thinking about a scenario where the user frees the If we go with plain pointers for resources (instead of 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. I'm planning to change TracerProvider to (a) ensure shutdown and (b) require resource cleanup after shutdown. Would you be amenable to that change in correlation with this? I think it's needed to make this safe, and I'm happy to go update the docs. 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. I'm definitely amenable to you making those changes. Some other question: did you for performance reasons decide not to use a managed pointer ( So far we tried to make all ownership explicit to be on the (memory) safe side. |
||
* owned by the `TracerProvider` which (indirectly) owns the `Exporter` that generates a | ||
* `Recordable`. | ||
* | ||
* @param resource the Resource for this span. | ||
* Note: this reference will remain stable for the life of the Recordable. | ||
*/ | ||
virtual void SetResourceRef( | ||
const opentelemetry::sdk::resource::Resource &resource) noexcept = 0; | ||
|
||
/** | ||
* Set an attribute of a span. | ||
* @param name the name of the attribute | ||
|
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.
nit: replace this comment with TODO support for moving?
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.
Actually, theoretically it is moved, I should have removed it before :)