-
Notifications
You must be signed in to change notification settings - Fork 15
feat: store tracer configuration in an in-memory file #184
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
Changes from all commits
14c8dee
06b7aa4
73b6735
e822ca8
5e66b93
bb89b13
6f71825
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 |
|---|---|---|
|
|
@@ -19,7 +19,9 @@ | |
| #include "extraction_util.h" | ||
| #include "hex.h" | ||
| #include "json.hpp" | ||
| #include "msgpack.h" | ||
| #include "platform_util.h" | ||
| #include "random.h" | ||
| #include "span_data.h" | ||
| #include "span_sampler.h" | ||
| #include "tags.h" | ||
|
|
@@ -85,6 +87,8 @@ Tracer::Tracer(const FinalizedTracerConfig& config, | |
| log << "DATADOG TRACER CONFIGURATION - " << configuration; | ||
| }); | ||
| } | ||
|
|
||
| store_config(); | ||
| } | ||
|
|
||
| std::string Tracer::config() const { | ||
|
|
@@ -110,6 +114,42 @@ std::string Tracer::config() const { | |
| return config.dump(); | ||
| } | ||
|
|
||
| void Tracer::store_config() { | ||
|
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. Can this lead to incorrect usage? If store_config is called twice, will that result in multiple descriptors for this process? If so, what are the implications of that? 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. Every call to this method will result in |
||
| auto maybe_file = | ||
| InMemoryFile::make(std::string("datadog-tracer-info-") + short_uuid()); | ||
| if (auto error = maybe_file.if_error()) { | ||
| if (error->code == Error::Code::NOT_IMPLEMENTED) return; | ||
|
|
||
| logger_->log_error("Failed to open anonymous file"); | ||
| return; | ||
| } | ||
|
|
||
| metadata_file_ = std::make_unique<InMemoryFile>(std::move(*maybe_file)); | ||
|
|
||
| auto defaults = config_manager_->span_defaults(); | ||
|
|
||
| std::string buffer; | ||
| buffer.reserve(1024); | ||
|
|
||
| // clang-format off | ||
| msgpack::pack_map( | ||
| buffer, | ||
| "schema_version", [&](auto& buffer) { msgpack::pack_integer(buffer, std::uint64_t(1)); return Expected<void>{}; }, | ||
| "runtime_id", [&](auto& buffer) { return msgpack::pack_string(buffer, runtime_id_.string()); }, | ||
| "tracer_version", [&](auto& buffer) { return msgpack::pack_string(buffer, signature_.library_version); }, | ||
| "tracer_language", [&](auto& buffer) { return msgpack::pack_string(buffer, signature_.library_language); }, | ||
| "hostname", [&](auto& buffer) { return msgpack::pack_string(buffer, hostname_.value_or("")); }, | ||
| "service_name", [&](auto& buffer) { return msgpack::pack_string(buffer, defaults->service); }, | ||
| "service_env", [&](auto& buffer) { return msgpack::pack_string(buffer, defaults->environment); }, | ||
| "service_version", [&](auto& buffer) { return msgpack::pack_string(buffer, defaults->version); } | ||
| ); | ||
| // clang-format on | ||
|
|
||
| if (!metadata_file_->write_then_seal(buffer)) { | ||
| logger_->log_error("Either failed to write or seal the configuration file"); | ||
| } | ||
| } | ||
|
|
||
| Span Tracer::create_span() { return create_span(SpanConfig{}); } | ||
|
|
||
| Span Tracer::create_span(const SpanConfig& config) { | ||
|
|
||
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.
Question: The RFC suggest to use libdatadog for this. Is this temporary or will the cpp tracer now follow that advice?
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.
It suggest, doesn't enforce. Since
dd-trace-cpphas no dependency onlibdatadog, it will not be that efficient to use it.