Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions exporters/otlp/src/otlp_file_client.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <nlohmann/json.hpp>

#include <limits.h>
#include <atomic>
#include <chrono>
Expand All @@ -12,7 +14,6 @@
#include <fstream>
#include <functional>
#include <mutex>
#include <nlohmann/json.hpp>
#include <ratio>
#include <string>
#include <thread>
Expand Down Expand Up @@ -1028,21 +1029,21 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender

MaybeRotateLog(data.size());

std::shared_ptr<FILE> out = OpenLogFile(true);
std::shared_ptr<std::FILE> out = OpenLogFile(true);
if (!out)
{
return;
}

fwrite(data.data(), 1, data.size(), out.get());
std::fwrite(data.data(), 1, data.size(), out.get());

{
std::lock_guard<std::mutex> lock_guard{file_->file_lock};

file_->record_count += record_count;

// Pipe file size always returns 0, we ignore the size limit of it.
auto written_size = ftell(out.get());
auto written_size = std::ftell(out.get());
if (written_size >= 0)
{
file_->written_size = static_cast<std::size_t>(written_size);
Expand All @@ -1054,7 +1055,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
{
file_->left_flush_record_count = options_.flush_count;

fflush(out.get());
std::fflush(out.get());

file_->flushed_record_count.store(file_->record_count.load(std::memory_order_acquire),
std::memory_order_release);
Expand Down Expand Up @@ -1216,7 +1217,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
OpenLogFile(false);
}

std::shared_ptr<FILE> OpenLogFile(bool destroy_content)
std::shared_ptr<std::FILE> OpenLogFile(bool destroy_content)
{
std::lock_guard<std::mutex> lock_guard{file_->file_lock};

Expand All @@ -1238,8 +1239,6 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
}
file_path[file_path_size] = 0;

std::shared_ptr<FILE> of = std::make_shared<FILE>();

std::string directory_name = FileSystemUtil::DirName(file_path);
if (!directory_name.empty())
{
Expand Down Expand Up @@ -1294,10 +1293,10 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
<< " failed with pattern: " << options_.file_pattern << hint);
return nullptr;
}
of = std::shared_ptr<std::FILE>(new_file, fclose);
std::shared_ptr<std::FILE> of = std::shared_ptr<std::FILE>(new_file, fclose);

fseek(of.get(), 0, SEEK_END);
file_->written_size = static_cast<size_t>(ftell(of.get()));
std::fseek(of.get(), 0, SEEK_END);
file_->written_size = static_cast<size_t>(std::ftell(of.get()));

file_->current_file = of;
file_->last_checkpoint = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
Expand Down Expand Up @@ -1513,7 +1512,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender

if (concurrency_file->current_file)
{
fflush(concurrency_file->current_file.get());
std::fflush(concurrency_file->current_file.get());
}

concurrency_file->flushed_record_count.store(current_record_count,
Expand Down Expand Up @@ -1568,7 +1567,7 @@ class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
std::size_t rotate_index;
std::size_t written_size;
std::size_t left_flush_record_count;
std::shared_ptr<FILE> current_file;
std::shared_ptr<std::FILE> current_file;
std::mutex file_lock;
std::time_t last_checkpoint;
std::string file_path;
Expand Down
Loading