Skip to content

Commit

Permalink
Add preview feature-flag/macro for logs (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored May 29, 2021
1 parent 33c6f6d commit f793e6e
Show file tree
Hide file tree
Showing 41 changed files with 347 additions and 230 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ if(WITH_METRICS_PREVIEW)
add_definitions(-DENABLE_METRICS_PREVIEW)
endif()

option(WITH_LOGS_PREVIEW "Whether to build logs preview" OFF)

if(WITH_LOGS_PREVIEW)
add_definitions(-DENABLE_LOGS_PREVIEW)
endif()

find_package(Threads)

function(install_windows_deps)
Expand Down
12 changes: 12 additions & 0 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ install(
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

set(LOGS_EXCLUDE_PATTERN "")
if(NOT WITH_LOGS_PREVIEW)
set(LOGS_EXCLUDE_PATTERN "logs")
endif()

set(METRICS_EXCLUDE_PATTERN "")
if(NOT WITH_METRICS_PREVIEW)
set(METRICS_EXCLUDE_PATTERN "metrics")
Expand All @@ -25,6 +30,13 @@ install(
PATTERN "*.h"
PATTERN "${METRICS_EXCLUDE_PATTERN}" EXCLUDE)

install(
DIRECTORY include/opentelemetry
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN "${LOGS_EXCLUDE_PATTERN}" EXCLUDE)

if(BUILD_TESTING)
add_subdirectory(test)
endif()
Expand Down
38 changes: 20 additions & 18 deletions api/include/opentelemetry/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <chrono>
#include <map>
#include <vector>

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable.h"
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/logs/severity.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/type_traits.h"
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/trace_flags.h"
#include "opentelemetry/trace/trace_id.h"
#include "opentelemetry/version.h"
#ifdef ENABLE_LOGS_PREVIEW

# include <chrono>
# include <map>
# include <vector>

# include "opentelemetry/common/attribute_value.h"
# include "opentelemetry/common/key_value_iterable.h"
# include "opentelemetry/common/key_value_iterable_view.h"
# include "opentelemetry/common/timestamp.h"
# include "opentelemetry/logs/severity.h"
# include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/nostd/span.h"
# include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/nostd/type_traits.h"
# include "opentelemetry/trace/span_id.h"
# include "opentelemetry/trace/trace_flags.h"
# include "opentelemetry/trace/trace_id.h"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace logs
Expand Down Expand Up @@ -568,3 +569,4 @@ class Logger
};
} // namespace logs
OPENTELEMETRY_END_NAMESPACE
#endif
8 changes: 5 additions & 3 deletions api/include/opentelemetry/logs/logger_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#ifdef ENABLE_LOGS_PREVIEW

#include "opentelemetry/logs/logger.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/logs/logger.h"
# include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/nostd/string_view.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace logs
Expand Down Expand Up @@ -37,3 +38,4 @@ class LoggerProvider
};
} // namespace logs
OPENTELEMETRY_END_NAMESPACE
#endif
37 changes: 20 additions & 17 deletions api/include/opentelemetry/logs/noop.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#ifdef ENABLE_LOGS_PREVIEW

// Please refer to provider.h for documentation on how to obtain a Logger object.
//
// This file is part of the internal implementation of OpenTelemetry. Nothing in this file should be
// used directly. Please refer to logger.h for documentation on these interfaces.

#include <memory>
# include <memory>

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/context/runtime_context.h"
#include "opentelemetry/logs/logger.h"
#include "opentelemetry/logs/logger_provider.h"
#include "opentelemetry/logs/severity.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/trace_flags.h"
#include "opentelemetry/trace/trace_id.h"
#include "opentelemetry/version.h"
# include "opentelemetry/common/attribute_value.h"
# include "opentelemetry/common/key_value_iterable.h"
# include "opentelemetry/common/timestamp.h"
# include "opentelemetry/context/runtime_context.h"
# include "opentelemetry/logs/logger.h"
# include "opentelemetry/logs/logger_provider.h"
# include "opentelemetry/logs/severity.h"
# include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/nostd/span.h"
# include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/nostd/unique_ptr.h"
# include "opentelemetry/trace/span_id.h"
# include "opentelemetry/trace/trace_flags.h"
# include "opentelemetry/trace/trace_id.h"
# include "opentelemetry/version.h"

