diff --git a/.bazelignore b/.bazelignore index 56306fc4b9..c6cb4a3b46 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1,3 +1,4 @@ third_party tools out +examples/e2e diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a692615fe..9c451ba2e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -434,6 +434,27 @@ jobs: - name: run tests run: ./ci/do_ci.sh bazel.tsan + bazel_e2e: + name: Bazel e2e gRPC C++11 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: Mount Bazel Cache + uses: actions/cache@v3 + env: + cache-name: bazel_cache + with: + path: /home/runner/.cache/bazel + key: bazel_tsan + - name: setup + run: | + sudo ./ci/setup_ci_environment.sh + sudo ./ci/install_bazelisk.sh + - name: run tests + run: ./ci/do_ci.sh bazel.e2e + bazel_osx: name: Bazel on MacOS runs-on: macos-latest diff --git a/.gitignore b/.gitignore index 87d2de3921..ebae3cf673 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,5 @@ tags .cache/clangd/* + +e2e/bazel-* diff --git a/examples/e2e/.bazelrc b/examples/e2e/.bazelrc new file mode 100644 index 0000000000..d227eb6c31 --- /dev/null +++ b/examples/e2e/.bazelrc @@ -0,0 +1,5 @@ +# bazelrc file + +build --cxxopt='-std=c++11' +build --action_env=GRPC_BAZEL_RUNTIME=1 +build --define=use_fast_cpp_protos=true diff --git a/examples/e2e/BUILD b/examples/e2e/BUILD new file mode 100644 index 0000000000..a1a6a3ce38 --- /dev/null +++ b/examples/e2e/BUILD @@ -0,0 +1,12 @@ +cc_binary( + name = "e2e_example_otlp_grpc", + srcs = [ + "grpc_main.cc", + ], + deps = [ + "@io_opentelemetry_cpp//api", + "@io_opentelemetry_cpp//examples/common/foo_library:common_foo_library", + "@io_opentelemetry_cpp//exporters/otlp:otlp_grpc_exporter", + "@io_opentelemetry_cpp//sdk/src/trace", + ], +) diff --git a/examples/e2e/WORKSPACE b/examples/e2e/WORKSPACE new file mode 100644 index 0000000000..d478e0b51d --- /dev/null +++ b/examples/e2e/WORKSPACE @@ -0,0 +1,34 @@ +workspace(name = "otel_e2e") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "io_opentelemetry_cpp", + repo_mapping = { + "@com_github_grpc_grpc": "@com_github_grpc_grpc_latest11", + }, + strip_prefix = "opentelemetry-cpp-grpc_e2e", + urls = [ + "https://github.com/esigo/opentelemetry-cpp/archive/grpc_e2e.zip", + ], +) + +# Load OpenTelemetry dependencies after load. +load("@io_opentelemetry_cpp//bazel:repository.bzl", "opentelemetry_cpp_deps") + +opentelemetry_cpp_deps() + +# Load gRPC dependencies after load. +load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") + +grpc_deps() + +# Load extra gRPC dependencies due to https://github.com/grpc/grpc/issues/20511 +load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") + +grpc_extra_deps() + +load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library") +load("@upb//bazel:workspace_deps.bzl", "upb_deps") + +upb_deps() diff --git a/examples/e2e/grpc_main.cc b/examples/e2e/grpc_main.cc new file mode 100644 index 0000000000..7d3dd3e4a8 --- /dev/null +++ b/examples/e2e/grpc_main.cc @@ -0,0 +1,50 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_provider_factory.h" +#include "opentelemetry/trace/provider.h" + +#ifdef BAZEL_BUILD +# include "examples/common/foo_library/foo_library.h" +#else +# include "foo_library/foo_library.h" +#endif + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; +namespace trace_sdk = opentelemetry::sdk::trace; +namespace otlp = opentelemetry::exporter::otlp; + +namespace +{ +opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; +void InitTracer() +{ + // Create OTLP exporter instance + auto exporter = otlp::OtlpGrpcExporterFactory::Create(opts); + auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); + std::shared_ptr provider = + trace_sdk::TracerProviderFactory::Create(std::move(processor)); + // Set the global trace provider + trace::Provider::SetTracerProvider(provider); +} +} // namespace + +int main(int argc, char *argv[]) +{ + if (argc > 1) + { + opts.endpoint = argv[1]; + if (argc > 2) + { + opts.use_ssl_credentials = true; + opts.ssl_credentials_cacert_path = argv[2]; + } + } + // Removing this line will leave the default noop TracerProvider in place. + InitTracer(); + + foo_library(); +}