Skip to content
Merged
3 changes: 2 additions & 1 deletion ext/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include_directories(sdk)
add_library(opentelemetry_ext INTERFACE)
target_include_directories(
opentelemetry_ext
Expand All @@ -19,8 +20,8 @@ install(
FILES_MATCHING
PATTERN "*.h")

add_subdirectory(src)
include_directories(include)
add_subdirectory(src)

if(BUILD_TESTING)
add_subdirectory(test)
Expand Down
19 changes: 19 additions & 0 deletions ext/include/opentelemetry/ext/http/client/http_client_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include "opentelemetry/ext/http/client/http_client.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace ext
{
namespace http
{
namespace client
{
class HttpClientFactory
{
public:
static std::shared_ptr<SessionManager> Create();
};
} // namespace client
} // namespace http
} // namespace ext
OPENTELEMETRY_END_NAMESPACE
1 change: 1 addition & 0 deletions ext/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(zpages)
add_subdirectory(http/client/curl)
14 changes: 14 additions & 0 deletions ext/src/http/client/curl/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "http_client_curl",
srcs = ["http_client_factory_curl.cc"],
include_prefix = "src/http/client/curl",
deps = [
"//api",
"//ext:headers",
"//sdk:headers",
"//sdk/src/common:random",
"@curl",
],
)
4 changes: 4 additions & 0 deletions ext/src/http/client/curl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
find_package(CURL)
if(CURL_FOUND)
add_library(opentelemetry_curl_factory http_client_factory_curl)
endif()
9 changes: 9 additions & 0 deletions ext/src/http/client/curl/http_client_factory_curl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "opentelemetry/ext/http/client/curl/http_client_curl.h"
#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/ext/http/client/http_client_factory.h"

std::shared_ptr<opentelemetry::ext::http::client::SessionManager>
opentelemetry::ext::http::client::HttpClientFactory::Create()
{
return std::make_shared<opentelemetry::ext::http::client::curl::SessionManager>();
}
2 changes: 2 additions & 0 deletions ext/test/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cc_test(
# TODO: Move copts/linkopts for static CURL usage into shared bzl file.
copts = [
"-DCURL_STATICLIB",
"-DWITH_CURL",
],
linkopts = select({
"//bazel:windows": [
Expand All @@ -17,6 +18,7 @@ cc_test(
}),
deps = [
"//ext:headers",
"//ext/src/http/client/curl:http_client_curl",
"//sdk/src/trace",
"@com_google_googletest//:gtest_main",
"@curl",
Expand Down
6 changes: 4 additions & 2 deletions ext/test/http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
find_package(CURL)
if(CURL_FOUND)
set(FILENAME curl_http_test)
add_compile_definitions(WITH_CURL)
Comment thread
lalitb marked this conversation as resolved.
add_executable(${FILENAME} ${FILENAME}.cc)
target_link_libraries(${FILENAME} ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT})

if(TARGET CURL::libcurl)
target_link_libraries(${FILENAME} CURL::libcurl)
target_link_libraries(${FILENAME} CURL::libcurl opentelemetry_curl_factory)
else()
include_directories(${CURL_INCLUDE_DIRS})
target_link_libraries(${FILENAME} ${CURL_LIBRARIES})
target_link_libraries(${FILENAME} ${CURL_LIBRARIES}
opentelemetry_curl_factory)
endif()
gtest_add_tests(
TARGET ${FILENAME}
Expand Down
20 changes: 12 additions & 8 deletions ext/test/http/curl_http_test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "opentelemetry/ext//http/client/curl//http_client_curl.h"
#include "opentelemetry/ext/http/client/http_client_factory.h"
#include "opentelemetry/ext/http/server/http_server.h"

#include <assert.h>
Expand Down Expand Up @@ -184,9 +185,10 @@ TEST_F(BasicCurlHttpTests, HttpResponse)
TEST_F(BasicCurlHttpTests, SendGetRequest)
{
received_requests_.clear();
curl::SessionManager session_manager;
auto session_manager = http_client::HttpClientFactory::Create();
EXPECT_TRUE(session_manager != nullptr);

auto session = session_manager.CreateSession("127.0.0.1", HTTP_PORT);
auto session = session_manager->CreateSession("127.0.0.1", HTTP_PORT);
Comment thread
lalitb marked this conversation as resolved.
auto request = session->CreateRequest();
Comment thread
lalitb marked this conversation as resolved.
request->SetUri("get/");
GetEventHandler *handler = new GetEventHandler();
Expand All @@ -200,9 +202,10 @@ TEST_F(BasicCurlHttpTests, SendGetRequest)
TEST_F(BasicCurlHttpTests, SendPostRequest)
{
received_requests_.clear();
curl::SessionManager session_manager;
auto session_manager = http_client::HttpClientFactory::Create();
EXPECT_TRUE(session_manager != nullptr);

auto session = session_manager.CreateSession("127.0.0.1", HTTP_PORT);
auto session = session_manager->CreateSession("127.0.0.1", HTTP_PORT);
auto request = session->CreateRequest();
Comment thread
lalitb marked this conversation as resolved.
request->SetUri("post/");
request->SetMethod(http_client::Method::Post);
Expand All @@ -217,19 +220,20 @@ TEST_F(BasicCurlHttpTests, SendPostRequest)
session->FinishSession();
ASSERT_TRUE(handler->is_called_);

session_manager.CancelAllSessions();
session_manager.FinishAllSessions();
session_manager->CancelAllSessions();
session_manager->FinishAllSessions();

delete handler;
}

TEST_F(BasicCurlHttpTests, RequestTimeout)
{
received_requests_.clear();
curl::SessionManager session_manager;
auto session_manager = http_client::HttpClientFactory::Create();
EXPECT_TRUE(session_manager != nullptr);

auto session =
session_manager.CreateSession("222.222.222.200", HTTP_PORT); // Non Existing address
session_manager->CreateSession("222.222.222.200", HTTP_PORT); // Non Existing address
auto request = session->CreateRequest();
request->SetUri("get/");
GetEventHandler *handler = new GetEventHandler();
Expand Down