Skip to content

Commit

Permalink
Merge branch 'main' into async-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored May 3, 2022
2 parents 77d344a + 13ac5c3 commit 9dcaf1a
Show file tree
Hide file tree
Showing 46 changed files with 1,353 additions and 187 deletions.
7 changes: 7 additions & 0 deletions .github/.codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ comment:
# to coverage report file paths.
fixes:
- "/home/runner/::"

ignore:
- "docs/**/*"
- "docker/**/*"
- "examples/**/*"
- "**/test/**/*"
- "**.md"
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
sudo ./ci/setup_cmake.sh
sudo ./ci/setup_ci_environment.sh
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: cpp
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ if(WITH_PROMETHEUS)
if(NOT prometheus-cpp_FOUND)
message("Trying to use local prometheus-cpp from submodule")
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/prometheus-cpp/.git)
set(SAVED_ENABLE_TESTING ${ENABLE_TESTING})
set(ENABLE_TESTING OFF)
add_subdirectory(third_party/prometheus-cpp)
set(ENABLE_TESTING ${SAVED_ENABLE_TESTING})
else()
message(
FATAL_ERROR
Expand Down Expand Up @@ -361,7 +364,7 @@ if(BUILD_TESTING)
${CMAKE_BINARY_DIR}/lib/libgmock.a)
elseif(WIN32)
# Make sure we are always bootsrapped with vcpkg on Windows
find_package(GTest)
find_package(GTest REQUIRED)
if(NOT (GTEST_FOUND OR GTest_FOUND))
install_windows_deps()
find_package(GTest REQUIRED)
Expand Down
4 changes: 3 additions & 1 deletion api/include/opentelemetry/baggage/baggage.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ class Baggage
};

auto from_hex = [](char c) -> char {
return std::isdigit(c) ? c - '0' : std::toupper(c) - 'A' + 10;
// c - '0' produces integer type which could trigger error/warning when casting to char,
// but the cast is safe here.
return static_cast<char>(std::isdigit(c) ? c - '0' : std::toupper(c) - 'A' + 10);
};

std::string ret;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <initializer_list>
#include <memory>
#include <vector>
Expand Down
4 changes: 2 additions & 2 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ elif [[ "$1" == "bazel.legacy.test" ]]; then
elif [[ "$1" == "bazel.noexcept" ]]; then
# there are some exceptions and error handling code from the Prometheus and Jaeger Clients
# that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here.
bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/...
bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/...
bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/...
bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... -//examples/prometheus/...
exit 0
elif [[ "$1" == "bazel.nortti" ]]; then
# there are some exceptions and error handling code from the Prometheus and Jaeger Clients
Expand Down
7 changes: 4 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ endif()
if(WITH_ZIPKIN)
add_subdirectory(zipkin)
endif()
if(WITH_PROMETHEUS AND NOT WITH_METRICS_PREVIEW)
add_subdirectory(prometheus)
endif()
add_subdirectory(plugin)
add_subdirectory(simple)
add_subdirectory(batch)
if(WITH_METRICS_PREVIEW)
add_subdirectory(metrics_simple)
endif()
add_subdirectory(metrics_simple)
add_subdirectory(multithreaded)
add_subdirectory(multi_processor)
add_subdirectory(http)
1 change: 1 addition & 0 deletions examples/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ add_subdirectory(foo_library)
if(WITH_LOGS_PREVIEW)
add_subdirectory(logs_foo_library)
endif()
add_subdirectory(metrics_foo_library)
2 changes: 2 additions & 0 deletions examples/common/metrics_foo_library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(common_metrics_foo_library foo_library.h foo_library.cc)
target_link_libraries(common_metrics_foo_library PUBLIC opentelemetry_api)
17 changes: 12 additions & 5 deletions examples/metrics_simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include)

