Skip to content

Commit

Permalink
Merge branch 'main' into fix_build_for_m32_platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Nov 24, 2024
2 parents 851da95 + c1ef416 commit 75eb177
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 290 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Enable automatic configs based on platform
common --enable_platform_specific_config

# Make globs that don't match anything fail
common --incompatible_disallow_empty_glob

# Needed by gRPC to build on some platforms.
build --copt -DGRPC_BAZEL_BUILD

Expand Down
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ if(OTELCPP_VERSIONED_LIBS AND NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "OTELCPP_VERSIONED_LIBS=ON requires BUILD_SHARED_LIBS=ON")
endif()

set(OTELCPP_PROTO_PATH
""
CACHE PATH "Path to opentelemetry-proto")

if(WIN32)
option(WITH_ETW "Whether to include the ETW Exporter in the SDK" ON)
else()
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "github_nlohma
bazel_dep(name = "opentelemetry-proto", version = "1.3.2", repo_name = "com_github_opentelemetry_proto")
bazel_dep(name = "opentracing-cpp", version = "1.6.0", repo_name = "com_github_opentracing")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "prometheus-cpp", version = "1.2.4", repo_name = "com_github_jupp0r_prometheus_cpp")
bazel_dep(name = "prometheus-cpp", version = "1.3.0", repo_name = "com_github_jupp0r_prometheus_cpp")
bazel_dep(name = "protobuf", version = "26.0", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "zlib", version = "1.3.1.bcr.1")
Expand Down
6 changes: 3 additions & 3 deletions bazel/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def opentelemetry_cpp_deps():
http_archive,
name = "com_github_opentelemetry_proto",
build_file = "@io_opentelemetry_cpp//bazel:opentelemetry_proto.BUILD",
sha256 = "c069c0d96137cf005d34411fa67dd3b6f1f8c64af1e7fb2fe0089a41c425acd7",
strip_prefix = "opentelemetry-proto-1.3.2",
sha256 = "53cd32cedb27762ea2060a9c8d83e4b822de13d73b5d5d37a2db3cf55018d694",
strip_prefix = "opentelemetry-proto-1.4.0",
urls = [
"https://github.com/open-telemetry/opentelemetry-proto/archive/v1.3.2.tar.gz",
"https://github.com/open-telemetry/opentelemetry-proto/archive/v1.4.0.tar.gz",
],
)

Expand Down
2 changes: 1 addition & 1 deletion cmake/opentelemetry-cpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ endif()

if(@WITH_ABSEIL@ OR @WITH_OTLP_GRPC@)
find_package(absl CONFIG)
elseif(OR @WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@)
elseif(@WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@)
if("@Protobuf_VERSION@" VERSION_GREATER_EQUAL "3.22.0")
find_package(absl CONFIG)
endif()
Expand Down
36 changes: 13 additions & 23 deletions cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ else()
"opentelemetry-proto=[ \\t]*([A-Za-z0-9_\\.\\-]+)")
set(opentelemetry-proto "${CMAKE_MATCH_1}")
else()
set(opentelemetry-proto "v1.3.2")
set(opentelemetry-proto "v1.4.0")
endif()
unset(OTELCPP_THIRD_PARTY_RELEASE_CONTENT)
endif()
Expand Down Expand Up @@ -81,10 +81,7 @@ set(LOGS_PROTO "${PROTO_PATH}/opentelemetry/proto/logs/v1/logs.proto")
set(METRICS_PROTO "${PROTO_PATH}/opentelemetry/proto/metrics/v1/metrics.proto")

set(PROFILES_PROTO
"${PROTO_PATH}/opentelemetry/proto/profiles/v1experimental/profiles.proto")
set(PROFILES_EXT_PROTO
"${PROTO_PATH}/opentelemetry/proto/profiles/v1experimental/pprofextended.proto"
)
"${PROTO_PATH}/opentelemetry/proto/profiles/v1development/profiles.proto")

set(TRACE_SERVICE_PROTO
"${PROTO_PATH}/opentelemetry/proto/collector/trace/v1/trace_service.proto")
Expand All @@ -95,7 +92,7 @@ set(METRICS_SERVICE_PROTO
)

