Skip to content

Commit 3e4a517

Browse files
committed
fixup! [EXPORTERS]: elastic search set timestamp within @timestamp instead of timestamp
1 parent 67d7e6b commit 3e4a517

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

exporters/elasticsearch/src/es_log_recordable.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,25 +210,25 @@ nlohmann::json ElasticSearchRecordable::GetJSON() noexcept
210210
void ElasticSearchRecordable::SetTimestamp(
211211
opentelemetry::common::SystemTimestamp timestamp) noexcept
212212
{
213+
const std::chrono::system_clock::time_point timePoint{timestamp};
214+
213215
// If built with with at least cpp 20 then use std::format
214216
// Otherwise use the old style to format the timestamp in UTC
215217
#if __cplusplus >= 202002L
216-
const std::chrono::system_clock::time_point timePoint{timestamp};
217218
const std::string dateStr = std::format("{:%FT%T%Ez}", timePoint);
218219
#else
219220
const static int dateToSecondsSize = 19;
220221
const static int millisecondsSize = 8;
221222
const static int timeZoneSize = 1;
222223
const static int dateSize = dateToSecondsSize + millisecondsSize + timeZoneSize;
223224

224-
std::chrono::system_clock::time_point timestamp = std::chrono::system_clock::now();
225-
std::time_t time = std::chrono::system_clock::to_time_t(timestamp);
225+
std::time_t time = std::chrono::system_clock::to_time_t(timePoint);
226226
std::tm tm = *std::gmtime(&time);
227227

228228
char bufferDate[dateSize]; // example: 2024-10-18T07:26:00.123456Z
229229
std::strftime(bufferDate, sizeof(bufferDate), "%Y-%m-%dT%H:%M:%S", &tm);
230230
auto microseconds =
231-
std::chrono::duration_cast<std::chrono::microseconds>(timestamp.time_since_epoch()) %
231+
std::chrono::duration_cast<std::chrono::microseconds>(timePoint.time_since_epoch()) %
232232
std::chrono::seconds(1);
233233

234234
char bufferMilliseconds[millisecondsSize];

0 commit comments

Comments
 (0)