add_executable(simple_metrics main.cc)
target_link_libraries(
simple_metrics ${CMAKE_THREAD_LIBS_INIT} opentelemetry_metrics_deprecated
opentelemetry_exporter_ostream_metrics_deprecated)
if(WITH_METRICS_PREVIEW)
add_executable(simple_metrics main.cc)
target_link_libraries(
simple_metrics ${CMAKE_THREAD_LIBS_INIT} opentelemetry_metrics_deprecated
opentelemetry_exporter_ostream_metrics_deprecated)
else()
add_executable(metrics_ostream_example metrics_ostream.cc)
target_link_libraries(
metrics_ostream_example ${CMAKE_THREAD_LIBS_INIT} opentelemetry_metrics
opentelemetry_exporter_ostream_metrics opentelemetry_resources
common_metrics_foo_library)
endif()
6 changes: 2 additions & 4 deletions examples/metrics_simple/metrics_ostream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace
void initMetrics(const std::string &name)
{
std::unique_ptr<metric_sdk::MetricExporter> exporter{new exportermetrics::OStreamMetricExporter};
std::vector<std::unique_ptr<metric_sdk::MetricExporter>> exporters;

std::string version{"1.2.0"};
std::string schema{"https://opentelemetry.io/schemas/1.2.0"};
Expand All @@ -41,9 +40,8 @@ void initMetrics(const std::string &name)
options.export_timeout_millis = std::chrono::milliseconds(500);
std::unique_ptr<metric_sdk::MetricReader> reader{
new metric_sdk::PeriodicExportingMetricReader(std::move(exporter), options)};
auto provider = std::shared_ptr<metrics_api::MeterProvider>(
new metric_sdk::MeterProvider(std::move(exporters)));
auto p = std::static_pointer_cast<metric_sdk::MeterProvider>(provider);
auto provider = std::shared_ptr<metrics_api::MeterProvider>(new metric_sdk::MeterProvider());
auto p = std::static_pointer_cast<metric_sdk::MeterProvider>(provider);
p->AddMetricReader(std::move(reader));

// counter view
Expand Down
14 changes: 14 additions & 0 deletions examples/prometheus/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cc_binary(
name = "prometheus_example",
srcs = [
"main.cc",
],
linkopts = ["-pthread"],
tags = ["ostream"],
deps = [
"//api",
"//examples/common/metrics_foo_library:common_metrics_foo_library",
"//exporters/prometheus:prometheus_exporter",
"//sdk/src/metrics",
],
)
5 changes: 5 additions & 0 deletions examples/prometheus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_directories(${CMAKE_SOURCE_DIR}/exporters/prometheus/include)
add_executable(prometheus_example main.cc)
target_link_libraries(
prometheus_example ${CMAKE_THREAD_LIBS_INIT} opentelemetry_metrics
prometheus_exporter opentelemetry_resources common_metrics_foo_library)
118 changes: 118 additions & 0 deletions examples/prometheus/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#ifndef ENABLE_METRICS_PREVIEW
# include <memory>
# include <thread>
# include "opentelemetry/exporters/prometheus/exporter.h"
# include "opentelemetry/metrics/provider.h"
# include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h"
# include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h"
# include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h"
# include "opentelemetry/sdk/metrics/meter.h"
# include "opentelemetry/sdk/metrics/meter_provider.h"

# ifdef BAZEL_BUILD
# include "examples/common/metrics_foo_library/foo_library.h"
# else
# include "metrics_foo_library/foo_library.h"
# endif

namespace metrics_sdk = opentelemetry::sdk::metrics;
namespace nostd = opentelemetry::nostd;
namespace common = opentelemetry::common;
namespace metrics_exporter = opentelemetry::exporter::metrics;
namespace metrics_api = opentelemetry::metrics;

namespace
{

void initMetrics(const std::string &name, const std::string &addr)
{
metrics_exporter::PrometheusExporterOptions opts;
if (!addr.empty())
{
opts.url = addr;
}
std::puts("PrometheusExporter example program running ...");

std::unique_ptr<metrics_sdk::MetricExporter> exporter{
new metrics_exporter::PrometheusExporter(opts)};

std::string version{"1.2.0"};
std::string schema{"https://opentelemetry.io/schemas/1.2.0"};

// Initialize and set the global MeterProvider
metrics_sdk::PeriodicExportingMetricReaderOptions options;
options.export_interval_millis = std::chrono::milliseconds(1000);
options.export_timeout_millis = std::chrono::milliseconds(500);
std::unique_ptr<metrics_sdk::MetricReader> reader{
new metrics_sdk::PeriodicExportingMetricReader(std::move(exporter), options)};
auto provider = std::shared_ptr<metrics_api::MeterProvider>(new metrics_sdk::MeterProvider());
auto p = std::static_pointer_cast<metrics_sdk::MeterProvider>(provider);
p->AddMetricReader(std::move(reader));

// counter view
std::string counter_name = name + "_counter";
std::unique_ptr<metrics_sdk::InstrumentSelector> instrument_selector{
new metrics_sdk::InstrumentSelector(metrics_sdk::InstrumentType::kCounter, counter_name)};
std::unique_ptr<metrics_sdk::MeterSelector> meter_selector{
new metrics_sdk::MeterSelector(name, version, schema)};
std::unique_ptr<metrics_sdk::View> sum_view{
new metrics_sdk::View{name, "description", metrics_sdk::AggregationType::kSum}};
p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view));

// histogram view
std::string histogram_name = name + "_histogram";
std::unique_ptr<metrics_sdk::InstrumentSelector> histogram_instrument_selector{
new metrics_sdk::InstrumentSelector(metrics_sdk::InstrumentType::kHistogram, histogram_name)};
std::unique_ptr<metrics_sdk::MeterSelector> histogram_meter_selector{
new metrics_sdk::MeterSelector(name, version, schema)};
std::unique_ptr<metrics_sdk::View> histogram_view{
new metrics_sdk::View{name, "description", metrics_sdk::AggregationType::kHistogram}};
p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector),
std::move(histogram_view));
metrics_api::Provider::SetMeterProvider(provider);
}
} // namespace