set(PROFILES_SERVICE_PROTO
"${PROTO_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.proto"
"${PROTO_PATH}/opentelemetry/proto/collector/profiles/v1development/profiles_service.proto"
)

set(GENERATED_PROTOBUF_PATH
Expand Down Expand Up @@ -138,30 +135,24 @@ set(TRACE_SERVICE_PB_H_FILE
#

set(PROFILES_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1experimental/profiles.pb.cc"
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1development/profiles.pb.cc"
)
set(PROFILES_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1experimental/profiles.pb.h"
)
set(PROFILES_EXT_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1experimental/pprofextended.pb.cc"
)
set(PROFILES_EXT_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1experimental/pprofextended.pb.h"
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/profiles/v1development/profiles.pb.h"
)
set(PROFILES_SERVICE_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.pb.h"
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1development/profiles_service.pb.h"
)
set(PROFILES_SERVICE_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.pb.cc"
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1development/profiles_service.pb.cc"
)

if(WITH_OTLP_GRPC)
set(PROFILES_SERVICE_GRPC_PB_H_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.grpc.pb.h"
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1development/profiles_service.grpc.pb.h"
)
set(PROFILES_SERVICE_GRPC_PB_CPP_FILE
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1experimental/profiles_service.grpc.pb.cc"
"${GENERATED_PROTOBUF_PATH}/opentelemetry/proto/collector/profiles/v1development/profiles_service.grpc.pb.cc"
)
endif()

Expand Down Expand Up @@ -243,8 +234,6 @@ set(PROTOBUF_GENERATED_FILES
${METRICS_PB_CPP_FILE}
${PROFILES_H_FILE}
${PROFILES_CPP_FILE}
${PROFILES_EXT_H_FILE}
${PROFILES_EXT_CPP_FILE}
${TRACE_SERVICE_PB_H_FILE}
${TRACE_SERVICE_PB_CPP_FILE}
${LOGS_SERVICE_PB_H_FILE}
Expand Down Expand Up @@ -283,7 +272,6 @@ foreach(
${LOGS_PROTO}
${METRICS_PROTO}
${PROFILES_PROTO}
${PROFILES_EXT_PROTO}
${TRACE_SERVICE_PROTO}
${LOGS_SERVICE_PROTO}
${METRICS_SERVICE_PROTO}
Expand All @@ -298,9 +286,11 @@ add_custom_command(
${PROTOBUF_PROTOC_EXECUTABLE} ${PROTOBUF_COMMON_FLAGS}
${PROTOBUF_INCLUDE_FLAGS} ${COMMON_PROTO} ${RESOURCE_PROTO} ${TRACE_PROTO}
${LOGS_PROTO} ${METRICS_PROTO} ${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO}
${METRICS_SERVICE_PROTO} ${PROFILES_PROTO} ${PROFILES_EXT_PROTO}
${METRICS_SERVICE_PROTO} ${PROFILES_PROTO}
${PROFILES_SERVICE_PROTO}
COMMENT "[Run]: ${PROTOBUF_RUN_PROTOC_COMMAND}")
COMMENT "[Run]: ${PROTOBUF_RUN_PROTOC_COMMAND}"
DEPENDS ${PROTOBUF_PROTOC_EXECUTABLE}
)

include_directories("${GENERATED_PROTOBUF_PATH}")

Expand Down
92 changes: 69 additions & 23 deletions exporters/elasticsearch/test/es_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,48 @@
// SPDX-License-Identifier: Apache-2.0

#include "opentelemetry/exporters/elasticsearch/es_log_record_exporter.h"
#include "opentelemetry/ext/http/server/http_server.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/exporters/elasticsearch/es_log_recordable.h"
#include "opentelemetry/logs/severity.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/logger_provider.h"
#include "opentelemetry/sdk/logs/simple_log_record_processor.h"
#include "opentelemetry/sdk/resource/resource.h"

#include <gtest/gtest.h>
#include <iostream>
#include <chrono>
#include <string>

namespace sdklogs = opentelemetry::sdk::logs;
namespace logs_api = opentelemetry::logs;
namespace nostd = opentelemetry::nostd;
namespace logs_exporter = opentelemetry::exporter::logs;

TEST(ElasticsearchLogsExporterTests, Dummy)
{
// to enable linking
}

#if 0
// Attempt to write a log to an invalid host/port, test that the Export() returns failure
TEST(ElasticsearchLogsExporterTests, InvalidEndpoint)
TEST(DISABLED_ElasticsearchLogsExporterTests, InvalidEndpoint)
{
// Create invalid connection options for the elasticsearch exporter
logs_exporter::ElasticsearchExporterOptions options("localhost", -1);

// Create an elasticsearch exporter
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter(options));
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new logs_exporter::ElasticsearchLogRecordExporter(options));

// Create a log record and send to the exporter
auto record = exporter->MakeRecordable();
auto result = exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

// Ensure the return value is failure
ASSERT_EQ(result, sdk::common::ExportResult::kFailure);
ASSERT_EQ(result, opentelemetry::sdk::common::ExportResult::kFailure);
}

// Test that when the exporter is shutdown, any call to Export should return failure
TEST(ElasticsearchLogsExporterTests, Shutdown)
TEST(DISABLED_ElasticsearchLogsExporterTests, Shutdown)
{
// Create an elasticsearch exporter and immediately shut it down
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter);
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new logs_exporter::ElasticsearchLogRecordExporter);
bool shutdownResult = exporter->Shutdown();
ASSERT_TRUE(shutdownResult);

