Skip to content
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] General cleanup for is_shutdown_ flags in exporters. #2663

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once

#include "nlohmann/json.hpp"
#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/ext/http/client/http_client_factory.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/logs/exporter.h"
Expand Down Expand Up @@ -110,14 +109,13 @@ class ElasticsearchLogRecordExporter final : public opentelemetry::sdk::logs::Lo

private:
// Stores if this exporter had its Shutdown() method called
bool is_shutdown_ = false;
std::atomic<bool> is_shutdown_{false};

// Configuration options for the exporter
ElasticsearchExporterOptions options_;

// Object that stores the HTTP sessions that have been created
std::shared_ptr<ext::http::client::HttpClient> http_client_;
mutable opentelemetry::common::SpinLockMutex lock_;
bool isShutdown() const noexcept;

#ifdef ENABLE_ASYNC_EXPORT
Expand Down
2 changes: 0 additions & 2 deletions exporters/elasticsearch/src/es_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ bool ElasticsearchLogRecordExporter::ForceFlush(

bool ElasticsearchLogRecordExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;

// Shutdown the session manager
Expand All @@ -472,7 +471,6 @@ bool ElasticsearchLogRecordExporter::Shutdown(std::chrono::microseconds /* timeo

bool ElasticsearchLogRecordExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}
} // namespace logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <atomic>
#include <mutex>
#include "opentelemetry/common/spin_lock_mutex.h"

#include "opentelemetry/exporters/memory/in_memory_span_data.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/span_data.h"
#include "opentelemetry/sdk_config.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
Expand Down Expand Up @@ -72,7 +75,6 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte
*/
bool Shutdown(std::chrono::microseconds /* timeout */) noexcept override
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
return true;
}
Expand All @@ -84,13 +86,8 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte

private:
std::shared_ptr<InMemorySpanData> data_;
bool is_shutdown_ = false;
mutable opentelemetry::common::SpinLockMutex lock_;
bool isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}
std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept { return is_shutdown_; }
};
} // namespace memory
} // namespace exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#pragma once

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/sdk/logs/exporter.h"

#include "opentelemetry/version.h"

#include <atomic>
#include <iostream>
#include <sstream>
#include <unordered_map>
Expand Down Expand Up @@ -59,8 +58,7 @@ class OStreamLogRecordExporter final : public opentelemetry::sdk::logs::LogRecor
// The OStream to send the logs to
std::ostream &sout_;
// Whether this exporter has been shut down
bool is_shutdown_ = false;
mutable opentelemetry::common::SpinLockMutex lock_;
std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept;
void printAttributes(
const std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue> &map,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#pragma once

#include <atomic>
#include <iostream>
#include <mutex>
#include <string>

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/sdk/metrics/data/metric_data.h"
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/sdk/metrics/instruments.h"
Expand Down Expand Up @@ -72,8 +73,8 @@ class OStreamMetricExporter final : public opentelemetry::sdk::metrics::PushMetr

private:
std::ostream &sout_;
bool is_shutdown_ = false;
mutable opentelemetry::common::SpinLockMutex lock_;
std::atomic<bool> is_shutdown_{false};
std::mutex serialize_lock_;
marcalff marked this conversation as resolved.
Show resolved Hide resolved
sdk::metrics::AggregationTemporality aggregation_temporality_;
bool isShutdown() const noexcept;
void printInstrumentationInfoMetricData(const sdk::metrics::ScopeMetrics &info_metrics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

#pragma once

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/span_data.h"
#include "opentelemetry/version.h"

#include <atomic>
#include <iostream>
#include <map>
#include <sstream>
Expand Down Expand Up @@ -51,8 +51,7 @@ class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter

private:
std::ostream &sout_;
bool is_shutdown_ = false;
mutable opentelemetry::common::SpinLockMutex lock_;
std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept;

// Mapping status number to the string from api/include/opentelemetry/trace/span_metadata.h
Expand Down
2 changes: 0 additions & 2 deletions exporters/ostream/src/log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,12 @@ bool OStreamLogRecordExporter::ForceFlush(std::chrono::microseconds /* timeout *

bool OStreamLogRecordExporter::Shutdown(std::chrono::microseconds) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
return true;
}

bool OStreamLogRecordExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}

Expand Down
7 changes: 3 additions & 4 deletions exporters/ostream/src/metric_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void OStreamMetricExporter::printInstrumentationInfoMetricData(
const sdk::metrics::ResourceMetrics &data)
{
// sout_ is shared
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
const std::lock_guard<std::mutex> serialize(serialize_lock_);
sout_ << "{";
sout_ << "\n scope name\t: " << info_metric.scope_->GetName()
<< "\n schema url\t: " << info_metric.scope_->GetSchemaURL()
Expand Down Expand Up @@ -246,20 +246,19 @@ void OStreamMetricExporter::printPointAttributes(

bool OStreamMetricExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
const std::lock_guard<std::mutex> serialize(serialize_lock_);
sout_.flush();
return true;
}

bool OStreamMetricExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
return true;
}

bool OStreamMetricExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}

Expand Down
3 changes: 1 addition & 2 deletions exporters/ostream/src/span_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,15 @@ bool OStreamSpanExporter::ForceFlush(std::chrono::microseconds /* timeout */) no

bool OStreamSpanExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
return true;
}

bool OStreamSpanExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}

void OStreamSpanExporter::printAttributes(
const std::unordered_map<std::string, sdkcommon::OwnedAttributeValue> &map,
const std::string prefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#pragma once

#include <atomic>
#include <chrono>

#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h"

#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
Expand Down Expand Up @@ -92,8 +92,7 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter
* @param stub the service stub to be used for exporting
*/
OtlpGrpcExporter(std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> stub);
bool is_shutdown_ = false;
mutable opentelemetry::common::SpinLockMutex lock_;
std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept;
};
} // namespace otlp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"
#include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h"
#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"

// clang-format on
Expand All @@ -16,6 +15,8 @@
#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_options.h"
#include "opentelemetry/sdk/logs/exporter.h"

#include <atomic>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
Expand Down Expand Up @@ -92,8 +93,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo
*/
OtlpGrpcLogRecordExporter(
std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub);
bool is_shutdown_ = false;
mutable opentelemetry::common::SpinLockMutex lock_;
std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"
#include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h"
#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"

// clang-format on
Expand All @@ -16,6 +15,8 @@
#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"

#include <atomic>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
Expand Down Expand Up @@ -82,8 +83,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp
*/
OtlpGrpcMetricExporter(
std::unique_ptr<proto::collector::metrics::v1::MetricsService::StubInterface> stub);
bool is_shutdown_ = false;
mutable opentelemetry::common::SpinLockMutex lock_;
std::atomic<bool> is_shutdown_{false};
bool isShutdown() const noexcept;
};
} // namespace otlp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#pragma once

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/nostd/variant.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
Expand Down
2 changes: 0 additions & 2 deletions exporters/otlp/src/otlp_grpc_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ bool OtlpGrpcExporter::ForceFlush(
bool OtlpGrpcExporter::Shutdown(
OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
#ifdef ENABLE_ASYNC_EXPORT
return client_->Shutdown(timeout);
Expand All @@ -146,7 +145,6 @@ bool OtlpGrpcExporter::Shutdown(

bool OtlpGrpcExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}

Expand Down
2 changes: 0 additions & 2 deletions exporters/otlp/src/otlp_grpc_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogRecordExporter::Export(
bool OtlpGrpcLogRecordExporter::Shutdown(
OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
#ifdef ENABLE_ASYNC_EXPORT
return client_->Shutdown(timeout);
Expand All @@ -159,7 +158,6 @@ bool OtlpGrpcLogRecordExporter::ForceFlush(

bool OtlpGrpcLogRecordExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}

Expand Down
2 changes: 0 additions & 2 deletions exporters/otlp/src/otlp_grpc_metric_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ bool OtlpGrpcMetricExporter::ForceFlush(
bool OtlpGrpcMetricExporter::Shutdown(
OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
is_shutdown_ = true;
#ifdef ENABLE_ASYNC_EXPORT
return client_->Shutdown(timeout);
Expand All @@ -152,7 +151,6 @@ bool OtlpGrpcMetricExporter::Shutdown(

bool OtlpGrpcMetricExporter::isShutdown() const noexcept
{
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
return is_shutdown_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <vector>

#include <prometheus/exposer.h>
#include "opentelemetry/common/spin_lock_mutex.h"

#include "opentelemetry/exporters/prometheus/collector.h"
#include "opentelemetry/exporters/prometheus/exporter_options.h"
#include "opentelemetry/nostd/span.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#pragma once

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/exporters/zipkin/zipkin_exporter_options.h"
#include "opentelemetry/ext/http/client/http_client_factory.h"
#include "opentelemetry/ext/http/common/url_parser.h"
Expand All @@ -13,6 +12,8 @@

#include "nlohmann/json.hpp"

#include <atomic>

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
Expand Down Expand Up @@ -69,7 +70,7 @@ class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter

private:
// The configuration options associated with this exporter.
bool is_shutdown_ = false;
std::atomic<bool> is_shutdown_{false};
ZipkinExporterOptions options_;
std::shared_ptr<opentelemetry::ext::http::client::HttpClientSync> http_client_;
opentelemetry::ext::http::common::UrlParser url_parser_;
Expand All @@ -84,7 +85,6 @@ class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter
*/
ZipkinExporter(std::shared_ptr<opentelemetry::ext::http::client::HttpClientSync> http_client);

mutable opentelemetry::common::SpinLockMutex lock_;
bool isShutdown() const noexcept;
};
} // namespace zipkin
Expand Down
Loading