NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/exporters/otlp/otlp_grpc_client.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <grpcpp/grpcpp.h>
7 #include <grpcpp/support/status.h>
8 #include <atomic>
9 #include <chrono>
10 #include <memory>
11 #include <string>
12 
13 #include "opentelemetry/exporters/otlp/otlp_grpc_client_options.h"
14 #include "opentelemetry/version.h"
15 
16 // clang-format off
17 #include "opentelemetry/exporters/otlp/protobuf_include_prefix.h" // IWYU pragma: keep
18 #include "opentelemetry/proto/collector/logs/v1/logs_service.grpc.pb.h"
19 #include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h"
20 #include "opentelemetry/proto/collector/trace/v1/trace_service.grpc.pb.h"
21 #include "opentelemetry/exporters/otlp/protobuf_include_suffix.h" // IWYU pragma: keep
22 // clang-format on
23 
24 #ifdef ENABLE_ASYNC_EXPORT
25 # include <functional>
26 
27 # include "opentelemetry/sdk/common/exporter_utils.h"
28 #endif /* ENABLE_ASYNC_EXPORT */
29 
30 namespace google
31 {
32 namespace protobuf
33 {
34 class Arena;
35 }
36 } // namespace google
37 
38 namespace opentelemetry
39 {
40 namespace proto
41 {
42 namespace collector
43 {
44 
45 namespace logs
46 {
47 namespace v1
48 {
51 } // namespace v1
52 } // namespace logs
53 
54 namespace metrics
55 {
56 namespace v1
57 {
60 } // namespace v1
61 } // namespace metrics
62 
63 namespace trace
64 {
65 namespace v1
66 {
69 } // namespace v1
70 
71 } // namespace trace
72 
73 } // namespace collector
74 } // namespace proto
75 } // namespace opentelemetry
76 
78 namespace exporter
79 {
80 namespace otlp
81 {
82 
83 struct OtlpGrpcClientOptions; // IWYU pragma: keep
84 struct OtlpGrpcClientAsyncData; // IWYU pragma: keep
85 
87 {
88 public:
91 
96 
97 private:
98  friend class OtlpGrpcClient;
99  std::atomic<bool> has_value_;
100 };
101 
106 {
107 public:
108  OtlpGrpcClient(const OtlpGrpcClientOptions &options);
109  ~OtlpGrpcClient();
110  OtlpGrpcClient(const OtlpGrpcClient &) = delete;
111  OtlpGrpcClient(OtlpGrpcClient &&) = delete;
112  OtlpGrpcClient &operator=(const OtlpGrpcClient &) = delete;
114 
115  static std::string GetGrpcTarget(const std::string &endpoint);
116 
120  static std::shared_ptr<grpc::Channel> MakeChannel(const OtlpGrpcClientOptions &options);
121 
125  static std::unique_ptr<grpc::ClientContext> MakeClientContext(
126  const OtlpGrpcClientOptions &options);
127 
131  std::unique_ptr<proto::collector::trace::v1::TraceService::StubInterface> MakeTraceServiceStub();
132 
136  std::unique_ptr<proto::collector::metrics::v1::MetricsService::StubInterface>
138 
142  std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> MakeLogsServiceStub();
143 
144  static grpc::Status DelegateExport(
145  proto::collector::trace::v1::TraceService::StubInterface *stub,
146  std::unique_ptr<grpc::ClientContext> &&context,
147  std::unique_ptr<google::protobuf::Arena> &&arena,
148  proto::collector::trace::v1::ExportTraceServiceRequest &&request,
149  proto::collector::trace::v1::ExportTraceServiceResponse *response);
150 
151  static grpc::Status DelegateExport(
152  proto::collector::metrics::v1::MetricsService::StubInterface *stub,
153  std::unique_ptr<grpc::ClientContext> &&context,
154  std::unique_ptr<google::protobuf::Arena> &&arena,
155  proto::collector::metrics::v1::ExportMetricsServiceRequest &&request,
156  proto::collector::metrics::v1::ExportMetricsServiceResponse *response);
157 
158  static grpc::Status DelegateExport(
159  proto::collector::logs::v1::LogsService::StubInterface *stub,
160  std::unique_ptr<grpc::ClientContext> &&context,
161  std::unique_ptr<google::protobuf::Arena> &&arena,
162  proto::collector::logs::v1::ExportLogsServiceRequest &&request,
163  proto::collector::logs::v1::ExportLogsServiceResponse *response);
164 
166  const OtlpGrpcClientOptions &options) noexcept;
167 
174  bool RemoveReference(OtlpGrpcClientReferenceGuard &guard) noexcept;
175 
176 #ifdef ENABLE_ASYNC_EXPORT
177 
185  sdk::common::ExportResult DelegateAsyncExport(
186  const OtlpGrpcClientOptions &options,
187  proto::collector::trace::v1::TraceService::StubInterface *stub,
188  std::unique_ptr<grpc::ClientContext> &&context,
189  std::unique_ptr<google::protobuf::Arena> &&arena,
190  proto::collector::trace::v1::ExportTraceServiceRequest &&request,
191  std::function<bool(opentelemetry::sdk::common::ExportResult,
192  std::unique_ptr<google::protobuf::Arena> &&,
193  const proto::collector::trace::v1::ExportTraceServiceRequest &,
194  proto::collector::trace::v1::ExportTraceServiceResponse *)>
195  &&result_callback) noexcept;
196 
205  sdk::common::ExportResult DelegateAsyncExport(
206  const OtlpGrpcClientOptions &options,
207  proto::collector::metrics::v1::MetricsService::StubInterface *stub,
208  std::unique_ptr<grpc::ClientContext> &&context,
209  std::unique_ptr<google::protobuf::Arena> &&arena,
210  proto::collector::metrics::v1::ExportMetricsServiceRequest &&request,
211  std::function<bool(opentelemetry::sdk::common::ExportResult,
212  std::unique_ptr<google::protobuf::Arena> &&,
213  const proto::collector::metrics::v1::ExportMetricsServiceRequest &,
214  proto::collector::metrics::v1::ExportMetricsServiceResponse *)>
215  &&result_callback) noexcept;
216 
225  sdk::common::ExportResult DelegateAsyncExport(
226  const OtlpGrpcClientOptions &options,
227  proto::collector::logs::v1::LogsService::StubInterface *stub,
228  std::unique_ptr<grpc::ClientContext> &&context,
229  std::unique_ptr<google::protobuf::Arena> &&arena,
230  proto::collector::logs::v1::ExportLogsServiceRequest &&request,
231  std::function<bool(opentelemetry::sdk::common::ExportResult,
232  std::unique_ptr<google::protobuf::Arena> &&,
233  const proto::collector::logs::v1::ExportLogsServiceRequest &,
234  proto::collector::logs::v1::ExportLogsServiceResponse *)>
235  &&result_callback) noexcept;
236 #endif
237 
241  bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept;
242 
250  std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept;
251 
252  std::shared_ptr<OtlpGrpcClientAsyncData> MutableAsyncData(const OtlpGrpcClientOptions &options);
253 
254  bool IsShutdown() const noexcept;
255 
256 private:
257  // Stores if this gRPC client had its Shutdown() method called
258  std::atomic<bool> is_shutdown_;
259 
260  // Stores shared data between threads of this gRPC client
261  std::shared_ptr<OtlpGrpcClientAsyncData> async_data_;
262 };
263 } // namespace otlp
264 } // namespace exporter
exporter::otlp::OtlpGrpcClient::Shutdown
bool Shutdown(OtlpGrpcClientReferenceGuard &guard, std::chrono::microseconds timeout=std::chrono::microseconds(0)) noexcept
Shut down the gRPC client.
sdk::common::ExportResult
ExportResult
ExportResult is returned as result of exporting a batch of Records.
Definition: includes/opentelemetry/sdk/common/exporter_utils.h:16
exporter::otlp::OtlpGrpcClient::~OtlpGrpcClient
~OtlpGrpcClient()
exporter::otlp::OtlpGrpcClient::MakeTraceServiceStub
std::unique_ptr< proto::collector::trace::v1::TraceService::StubInterface > MakeTraceServiceStub()
Create trace service stub to communicate with the OpenTelemetry Collector.
trace
Definition: includes/opentelemetry/context/context_value.h:18
exporter::otlp::OtlpGrpcClientReferenceGuard::OtlpGrpcClientReferenceGuard
OtlpGrpcClientReferenceGuard() noexcept
logs
Definition: includes/opentelemetry/logs/event_id.h:13
exporter
Definition: includes/opentelemetry/exporters/memory/in_memory_data.h:11
exporter::otlp::OtlpGrpcClient::MakeClientContext
static std::unique_ptr< grpc::ClientContext > MakeClientContext(const OtlpGrpcClientOptions &options)
Create gRPC client context to call RPC.
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceRequest
Definition: includes/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h:80
exporter::otlp::OtlpGrpcClientReferenceGuard::operator=
OtlpGrpcClientReferenceGuard & operator=(const OtlpGrpcClientReferenceGuard &)=delete
context
Definition: includes/opentelemetry/context/context.h:16
exporter::otlp::OtlpGrpcClientOptions
Definition: includes/opentelemetry/exporters/otlp/otlp_grpc_client_options.h:24
opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest
Definition: includes/opentelemetry/proto/collector/logs/v1/logs_service.pb.h:80
exporter::otlp::OtlpGrpcClient::MakeMetricsServiceStub
std::unique_ptr< proto::collector::metrics::v1::MetricsService::StubInterface > MakeMetricsServiceStub()
Create metrics service stub to communicate with the OpenTelemetry Collector.
exporter::otlp::OtlpGrpcClient::MutableAsyncData
std::shared_ptr< OtlpGrpcClientAsyncData > MutableAsyncData(const OtlpGrpcClientOptions &options)
max
int max(int a, int b)
Compute the component-wise maximum.
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:60
exporter::otlp::OtlpGrpcClient::DelegateExport
static grpc::Status DelegateExport(proto::collector::trace::v1::TraceService::StubInterface *stub, std::unique_ptr< grpc::ClientContext > &&context, std::unique_ptr< google::protobuf::Arena > &&arena, proto::collector::trace::v1::ExportTraceServiceRequest &&request, proto::collector::trace::v1::ExportTraceServiceResponse *response)
exporter::otlp::OtlpGrpcClient::IsShutdown
bool IsShutdown() const noexcept
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
exporter::otlp::OtlpGrpcClient::OtlpGrpcClient
OtlpGrpcClient(const OtlpGrpcClientOptions &options)
opentelemetry::proto::collector::logs::v1::ExportLogsServiceResponse
Definition: includes/opentelemetry/proto/collector/logs/v1/logs_service.pb.h:237
opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest
Definition: includes/opentelemetry/proto/collector/trace/v1/trace_service.pb.h:80
exporter::otlp::OtlpGrpcClient::AddReference
void AddReference(OtlpGrpcClientReferenceGuard &guard, const OtlpGrpcClientOptions &options) noexcept
exporter::otlp::OtlpGrpcClient::MakeLogsServiceStub
std::unique_ptr< proto::collector::logs::v1::LogsService::StubInterface > MakeLogsServiceStub()
Create logs service stub to communicate with the OpenTelemetry Collector.
opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse
Definition: includes/opentelemetry/proto/collector/trace/v1/trace_service.pb.h:237
exporter::otlp::OtlpGrpcClient::RemoveReference
bool RemoveReference(OtlpGrpcClientReferenceGuard &guard) noexcept
Reomve reference fro a guard object.
opentelemetry::proto::collector::metrics::v1::ExportMetricsServiceResponse
Definition: includes/opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h:237
exporter::otlp::OtlpGrpcClientReferenceGuard
Definition: includes/opentelemetry/exporters/otlp/otlp_grpc_client.h:86
exporter::otlp::OtlpGrpcClient::ForceFlush
bool ForceFlush(std::chrono::microseconds timeout=(std::chrono::microseconds::max)()) noexcept
Force flush the gRPC client.
exporter::otlp::OtlpGrpcClient
The OTLP gRPC client contains utility functions of gRPC.
Definition: includes/opentelemetry/exporters/otlp/otlp_grpc_client.h:105
metrics
Definition: includes/opentelemetry/metrics/async_instruments.h:10
exporter::otlp::OtlpGrpcClient::operator=
OtlpGrpcClient & operator=(const OtlpGrpcClient &)=delete
exporter::otlp::OtlpGrpcClient::MakeChannel
static std::shared_ptr< grpc::Channel > MakeChannel(const OtlpGrpcClientOptions &options)
Create gRPC channel from the exporter options.
exporter::otlp::OtlpGrpcClientReferenceGuard::~OtlpGrpcClientReferenceGuard
~OtlpGrpcClientReferenceGuard() noexcept
opentelemetry
Definition: includes/opentelemetry/exporters/otlp/otlp_grpc_client.h:38
google
Definition: includes/opentelemetry/exporters/otlp/otlp_grpc_client.h:30
exporter::otlp::OtlpGrpcClient::GetGrpcTarget
static std::string GetGrpcTarget(const std::string &endpoint)