#include "opentelemetry/version.h"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace logs
Expand Down Expand Up @@ -79,3 +81,4 @@ class NoopLoggerProvider final : public opentelemetry::logs::LoggerProvider
};
} // namespace logs
OPENTELEMETRY_END_NAMESPACE
#endif
12 changes: 7 additions & 5 deletions api/include/opentelemetry/logs/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#ifdef ENABLE_LOGS_PREVIEW

#include <mutex>
# include <mutex>

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/logs/logger_provider.h"
#include "opentelemetry/logs/noop.h"
#include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/common/spin_lock_mutex.h"
# include "opentelemetry/logs/logger_provider.h"
# include "opentelemetry/logs/noop.h"
# include "opentelemetry/nostd/shared_ptr.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace logs
Expand Down Expand Up @@ -56,3 +57,4 @@ class Provider

} // namespace logs
OPENTELEMETRY_END_NAMESPACE
#endif
5 changes: 4 additions & 1 deletion api/include/opentelemetry/logs/severity.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#include "opentelemetry/version.h"
#ifdef ENABLE_LOGS_PREVIEW

# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace logs
Expand Down Expand Up @@ -56,3 +58,4 @@ const opentelemetry::nostd::string_view SeverityNumToText[25] = {

} // namespace logs
OPENTELEMETRY_END_NAMESPACE
#endif
4 changes: 3 additions & 1 deletion api/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ add_subdirectory(trace)
if(WITH_METRICS_PREVIEW)
add_subdirectory(metrics)
endif()
add_subdirectory(logs)
if(WITH_LOGS_PREVIEW)
add_subdirectory(logs)
endif()
add_subdirectory(common)
add_subdirectory(baggage)
17 changes: 10 additions & 7 deletions api/test/logs/logger_test.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <gtest/gtest.h>
#include <array>
#ifdef ENABLE_LOGS_PREVIEW

#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/logs/logger.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/nostd/shared_ptr.h"
# include <gtest/gtest.h>
# include <array>

# include "opentelemetry/common/timestamp.h"
# include "opentelemetry/logs/logger.h"
# include "opentelemetry/logs/provider.h"
# include "opentelemetry/nostd/shared_ptr.h"

using opentelemetry::logs::Logger;
using opentelemetry::logs::LoggerProvider;
Expand Down Expand Up @@ -109,4 +111,5 @@ TEST(Logger, PushLoggerImplementation)
// Check that the implementation was pushed by calling TestLogger's GetName()
auto logger = lp->GetLogger("TestLogger");
ASSERT_EQ("test logger", logger->GetName());
}
}
#endif
15 changes: 9 additions & 6 deletions api/test/logs/provider_test.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <gtest/gtest.h>
#include <array>
#ifdef ENABLE_LOGS_PREVIEW

#include "opentelemetry/logs/provider.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
# include <gtest/gtest.h>
# include <array>

# include "opentelemetry/logs/provider.h"
# include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/nostd/span.h"
# include "opentelemetry/nostd/string_view.h"

using opentelemetry::logs::Logger;
using opentelemetry::logs::LoggerProvider;
Expand Down Expand Up @@ -66,3 +68,4 @@ TEST(Provider, GetLogger)
auto logger2 = tf->GetLogger("logger2", args);
EXPECT_EQ(nullptr, logger2);
}
#endif
4 changes: 2 additions & 2 deletions ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $action = $args[0]

$SRC_DIR=(Get-Item -Path ".\").FullName

$BAZEL_OPTIONS=""
$BAZEL_OPTIONS="--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW"
$BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors"

if (!(test-path build)) {
Expand All @@ -22,7 +22,7 @@ $VCPKG_DIR="$SRC_DIR\vcpkg"

switch ($action) {
"bazel.build" {
bazel build $BAZEL_OPTIONS -- //... //api/test/... //sdk/test/...
bazel build $BAZEL_OPTIONS -- //...
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
Expand Down
5 changes: 3 additions & 2 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mkdir -p "${BUILD_DIR}"
[ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin
mkdir -p "${PLUGIN_DIR}"

BAZEL_OPTIONS=""
BAZEL_OPTIONS="--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW"
BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors"
BAZEL_STARTUP_OPTIONS="--output_user_root=$HOME/.cache/bazel"

Expand All @@ -39,6 +39,7 @@ if [[ "$1" == "cmake.test" ]]; then
-DWITH_JAEGER=ON \
-DWITH_ELASTICSEARCH=ON \
-DWITH_METRICS_PREVIEW=ON \
-DWITH_LOGS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
"${SRC_DIR}"
make
Expand Down Expand Up @@ -114,7 +115,7 @@ EOF
examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null
exit 0
elif [[ "$1" == "bazel.test" ]]; then
bazel $BAZEL_STARTUP_OPTIONS build --copt=-DENABLE_METRICS_PREVIEW $BAZEL_OPTIONS //...
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS //...
bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS //...
exit 0
elif [[ "$1" == "bazel.legacy.test" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion exporters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if(WITH_ZIPKIN)
add_subdirectory(zipkin)
endif()

if(WITH_ELASTICSEARCH)
if(WITH_ELASTICSEARCH AND WITH_LOGS_PREVIEW)
add_subdirectory(elasticsearch)
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#ifdef ENABLE_LOGS_PREVIEW

#include "nlohmann/json.hpp"
#include "opentelemetry/ext/http/client/curl/http_client_curl.h"
#include "opentelemetry/nostd/type_traits.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/log_record.h"
# include "nlohmann/json.hpp"
# include "opentelemetry/ext/http/client/curl/http_client_curl.h"
# include "opentelemetry/nostd/type_traits.h"
# include "opentelemetry/sdk/logs/exporter.h"
# include "opentelemetry/sdk/logs/log_record.h"

#include <time.h>
#include <iostream>
# include <time.h>
# include <iostream>

namespace nostd = opentelemetry::nostd;
namespace sdklogs = opentelemetry::sdk::logs;
Expand Down Expand Up @@ -109,3 +110,4 @@ class ElasticsearchLogExporter final : public sdklogs::LogExporter
} // namespace logs
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#ifdef ENABLE_LOGS_PREVIEW

#include <map>
#include <unordered_map>
#include "nlohmann/json.hpp"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/sdk/logs/recordable.h"
#include "opentelemetry/version.h"
# include <map>
# include <unordered_map>
# include "nlohmann/json.hpp"
# include "opentelemetry/sdk/common/attribute_utils.h"
# include "opentelemetry/sdk/logs/recordable.h"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
Expand Down Expand Up @@ -158,3 +159,4 @@ class ElasticSearchRecordable final : public sdk::logs::Recordable
} // namespace logs
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif
7 changes: 5 additions & 2 deletions exporters/elasticsearch/src/es_log_exporter.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include "opentelemetry/exporters/elasticsearch/es_log_exporter.h"
#include "opentelemetry/exporters/elasticsearch/es_log_recordable.h"
#ifdef ENABLE_LOGS_PREVIEW

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

namespace nostd = opentelemetry::nostd;
namespace sdklogs = opentelemetry::sdk::logs;
Expand Down Expand Up @@ -215,3 +217,4 @@ bool ElasticsearchLogExporter::Shutdown(std::chrono::microseconds timeout) noexc
} // namespace logs
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif
Loading

0 comments on commit f793e6e

Please sign in to comment.