Expand All @@ -54,15 +52,15 @@ TEST(ElasticsearchLogsExporterTests, Shutdown)
auto result = exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

// Ensure the return value is failure
ASSERT_EQ(result, sdk::common::ExportResult::kFailure);
ASSERT_EQ(result, opentelemetry::sdk::common::ExportResult::kFailure);
}

// Test the elasticsearch recordable object
TEST(ElasticsearchLogsExporterTests, RecordableCreation)
TEST(DISABLED_ElasticsearchLogsExporterTests, RecordableCreation)
{
// Create an elasticsearch exporter
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter);
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new logs_exporter::ElasticsearchLogRecordExporter);

// Create a recordable
auto record = exporter->MakeRecordable();
Expand All @@ -79,4 +77,52 @@ TEST(ElasticsearchLogsExporterTests, RecordableCreation)

exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));
}
#endif

TEST(ElasticsearchLogRecordableTests, BasicTests)
{
const auto severity = logs_api::Severity::kFatal;
const std::array<nostd::string_view, 2> stringlist{
{nostd::string_view("string1"), nostd::string_view("string2")}};

const std::int64_t expected_observed_ts = 1732063944999647774LL;
const std::string expected_timestamp("2024-11-20T00:52:24.999647Z");
const std::string expected_severity(
opentelemetry::logs::SeverityNumToText[static_cast<std::size_t>(severity)]);
const std::string expected_body("Body of the log message");
const std::string expected_scope_name("scope_name");
const bool expected_boolean = false;
const int expected_int = 1;
const double expected_double = 2.0;

const nlohmann::json expected{
{"@timestamp", expected_timestamp},
{"boolean", expected_boolean},
{"double", expected_double},
{"ecs", {{"version", "8.11.0"}}},
{"int", expected_int},
{"log", {{"level", expected_severity}, {"logger", expected_scope_name}}},
{"message", expected_body},
{"observedtimestamp", expected_observed_ts},
{"stringlist", {stringlist[0], stringlist[1]}}};

const opentelemetry::common::SystemTimestamp now{std::chrono::nanoseconds(expected_observed_ts)};

const auto scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(expected_scope_name);

opentelemetry::exporter::logs::ElasticSearchRecordable recordable;
recordable.SetTimestamp(now);
recordable.SetObservedTimestamp(now);
recordable.SetSeverity(severity);
recordable.SetBody(expected_body);
recordable.SetInstrumentationScope(*scope);

recordable.SetAttribute("boolean", expected_boolean);
recordable.SetAttribute("int", expected_int);
recordable.SetAttribute("double", expected_double);
recordable.SetAttribute("stringlist", stringlist);

const auto actual = recordable.GetJSON();

EXPECT_EQ(actual, expected);
}
Loading

0 comments on commit 75eb177

Please sign in to comment.