Skip to content

Commit

Permalink
agents: share channel between OTLP exporters
Browse files Browse the repository at this point in the history
This will allow less grpc threads/resources to be used.
  • Loading branch information
santigimeno committed Dec 18, 2024
1 parent a369b9e commit 54d80b1
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions agents/grpc/src/grpc_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
#include "absl/log/initialize.h"
#include "opentelemetry/sdk/metrics/data/metric_data.h"
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_client.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_log_record_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_metric_utils.h"
#include "opentelemetry/trace/semantic_conventions.h"

Expand All @@ -29,12 +34,17 @@ using opentelemetry::sdk::metrics::ScopeMetrics;
using opentelemetry::sdk::resource::Resource;
using opentelemetry::sdk::resource::ResourceAttributes;
using opentelemetry::sdk::trace::Recordable;
using opentelemetry::v1::exporter::otlp::OtlpGrpcClient;
using opentelemetry::v1::exporter::otlp::OtlpGrpcClientFactory;
using opentelemetry::v1::exporter::otlp::OtlpGrpcClientOptions;
using opentelemetry::v1::exporter::otlp::OtlpGrpcExporter;
using opentelemetry::v1::exporter::otlp::OtlpGrpcExporterFactory;
using opentelemetry::v1::exporter::otlp::OtlpGrpcExporterOptions;
using opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporter;
using opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterFactory;
using opentelemetry::v1::exporter::otlp::OtlpGrpcLogRecordExporterOptions;
using opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporter;
using opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterFactory;
using opentelemetry::v1::exporter::otlp::OtlpGrpcMetricExporterOptions;
using opentelemetry::v1::exporter::otlp::OtlpMetricUtils;
using opentelemetry::v1::trace::SemanticConventions::kProcessOwner;
Expand Down Expand Up @@ -1020,6 +1030,24 @@ int GrpcAgent::config(const json& config) {
it->get<std::string>() : console_id_ + ".grpc.nodesource.io:443";
Debug("GrpcAgent configured. Endpoint: %s. Insecure: %d\n",
endpoint.c_str(), static_cast<unsigned>(insecure));


OtlpGrpcClientOptions opts;
opts.endpoint = endpoint;
opts.metadata = {{"nsolid-agent-id", agent_id_},
{"nsolid-saas", saas_}};
if (!insecure) {
opts.use_ssl_credentials = true;
if (!custom_certs_.empty()) {
opts.ssl_credentials_cacert_as_string = custom_certs_;
} else {
opts.ssl_credentials_cacert_as_string = cacert_;
}
}

std::shared_ptr<OtlpGrpcClient> client = OtlpGrpcClientFactory::Create(opts);
nsolid_service_stub_ = GrpcClient::MakeNSolidServiceStub(opts);

{
OtlpGrpcExporterOptions options;
options.endpoint = endpoint;
Expand All @@ -1034,7 +1062,7 @@ int GrpcAgent::config(const json& config) {
}
}

trace_exporter_ = std::make_unique<OtlpGrpcExporter>(options);
trace_exporter_ = std::make_unique<OtlpGrpcExporter>(options, client);
}
{
OtlpGrpcMetricExporterOptions options;
Expand All @@ -1050,7 +1078,8 @@ int GrpcAgent::config(const json& config) {
}
}

metrics_exporter_ = std::make_unique<OtlpGrpcMetricExporter>(options);
metrics_exporter_ =
std::make_unique<OtlpGrpcMetricExporter>(options, client);
}
{
OtlpGrpcLogRecordExporterOptions options;
Expand All @@ -1066,24 +1095,10 @@ int GrpcAgent::config(const json& config) {
}
}

log_exporter_ = std::make_unique<OtlpGrpcLogRecordExporter>(options);
log_exporter_ =
std::make_unique<OtlpGrpcLogRecordExporter>(options, client);
}
{
OtlpGrpcClientOptions options;
options.endpoint = endpoint;
options.metadata = {{"nsolid-agent-id", agent_id_},
{"nsolid-saas", saas_}};
if (!insecure) {
options.use_ssl_credentials = true;
if (!custom_certs_.empty()) {
options.ssl_credentials_cacert_as_string = custom_certs_;
} else {
options.ssl_credentials_cacert_as_string = cacert_;
}
}

nsolid_service_stub_ = GrpcClient::MakeNSolidServiceStub(options);
}
reset_command_stream();
}
}
Expand Down

0 comments on commit 54d80b1

Please sign in to comment.