[otel] Add bazel dependency (#33548)

Add bazel dependency on opentelemetry-cpp.
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/33558/head
Yash Tibrewal 2 years ago committed by GitHub
parent 16a11fadff
commit 875b7fdcff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      bazel/grpc_build_system.bzl
  2. 11
      bazel/grpc_deps.bzl
  3. 38
      test/cpp/ext/filters/otel/BUILD
  4. 46
      test/cpp/ext/filters/otel/otel_plugin_test.cc
  5. 7
      tools/buildgen/extract_metadata_from_bazel_xml.py
  6. 3
      tools/distrib/fix_build_deps.py
  7. 2
      tools/run_tests/sanity/check_bazel_workspace.py

@ -72,6 +72,8 @@ def _get_external_deps(external_deps):
ret.append("@com_google_absl//" + dep)
elif dep.startswith("google/"):
ret.append("@com_google_googleapis//" + dep)
elif dep.startswith("otel/"):
ret.append(dep.replace("otel/", "@io_opentelemetry_cpp//"))
else:
ret.append("//external:" + dep)
return ret

@ -510,6 +510,17 @@ def grpc_deps():
],
)
if "io_opentelemetry_cpp" not in native.existing_rules():
http_archive(
name = "io_opentelemetry_cpp",
sha256 = "668de24f81c8d36d75092ad9dcb02a97cd41473adbe72485ece05e336db48249",
strip_prefix = "opentelemetry-cpp-1.9.1",
urls = [
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/open-telemetry/opentelemetry-cpp/archive/refs/tags/v1.9.1.tar.gz",
"https://github.com/open-telemetry/opentelemetry-cpp/archive/refs/tags/v1.9.1.tar.gz",
],
)
grpc_python_deps()
# TODO: move some dependencies from "grpc_deps" here?

@ -0,0 +1,38 @@
# Copyright 2023 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package")
licenses(["notice"])
grpc_package(
name = "test/cpp/ext/filters/otel",
visibility = "tests",
)
grpc_cc_test(
name = "otel_plugin_test",
srcs = [
"otel_plugin_test.cc",
],
external_deps = [
"gtest",
"otel/api",
"otel/sdk/src/metrics",
],
language = "C++",
tags = [
],
deps = ["//test/core/util:grpc_test_util"],
)

@ -0,0 +1,46 @@
//
//
// Copyright 2023 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#include "api/include/opentelemetry/metrics/provider.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "sdk/include/opentelemetry/sdk/metrics/meter_provider.h"
#include "test/core/util/test_config.h"
namespace grpc {
namespace testing {
namespace {
TEST(OTelPluginTest, ApiDependency) {
opentelemetry::metrics::Provider::GetMeterProvider();
}
TEST(OTelPluginTest, SdkDependency) {
opentelemetry::sdk::metrics::MeterProvider();
}
} // namespace
} // namespace testing
} // namespace grpc
int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(&argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -736,6 +736,13 @@ def _exclude_unwanted_cc_tests(tests: List[str]) -> List[str]:
and not test.startswith("test/cpp/interop:observability_interop")
]
# we have not added otel dependency outside of bazel
tests = [
test
for test in tests
if not test.startswith("test/cpp/ext/filters/otel:")
]
# missing opencensus/stats/stats.h
tests = [
test

@ -93,6 +93,8 @@ EXTERNAL_DEPS = {
"absl/types/variant.h": "absl/types:variant",
"absl/utility/utility.h": "absl/utility",
"address_sorting/address_sorting.h": "address_sorting",
"api/include/opentelemetry/metrics/provider.h": "otel/api",
"sdk/include/opentelemetry/sdk/metrics/meter_provider.h": "otel/sdk/src/metrics",
"ares.h": "cares",
"fuzztest/fuzztest.h": ["fuzztest", "fuzztest_main"],
"google/api/monitored_resource.pb.h": (
@ -379,6 +381,7 @@ for dirname in [
"test/core/promise",
"test/core/resource_quota",
"test/core/transport/chaotic_good",
"test/cpp/ext/filters/otel",
"fuzztest",
"fuzztest/core/channel",
]:

@ -58,6 +58,7 @@ _GRPC_DEP_NAMES = [
"com_google_absl",
"com_google_fuzztest",
"io_opencensus_cpp",
"io_opentelemetry_cpp",
"envoy_api",
_BAZEL_SKYLIB_DEP_NAME,
_BAZEL_TOOLCHAINS_DEP_NAME,
@ -86,6 +87,7 @@ _GRPC_BAZEL_ONLY_DEPS = [
"com_google_absl",
"com_google_fuzztest",
"io_opencensus_cpp",
"io_opentelemetry_cpp",
_BAZEL_SKYLIB_DEP_NAME,
_BAZEL_TOOLCHAINS_DEP_NAME,
_BAZEL_COMPDB_DEP_NAME,

Loading…
Cancel
Save