-
Notifications
You must be signed in to change notification settings - Fork 440
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
Logger: Propagating resources through LoggerProvider #1154
Logger: Propagating resources through LoggerProvider #1154
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1154 +/- ##
=======================================
Coverage 93.29% 93.29%
=======================================
Files 174 174
Lines 6402 6402
=======================================
Hits 5972 5972
Misses 430 430
|
Where do you see its usage? We can possibly create a converter similar to AttributeValue to OwnedAttributeValue -
|
I have wrote a example to share resource between logs before.And the codes is like these: class KeyValueIterableViewForResourceAttributes final : public opentelemetry::common::KeyValueIterable {
public:
explicit KeyValueIterableViewForResourceAttributes(
const opentelemetry::sdk::resource::ResourceAttributes& container) noexcept
: container_{&container} {}
// KeyValueIterable
bool ForEachKeyValue(
opentelemetry::nostd::function_ref<bool(nostd::string_view, opentelemetry::common::AttributeValue)> callback)
const noexcept override {
auto iter = std::begin(*container_);
auto last = std::end(*container_);
for (; iter != last; ++iter) {
if (!callback(iter->first, ConvertOwnedAttribute(iter->second))) {
return false;
}
}
return true;
}
size_t size() const noexcept override { return nostd::size(*container_); }
static opentelemetry::common::AttributeValue ConvertOwnedAttribute(
const opentelemetry::sdk::common::OwnedAttributeValue& value) {
if (nostd::holds_alternative<bool>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<bool>(value)};
} else if (nostd::holds_alternative<int32_t>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<int32_t>(value)};
} else if (nostd::holds_alternative<int64_t>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<int64_t>(value)};
} else if (nostd::holds_alternative<uint32_t>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<uint32_t>(value)};
} else if (nostd::holds_alternative<uint64_t>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<uint64_t>(value)};
} else if (nostd::holds_alternative<double>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<double>(value)};
} else if (nostd::holds_alternative<std::string>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<std::string>(value)};
} else if (nostd::holds_alternative<std::vector<bool>>(value)) {
// TODO: Add support for vector<bool>
return opentelemetry::common::AttributeValue{};
} else if (nostd::holds_alternative<std::vector<int32_t>>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<std::vector<int32_t>>(value)};
} else if (nostd::holds_alternative<std::vector<uint32_t>>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<std::vector<uint32_t>>(value)};
} else if (nostd::holds_alternative<std::vector<int64_t>>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<std::vector<int64_t>>(value)};
} else if (nostd::holds_alternative<std::vector<uint64_t>>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<std::vector<uint64_t>>(value)};
} else if (nostd::holds_alternative<std::vector<double>>(value)) {
return opentelemetry::common::AttributeValue{nostd::get<std::vector<double>>(value)};
} else if (nostd::holds_alternative<std::vector<std::string>>(value)) {
// TODO: Add support to convert vector<std::string> tp vector<nostd::string_view>
return opentelemetry::common::AttributeValue{};
}
return opentelemetry::common::AttributeValue{};
}
private:
const opentelemetry::sdk::resource::ResourceAttributes* container_;
};
void Report(const opentelemetry::sdk::resource::Resource& shared_resource) {
auto span = GetTracer()->StartSpan("cpp-test-span-otlp");
auto ctx = span->GetContext();
auto logger = GetLogger();
auto shared_resource_attributes = KeyValueIterableViewForResourceAttributes(shared_resource.GetAttributes());
using attribute_span = nostd::span<const std::pair<nostd::string_view, opentelemetry::common::AttributeValue>>;
logger->Log(opentelemetry::logs::Severity::kInfo, "log name", "log body", shared_resource_attributes,
opentelemetry::common::KeyValueIterableView<attribute_span>{attribute_span{}}, ctx.trace_id(),
ctx.span_id(), ctx.trace_flags(), std::chrono::system_clock::now());
} It can not convert all types from |
Thanks for the explanation with a nicely written example. As you correctly mentioned, the scenario for resource is no more relevant once we start sharing resources through the provider. And passing resource as argument through Logger::log() should be removed. This is a breaking change, but acceptable as Logs Signal is still in preview. For log attributes, it would be better to pass them as KeyValueIterableView. Let me know if I am missing something here. |
Yes, this is what I mean, and my question is how to create |
I am still thinking why should this be under the scope of otel-cpp. Isn't this the responsibility of the library developer to ensure to call
Which conversion is a problem in your above example - |
|
yes agree, I see a problem with conversion for both |
9387847
to
de2ebed
Compare
@lalitb This PR is almost finished. Could you please review the changes some time later? |
19b3c7f
to
cfbb5f4
Compare
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.
thanks for the PR. Changes are nicely done. have added initial comments. It's a large PR, will have another scan on the multi-processor, multi-recordable part.
void Log(Severity severity, | ||
nostd::string_view name, | ||
nostd::string_view body, | ||
OPENTELEMETRY_MAYBE_UNUSED const common::KeyValueIterable &resource, |
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 don't have a strong opinion here, but Logger implementation is in preview and should be fine to have breaking changes without explicit deprecating first, and have cleaner code. Also for tracing implementation, specs are already stable, which means there won't be any further breaking changes required for it. Just thinking about whether we need to really add deprecated
support.
Whatever we decide need to also be done for the instrumentation library cc @esigo
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 it's helpful for users to have some time to upgrade the usage of Log API instead of just compile error
.
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.
With logs in experimental, I think breaking changes should be acceptable and users should be prepared for it. This will keep the API much cleaner. We should definitely mention this as a breaking change in the Release description.
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.
OK, I can remove these later, should I keep api/include/opentelemetry/common/macros.h
? Maybe it's useful in the future?
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.
We can remove macros for now, can add them back later if required. Thanks.
urls = [ | ||
"https://github.com/google/benchmark/archive/v1.5.2.tar.gz", | ||
"https://github.com/google/benchmark/archive/v1.6.0.tar.gz", |
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 - we also need to update the benchmark submodule used by cmake, and version in the ./third_party_release file ( we can raise an issue, and do it in separate PR).
exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_recordable.h
Show resolved
Hide resolved
std::stringstream sout; | ||
sout << "Invalid severity(" << severity_index << ")"; | ||
json_["severity"] = sout.str(); | ||
} |
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.
Thanks for fixing this.
32bbbf1
to
ce61fda
Compare
start_time = std::chrono::system_clock::now(); | ||
if (expire_time > start_time) | ||
{ | ||
timeout_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(expire_time - start_time); |
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 are we trying to achieve here - to ensure that the total time taken by all the processors shouldn't exceed timeout
? For traces, logic is a bit different, as the same timeout
is used for all processors. This looks good too to me.
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.
Yes, I think it may confuse ther users if they set timeout to some value, but actually take a more longer time.
E.g. when closing a service process, we may force to flush data, wait a limited time and then force to exit no matter it's done or not.
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.
Yes agree.
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.
LGTM once we remove the deprecated functionality.
Done. I keep the |
Thanks. Probably all unused functionality can be removed separately some other time. Changes look good now. Thanks for working on this. |
# define OPENTELEMETRY_MAYBE_UNUSED __attribute__((unused)) | ||
#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) | ||
# define OPENTELEMETRY_MAYBE_UNUSED __attribute__((unused)) | ||
#elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher |
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.
Why check vs2012 here? Seems the only valid case here is _MSVC_LANG >= 201703L
. Also if this is true, should this be covered by the first check of __cplusplus >= 201703L
?
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.
Yes, it's duplicated, I have removed it.Thanks.
@ThomsonTan - Is it good to merge? |
Signed-off-by: owentou <owentou@tencent.com>
Signed-off-by: owentou <owentou@tencent.com>
Signed-off-by: owentou <owentou@tencent.com>
Signed-off-by: owentou <owentou@tencent.com>
+ Fix multi log processor + Fix crash problem when log with invalid severity Signed-off-by: owentou <owentou@tencent.com>
Signed-off-by: owentou <owentou@tencent.com>
Signed-off-by: owentou <owentou@tencent.com>
Signed-off-by: owentou <owentou@tencent.com>
Signed-off-by: owentou <owentou@tencent.com>
Signed-off-by: owentou <owentou@tencent.com>
6d72128
to
c53bfd1
Compare
Rebase on main again |
Signed-off-by: owentou owentou@tencent.com
Fixes #1086
Changes
logs::LoggerContext
,logs::MultiLogProcessor
,logs::MultiRecordable
Logger::Log
TracerProvider::GetProcessor
(Without implementation before.)sdk::logs::Recordable::SetResource
LoggerProvider::SetProcessor
toLoggerProvider::AddProcessor
LoggerContext
between loggersapi/include/opentelemetry/common/macros.h
to provideOPENTELEMETRY_DEPRECATED
,OPENTELEMETRY_DEPRECATED_MESSAGE
andOPENTELEMETRY_MAYBE_UNUSED
Is there any way to convert
opentelemetry::sdk::common::OwnedAttributeValue
intoopentelemetry::common::AttributeValue
?It's difficult to reuse and dump data from
opentelemetry::sdk::common::OwnedAttributeValue
.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes