Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-cmake-grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Jul 30, 2021
2 parents a14806f + ef16d00 commit 0d28b9c
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 82 deletions.
34 changes: 14 additions & 20 deletions exporters/elasticsearch/src/es_log_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

#ifdef ENABLE_LOGS_PREVIEW

# include <sstream> // std::stringstream

# include "opentelemetry/exporters/elasticsearch/es_log_exporter.h"
# include "opentelemetry/exporters/elasticsearch/es_log_recordable.h"
# include "opentelemetry/sdk_config.h"

namespace nostd = opentelemetry::nostd;
namespace sdklogs = opentelemetry::sdk::logs;
Expand Down Expand Up @@ -74,23 +77,19 @@ class ResponseHandler : public http_client::EventHandler
switch (state)
{
case http_client::SessionState::ConnectFailed:
if (console_debug_)
std::cout << "Connection to elasticsearch failed\n";
OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Connection to elasticsearch failed");
cv_.notify_all();
break;
case http_client::SessionState::SendFailed:
if (console_debug_)
std::cout << "Request failed to be sent to elasticsearch\n";
OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Request failed to be sent to elasticsearch");
cv_.notify_all();
break;
case http_client::SessionState::TimedOut:
if (console_debug_)
std::cout << "Request to elasticsearch timed out\n";
OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Request to elasticsearch timed out");
cv_.notify_all();
break;
case http_client::SessionState::NetworkError:
if (console_debug_)
std::cout << "Network error to elasticsearch\n";
OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Network error to elasticsearch");
cv_.notify_all();
break;
}
Expand Down Expand Up @@ -131,11 +130,8 @@ sdk::common::ExportResult ElasticsearchLogExporter::Export(
// Return failure if this exporter has been shutdown
if (is_shutdown_)
{
if (options_.console_debug_)
{
std::cout << "Export failed, exporter is shutdown" << std::endl;
}

OTEL_INTERNAL_LOG_ERROR("[ES Trace Exporter] Export failed, exporter is shutdown");
return sdk::common::ExportResult::kFailure;
}

Expand Down Expand Up @@ -172,8 +168,9 @@ sdk::common::ExportResult ElasticsearchLogExporter::Export(
// Wait for the response to be received
if (options_.console_debug_)
{
std::cout << "waiting for response from Elasticsearch (timeout = " << options_.response_timeout_
<< " seconds)" << std::endl;
OTEL_INTERNAL_LOG_DEBUG(
"[ES Trace Exporter] waiting for response from Elasticsearch (timeout = "
<< options_.response_timeout_ << " seconds)");
}
bool write_successful = handler->waitForResponse();

Expand All @@ -191,12 +188,9 @@ sdk::common::ExportResult ElasticsearchLogExporter::Export(
std::string responseBody = handler->GetResponseBody();
if (responseBody.find("\"failed\" : 0") == std::string::npos)
{
if (options_.console_debug_)
{
std::cout << "Logs were not written to Elasticsearch correctly, response body:" << std::endl;
std::cout << responseBody << std::endl;
}

OTEL_INTERNAL_LOG_ERROR(
"[ES Trace Exporter] Logs were not written to Elasticsearch correctly, response body: "
<< responseBody);
// TODO: Retry logic
return sdk::common::ExportResult::kFailure;
}
Expand Down
5 changes: 4 additions & 1 deletion exporters/jaeger/src/TUDPTransport.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <sstream> // std::stringstream

#include "TUDPTransport.h"
#include "opentelemetry/sdk_config.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
Expand Down Expand Up @@ -51,7 +54,7 @@ void TUDPTransport::open()

if (error)
{
// TODO: log error
OTEL_INTERNAL_LOG_ERROR("Jaeger Exporter: getaddrinfo failed with error: " << error);
return;
}

Expand Down
5 changes: 4 additions & 1 deletion exporters/jaeger/src/udp_transport.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <sstream> // std::stringstream

#include "opentelemetry/sdk_config.h"
#include "udp_transport.h"

OPENTELEMETRY_BEGIN_NAMESPACE
Expand Down Expand Up @@ -36,7 +39,7 @@ void UDPTransport::InitSocket()
int err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0)
{
// TODO: handle error
OTEL_INTERNAL_LOG_ERROR("Jaeger Exporter: WSAStartup failed with error: " << error);
return;
}

Expand Down
6 changes: 4 additions & 2 deletions exporters/otlp/src/otlp_grpc_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_recordable.h"
#include "opentelemetry/sdk_config.h"

#include <grpcpp/grpcpp.h>
#include <fstream>
#include <iostream>
#include <sstream> // std::stringstream

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
Expand Down Expand Up @@ -112,7 +113,8 @@ sdk::common::ExportResult OtlpGrpcExporter::Export(

if (!status.ok())
{
std::cerr << "[OTLP Exporter] Export() failed: " << status.error_message() << "\n";

OTEL_INTERNAL_LOG_ERROR("[OTLP Exporter] Export() failed: " << status.error_message());
return sdk::common::ExportResult::kFailure;
}
return sdk::common::ExportResult::kSuccess;
Expand Down
85 changes: 34 additions & 51 deletions exporters/otlp/src/otlp_http_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
#include "opentelemetry/proto/collector/trace/v1/trace_service.pb.h"

#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"
#include "opentelemetry/sdk_config.h"

#include <condition_variable>
#include <fstream>
#include <iostream>
#include <mutex>
#include <sstream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -66,14 +67,15 @@ class ResponseHandler : public http_client::EventHandler

if (console_debug_)
{
std::cout << "[OTLP HTTP Exporter] Status:" << response.GetStatusCode() << std::endl
<< "Header:" << std::endl;
response.ForEachHeader([](opentelemetry::nostd::string_view header_name,
opentelemetry::nostd::string_view header_value) {
std::cout << "\t" << header_name.data() << " : " << header_value.data() << std::endl;
std::stringstream ss;
ss << "[OTLP HTTP Exporter] Status:" << response.GetStatusCode() << "Header:";
response.ForEachHeader([&ss](opentelemetry::nostd::string_view header_name,
opentelemetry::nostd::string_view header_value) {
ss << "\t" << header_name.data() << " : " << header_value.data() << ",";
return true;
});
std::cout << "Body:" << std::endl << body_ << std::endl;
ss << "Body:" << body_;
OTEL_INTERNAL_LOG_DEBUG(ss.str());
}

// Set the response_received_ flag to true and notify any threads waiting on this result
Expand All @@ -82,7 +84,7 @@ class ResponseHandler : public http_client::EventHandler
cv_.notify_all();
}

/**
/**resource
* A method the user calls to block their thread until the response is received. The longest
* duration is the timeout of the request, set by SetTimeoutMs()
*/
Expand Down Expand Up @@ -111,114 +113,94 @@ class ResponseHandler : public http_client::EventHandler
switch (state)
{
case http_client::SessionState::CreateFailed:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: session create failed" << std::endl;
}
OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: session create failed");
cv_.notify_all();
break;

case http_client::SessionState::Created:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: session created" << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: session created");
}
break;

case http_client::SessionState::Destroyed:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: session destroyed" << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: session destroyed");
}
break;

case http_client::SessionState::Connecting:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: connecting to peer" << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: connecting to peer");
}
break;

case http_client::SessionState::ConnectFailed:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: connection failed" << std::endl;
}
OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: connection failed");
cv_.notify_all();
break;

case http_client::SessionState::Connected:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: connected" << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: connected");
}
break;

case http_client::SessionState::Sending:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: sending request" << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: sending request");
}
break;

case http_client::SessionState::SendFailed:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: request send failed" << std::endl;
}
OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: request send failed");
cv_.notify_all();
break;

case http_client::SessionState::Response:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: response received" << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: response received");
}
break;

case http_client::SessionState::SSLHandshakeFailed:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: SSL handshake failed" << std::endl;
}
OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: SSL handshake failed");
cv_.notify_all();
break;

case http_client::SessionState::TimedOut:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: request time out" << std::endl;
}
OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: request time out");
cv_.notify_all();
break;

case http_client::SessionState::NetworkError:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: network error" << std::endl;
}
OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: network error");
cv_.notify_all();
break;

case http_client::SessionState::ReadError:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: error reading response" << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Session state: error reading response");
}
break;

case http_client::SessionState::WriteError:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: error writing request" << std::endl;
OTEL_INTERNAL_LOG_DEBUG(
"[OTLP HTTP Exporter] DEBUG:Session state: error writing request");
}
break;

case http_client::SessionState::Cancelled:
if (console_debug_)
{
std::cerr << "[OTLP HTTP Exporter] Session state: (manually) cancelled" << std::endl;
}
OTEL_INTERNAL_LOG_ERROR("[OTLP HTTP Exporter] Session state: (manually) cancelled\n");
cv_.notify_all();
break;

Expand Down Expand Up @@ -612,16 +594,16 @@ sdk::common::ExportResult OtlpHttpExporter::Export(
{
if (options_.console_debug)
{
std::cout << "[OTLP HTTP Exporter] Request body(Binary):\n"
<< service_request.Utf8DebugString() << std::endl;
OTEL_INTERNAL_LOG_DEBUG(
"[OTLP HTTP Exporter] Request body(Binary): " << service_request.Utf8DebugString());
}
}
else
{
if (options_.console_debug)
{
std::cout << "[OTLP HTTP Exporter] Serialize body failed(Binary):"
<< service_request.InitializationErrorString() << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Serialize body failed(Binary):"
<< service_request.InitializationErrorString());
}
return sdk::common::ExportResult::kFailure;
}
Expand All @@ -638,7 +620,7 @@ sdk::common::ExportResult OtlpHttpExporter::Export(
json_request.dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace);
if (options_.console_debug)
{
std::cout << "[OTLP HTTP Exporter] Request body(Json):\n" << post_body_json << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] Request body(Json)" << post_body_json);
}
body_vec.assign(post_body_json.begin(), post_body_json.end());
content_type = kHttpJsonContentType;
Expand All @@ -660,8 +642,9 @@ sdk::common::ExportResult OtlpHttpExporter::Export(
// Wait for the response to be received
if (options_.console_debug)
{
std::cout << "[OTLP HTTP Exporter] Waiting for response from " << options_.url
<< " (timeout = " << options_.timeout.count() << " milliseconds)" << std::endl;
OTEL_INTERNAL_LOG_DEBUG("[OTLP HTTP Exporter] DEBUG: Waiting for response from "
<< options_.url << " (timeout = " << options_.timeout.count()
<< " milliseconds)");
}
bool write_successful = handler->waitForResponse();

Expand Down
3 changes: 2 additions & 1 deletion exporters/zipkin/src/zipkin_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "opentelemetry/exporters/zipkin/recordable.h"
#include "opentelemetry/ext/http/client/http_client_factory.h"
#include "opentelemetry/ext/http/common/url_parser.h"
#include "opentelemetry/sdk_config.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
Expand Down Expand Up @@ -71,7 +72,7 @@ sdk::common::ExportResult ZipkinExporter::Export(
{
if (result.GetSessionState() == http_client::SessionState::ConnectFailed)
{
// TODO -> Handle error / retries
OTEL_INTERNAL_LOG_ERROR("ZIPKIN EXPORTER] Zipkin Exporter: Connection failed");
}
return sdk::common::ExportResult::kFailure;
}
Expand Down
4 changes: 2 additions & 2 deletions ext/include/opentelemetry/ext/http/client/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ class Result
{
if (response_ == nullptr)
{
static NoopResponse res;
return res;
// let's not return nullptr
response_.reset(new NoopResponse());
}
return *response_;
}
Expand Down
Loading

0 comments on commit 0d28b9c

Please sign in to comment.