int main(int argc, char **argv)
{
std::string example_type;
std::string addr{"localhost:8080"};
if (argc == 1)
{
std::puts("usage: $prometheus_example <example type> <url>");
}

if (argc >= 2)
{
example_type = argv[1];
}
if (argc > 2)
{
addr = argv[2];
}

std::string name{"prometheus_metric_example"};
initMetrics(name, addr);

if (example_type == "counter")
{
foo_library::counter_example(name);
}
else if (example_type == "histogram")
{
foo_library::histogram_example(name);
}
else
{
std::thread counter_example{&foo_library::counter_example, name};
std::thread histogram_example{&foo_library::histogram_example, name};
counter_example.join();
histogram_example.join();
}
}
#else
int main() {}
#endif
16 changes: 16 additions & 0 deletions examples/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
global:
scrape_interval: 5s
scrape_timeout: 2s
evaluation_interval: 5s
alerting:
alertmanagers:
- follow_redirects: true
scheme: http
timeout: 5s
api_version: v2
static_configs:
- targets: [localhost:8080]
scrape_configs:
- job_name: otel
static_configs:
- targets: ['localhost:8080']
1 change: 1 addition & 0 deletions examples/prometheus/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker run -p 9090:9090 -v $(pwd):/etc/prometheus --network="host" prom/prometheus
2 changes: 1 addition & 1 deletion exporters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif()
add_subdirectory(ostream)
add_subdirectory(memory)

if(WITH_PROMETHEUS AND WITH_METRICS_PREVIEW)
if(WITH_PROMETHEUS)
add_subdirectory(prometheus)
endif()

Expand Down
23 changes: 23 additions & 0 deletions exporters/etw/include/opentelemetry/exporters/etw/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TraceLogging Dynamic for Windows

Copyright (c) Microsoft Corporation. All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 9dcaf1a

Please sign in to comment.