-
Notifications
You must be signed in to change notification settings - Fork 427
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
[EXPORTER] Refactor ElasticSearchRecordable
#3164
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
{ | ||
static void to_json(json &j, const opentelemetry::sdk::common::OwnedAttributeValue &v) | ||
{ | ||
opentelemetry::nostd::visit([&j](const auto &value) { j = value; }, v); |
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.
A possible breaking change here is that the original WriteValue()
did not handle spans. If this is important, I can add an if
condition to follow the old behavior.
char trace_buf[32]; | ||
char trace_buf[opentelemetry::trace::TraceId::kSize * 2]; |
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.
This approach is safer: should kSize
change someday, the buffer's size will be automatically updated.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3164 +/- ##
=======================================
Coverage 87.86% 87.86%
=======================================
Files 195 195
Lines 6151 6151
=======================================
Hits 5404 5404
Misses 747 747
|
29b912b
to
737c785
Compare
|
||
std::strcat(bufferDate, bufferMilliseconds); | ||
std::strcat(bufferDate, "Z"); | ||
std::ostringstream oss; |
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 change it to put_time
and ostringstream
? In my understandarding, using strftime
and snprintf
with just one static buffer block will have better performence than using ostringstream
and put_time
with dynamic memory allocation. And there are also some compatiblity problems with put_time
and old compiler's STL.
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.
A newer version of gcc complained:
warning: ‘__builtin___snprintf_chk’ output may be truncated before the last format character [-Wformat-truncation=]
47 | std::snprintf(bufferMilliseconds, sizeof(bufferMilliseconds), ".%06ld",
| ^
In function ‘int snprintf(char*, size_t, const char*, ...)’,
/usr/include/x86_64-linux-gnu/bits/stdio2.h:54:35: note: ‘__builtin___snprintf_chk’ output between 8 and 9 bytes into a destination of size 8
54 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
so I tried to come up with something safe that does not involve hardcoded sizes, compiles cleanly, does not have a potential for buffer overflows, and is as fast as std::format("{:%FT%T%Ez}", timePoint)
.
For example, in
const static int dateToSecondsSize = 19;
const static int millisecondsSize = 8;
it was not immediately evident that millisecondsSize
reserves one byte for the null terminator (.123456
is seven bytes, not eight), and it felt like dateSize = dateToSecondsSize + millisecondsSize + timeZoneSize; char bufferDate[dateSize];
could lead to a buffer overflow.
Anyway, I think I have found a faster solution not involving strcat
and hardcoded buffer sizes.
7a27ac3
to
9d4cc32
Compare
9d4cc32
to
b72c41b
Compare
Changes
ElasticSearchRecordable::WriteValue()
by using the ADL Serializer;ElasticSearchRecordable::SetTimestamp()
;ElasticSearchRecordable::SetTraceId()
andElasticSearchRecordable::SetSpanId()
by using constants for array sizes instead of hardcoded values.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes