Skip to content

Commit ce14bf6

Browse files
authored
[EXPORTER] General cleanup for is_shutdown_ flags in exporters. (open-telemetry#2663)
1 parent 6de4ccd commit ce14bf6

File tree

19 files changed

+31
-54
lines changed

19 files changed

+31
-54
lines changed

exporters/elasticsearch/include/opentelemetry/exporters/elasticsearch/es_log_record_exporter.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#pragma once
55

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

111110
private:
112111
// Stores if this exporter had its Shutdown() method called
113-
bool is_shutdown_ = false;
112+
std::atomic<bool> is_shutdown_{false};
114113

115114
// Configuration options for the exporter
116115
ElasticsearchExporterOptions options_;
117116

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

123121
#ifdef ENABLE_ASYNC_EXPORT

exporters/elasticsearch/src/es_log_record_exporter.cc

-2
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ bool ElasticsearchLogRecordExporter::ForceFlush(
460460

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

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

473472
bool ElasticsearchLogRecordExporter::isShutdown() const noexcept
474473
{
475-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
476474
return is_shutdown_;
477475
}
478476
} // namespace logs

exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
#pragma once
5+
6+
#include <atomic>
57
#include <mutex>
6-
#include "opentelemetry/common/spin_lock_mutex.h"
8+
79
#include "opentelemetry/exporters/memory/in_memory_span_data.h"
810
#include "opentelemetry/sdk/trace/exporter.h"
911
#include "opentelemetry/sdk/trace/span_data.h"
1012
#include "opentelemetry/sdk_config.h"
13+
#include "opentelemetry/version.h"
1114

1215
OPENTELEMETRY_BEGIN_NAMESPACE
1316
namespace exporter
@@ -72,7 +75,6 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte
7275
*/
7376
bool Shutdown(std::chrono::microseconds /* timeout */) noexcept override
7477
{
75-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
7678
is_shutdown_ = true;
7779
return true;
7880
}
@@ -84,13 +86,8 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte
8486

8587
private:
8688
std::shared_ptr<InMemorySpanData> data_;
87-
bool is_shutdown_ = false;
88-
mutable opentelemetry::common::SpinLockMutex lock_;
89-
bool isShutdown() const noexcept
90-
{
91-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
92-
return is_shutdown_;
93-
}
89+
std::atomic<bool> is_shutdown_{false};
90+
bool isShutdown() const noexcept { return is_shutdown_; }
9491
};
9592
} // namespace memory
9693
} // namespace exporter

exporters/ostream/include/opentelemetry/exporters/ostream/log_record_exporter.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#pragma once
55

66
#include "opentelemetry/common/attribute_value.h"
7-
#include "opentelemetry/common/spin_lock_mutex.h"
87
#include "opentelemetry/nostd/span.h"
98
#include "opentelemetry/sdk/common/attribute_utils.h"
109
#include "opentelemetry/sdk/logs/exporter.h"
11-
1210
#include "opentelemetry/version.h"
1311

12+
#include <atomic>
1413
#include <iostream>
1514
#include <sstream>
1615
#include <unordered_map>
@@ -59,8 +58,7 @@ class OStreamLogRecordExporter final : public opentelemetry::sdk::logs::LogRecor
5958
// The OStream to send the logs to
6059
std::ostream &sout_;
6160
// Whether this exporter has been shut down
62-
bool is_shutdown_ = false;
63-
mutable opentelemetry::common::SpinLockMutex lock_;
61+
std::atomic<bool> is_shutdown_{false};
6462
bool isShutdown() const noexcept;
6563
void printAttributes(
6664
const std::unordered_map<std::string, opentelemetry::sdk::common::OwnedAttributeValue> &map,

exporters/ostream/include/opentelemetry/exporters/ostream/metric_exporter.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
#pragma once
55

6+
#include <atomic>
67
#include <iostream>
8+
#include <mutex>
79
#include <string>
810

9-
#include "opentelemetry/common/spin_lock_mutex.h"
1011
#include "opentelemetry/sdk/metrics/data/metric_data.h"
1112
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
1213
#include "opentelemetry/sdk/metrics/instruments.h"
@@ -72,8 +73,8 @@ class OStreamMetricExporter final : public opentelemetry::sdk::metrics::PushMetr
7273

7374
private:
7475
std::ostream &sout_;
75-
bool is_shutdown_ = false;
76-
mutable opentelemetry::common::SpinLockMutex lock_;
76+
std::atomic<bool> is_shutdown_{false};
77+
std::mutex serialize_lock_;
7778
sdk::metrics::AggregationTemporality aggregation_temporality_;
7879
bool isShutdown() const noexcept;
7980
void printInstrumentationInfoMetricData(const sdk::metrics::ScopeMetrics &info_metrics,

exporters/ostream/include/opentelemetry/exporters/ostream/span_exporter.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
#pragma once
55

6-
#include "opentelemetry/common/spin_lock_mutex.h"
76
#include "opentelemetry/nostd/span.h"
87
#include "opentelemetry/sdk/trace/exporter.h"
98
#include "opentelemetry/sdk/trace/span_data.h"
109
#include "opentelemetry/version.h"
1110

11+
#include <atomic>
1212
#include <iostream>
1313
#include <map>
1414
#include <sstream>
@@ -51,8 +51,7 @@ class OStreamSpanExporter final : public opentelemetry::sdk::trace::SpanExporter
5151

5252
private:
5353
std::ostream &sout_;
54-
bool is_shutdown_ = false;
55-
mutable opentelemetry::common::SpinLockMutex lock_;
54+
std::atomic<bool> is_shutdown_{false};
5655
bool isShutdown() const noexcept;
5756

5857
// Mapping status number to the string from api/include/opentelemetry/trace/span_metadata.h

exporters/ostream/src/log_record_exporter.cc

-2
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,12 @@ bool OStreamLogRecordExporter::ForceFlush(std::chrono::microseconds /* timeout *
126126

127127
bool OStreamLogRecordExporter::Shutdown(std::chrono::microseconds) noexcept
128128
{
129-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
130129
is_shutdown_ = true;
131130
return true;
132131
}
133132

134133
bool OStreamLogRecordExporter::isShutdown() const noexcept
135134
{
136-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
137135
return is_shutdown_;
138136
}
139137

exporters/ostream/src/metric_exporter.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void OStreamMetricExporter::printInstrumentationInfoMetricData(
129129
const sdk::metrics::ResourceMetrics &data)
130130
{
131131
// sout_ is shared
132-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
132+
const std::lock_guard<std::mutex> serialize(serialize_lock_);
133133
sout_ << "{";
134134
sout_ << "\n scope name\t: " << info_metric.scope_->GetName()
135135
<< "\n schema url\t: " << info_metric.scope_->GetSchemaURL()
@@ -246,20 +246,19 @@ void OStreamMetricExporter::printPointAttributes(
246246

247247
bool OStreamMetricExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept
248248
{
249-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
249+
const std::lock_guard<std::mutex> serialize(serialize_lock_);
250+
sout_.flush();
250251
return true;
251252
}
252253

253254
bool OStreamMetricExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept
254255
{
255-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
256256
is_shutdown_ = true;
257257
return true;
258258
}
259259

260260
bool OStreamMetricExporter::isShutdown() const noexcept
261261
{
262-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
263262
return is_shutdown_;
264263
}
265264

exporters/ostream/src/span_exporter.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,15 @@ bool OStreamSpanExporter::ForceFlush(std::chrono::microseconds /* timeout */) no
106106

107107
bool OStreamSpanExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept
108108
{
109-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
110109
is_shutdown_ = true;
111110
return true;
112111
}
113112

114113
bool OStreamSpanExporter::isShutdown() const noexcept
115114
{
116-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
117115
return is_shutdown_;
118116
}
117+
119118
void OStreamSpanExporter::printAttributes(
120119
const std::unordered_map<std::string, sdkcommon::OwnedAttributeValue> &map,
121120
const std::string prefix)

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_exporter.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
#pragma once
55

6+
#include <atomic>
67
#include <chrono>
78

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

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

1313
#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
@@ -92,8 +92,7 @@ class OtlpGrpcExporter final : public opentelemetry::sdk::trace::SpanExporter
9292
* @param stub the service stub to be used for exporting
9393
*/
9494
OtlpGrpcExporter(std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> stub);
95-
bool is_shutdown_ = false;
96-
mutable opentelemetry::common::SpinLockMutex lock_;
95+
std::atomic<bool> is_shutdown_{false};
9796
bool isShutdown() const noexcept;
9897
};
9998
} // namespace otlp

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"
99
#include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h"
10-
#include "opentelemetry/common/spin_lock_mutex.h"
1110
#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
1211

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

18+
#include <atomic>
19+
1920
OPENTELEMETRY_BEGIN_NAMESPACE
2021
namespace exporter
2122
{
@@ -92,8 +93,7 @@ class OtlpGrpcLogRecordExporter : public opentelemetry::sdk::logs::LogRecordExpo
9293
*/
9394
OtlpGrpcLogRecordExporter(
9495
std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub);
95-
bool is_shutdown_ = false;
96-
mutable opentelemetry::common::SpinLockMutex lock_;
96+
std::atomic<bool> is_shutdown_{false};
9797
bool isShutdown() const noexcept;
9898
};
9999

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"
99
#include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h"
10-
#include "opentelemetry/common/spin_lock_mutex.h"
1110
#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
1211

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

18+
#include <atomic>
19+
1920
OPENTELEMETRY_BEGIN_NAMESPACE
2021
namespace exporter
2122
{
@@ -82,8 +83,7 @@ class OtlpGrpcMetricExporter : public opentelemetry::sdk::metrics::PushMetricExp
8283
*/
8384
OtlpGrpcMetricExporter(
8485
std::unique_ptr<proto::collector::metrics::v1::MetricsService::StubInterface> stub);
85-
bool is_shutdown_ = false;
86-
mutable opentelemetry::common::SpinLockMutex lock_;
86+
std::atomic<bool> is_shutdown_{false};
8787
bool isShutdown() const noexcept;
8888
};
8989
} // namespace otlp

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#pragma once
55

6-
#include "opentelemetry/common/spin_lock_mutex.h"
76
#include "opentelemetry/ext/http/client/http_client.h"
87
#include "opentelemetry/nostd/variant.h"
98
#include "opentelemetry/sdk/common/exporter_utils.h"

exporters/otlp/src/otlp_grpc_exporter.cc

-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ bool OtlpGrpcExporter::ForceFlush(
135135
bool OtlpGrpcExporter::Shutdown(
136136
OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept
137137
{
138-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
139138
is_shutdown_ = true;
140139
#ifdef ENABLE_ASYNC_EXPORT
141140
return client_->Shutdown(timeout);
@@ -146,7 +145,6 @@ bool OtlpGrpcExporter::Shutdown(
146145

147146
bool OtlpGrpcExporter::isShutdown() const noexcept
148147
{
149-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
150148
return is_shutdown_;
151149
}
152150

exporters/otlp/src/otlp_grpc_log_record_exporter.cc

-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogRecordExporter::Export(
138138
bool OtlpGrpcLogRecordExporter::Shutdown(
139139
OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept
140140
{
141-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
142141
is_shutdown_ = true;
143142
#ifdef ENABLE_ASYNC_EXPORT
144143
return client_->Shutdown(timeout);
@@ -159,7 +158,6 @@ bool OtlpGrpcLogRecordExporter::ForceFlush(
159158

160159
bool OtlpGrpcLogRecordExporter::isShutdown() const noexcept
161160
{
162-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
163161
return is_shutdown_;
164162
}
165163

exporters/otlp/src/otlp_grpc_metric_exporter.cc

-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ bool OtlpGrpcMetricExporter::ForceFlush(
141141
bool OtlpGrpcMetricExporter::Shutdown(
142142
OPENTELEMETRY_MAYBE_UNUSED std::chrono::microseconds timeout) noexcept
143143
{
144-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
145144
is_shutdown_ = true;
146145
#ifdef ENABLE_ASYNC_EXPORT
147146
return client_->Shutdown(timeout);
@@ -152,7 +151,6 @@ bool OtlpGrpcMetricExporter::Shutdown(
152151

153152
bool OtlpGrpcMetricExporter::isShutdown() const noexcept
154153
{
155-
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(lock_);
156154
return is_shutdown_;
157155
}
158156

exporters/prometheus/include/opentelemetry/exporters/prometheus/exporter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <vector>
99

1010
#include <prometheus/exposer.h>
11-
#include "opentelemetry/common/spin_lock_mutex.h"
11+
1212
#include "opentelemetry/exporters/prometheus/collector.h"
1313
#include "opentelemetry/exporters/prometheus/exporter_options.h"
1414
#include "opentelemetry/nostd/span.h"

exporters/zipkin/include/opentelemetry/exporters/zipkin/zipkin_exporter.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#pragma once
55

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

1413
#include "nlohmann/json.hpp"
1514

15+
#include <atomic>
16+
1617
OPENTELEMETRY_BEGIN_NAMESPACE
1718
namespace exporter
1819
{
@@ -69,7 +70,7 @@ class ZipkinExporter final : public opentelemetry::sdk::trace::SpanExporter
6970

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

87-
mutable opentelemetry::common::SpinLockMutex lock_;
8888
bool isShutdown() const noexcept;
8989
};
9090
} // namespace zipkin

0 commit comments

Comments
 (0)