From e30c09952280f9c5b05c137bdc74c327b349fb25 Mon Sep 17 00:00:00 2001 From: dentiny Date: Tue, 4 Mar 2025 23:13:43 +0000 Subject: [PATCH 1/4] checkin opentelemetry sdk Signed-off-by: dentiny --- bazel/ray_deps_setup.bzl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bazel/ray_deps_setup.bzl b/bazel/ray_deps_setup.bzl index 706344abbd327..952cbc855a6c4 100644 --- a/bazel/ray_deps_setup.bzl +++ b/bazel/ray_deps_setup.bzl @@ -216,6 +216,12 @@ def ray_deps_setup(): patch_args = ["-p1"], ) + auto_http_archive( + name = "io_opentelemetry_cpp", + url = "https://github.com/open-telemetry/opentelemetry-cpp/archive/refs/tags/v1.19.0.zip", + sha256 = "8ef0a63f4959d5dfc3d8190d62229ef018ce41eef36e1f3198312d47ab2de05a", + ) + # OpenCensus depends on Abseil so we have to explicitly pull it in. # This is how diamond dependencies are prevented. # From ae7f26ff4c46266e10d9d1e2e9b13e94ca405bab Mon Sep 17 00:00:00 2001 From: dentiny Date: Wed, 5 Mar 2025 00:27:47 +0000 Subject: [PATCH 2/4] add example file Signed-off-by: dentiny --- BUILD.bazel | 9 +++++++ src/ray/stats/opentelemetry_metrics.cc | 34 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/ray/stats/opentelemetry_metrics.cc diff --git a/BUILD.bazel b/BUILD.bazel index a4ac6caa8328e..58794da2c30b4 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -860,6 +860,15 @@ ray_cc_library( ], ) +ray_cc_library( + name = "stats_opentelemetry", + srcs = ["src/ray/stats/opentelemetry_metrics.cc"], + deps = [ + "@io_opentelemetry_cpp//sdk/src/logs:logs", + "@io_opentelemetry_cpp//sdk/src/trace:trace", + ], +) + ray_cc_library( name = "stats_metric", srcs = [ diff --git a/src/ray/stats/opentelemetry_metrics.cc b/src/ray/stats/opentelemetry_metrics.cc new file mode 100644 index 0000000000000..d1e19266de032 --- /dev/null +++ b/src/ray/stats/opentelemetry_metrics.cc @@ -0,0 +1,34 @@ +// TODO(hjiang): This is an example file which demonstrates opentelemetry dependency is +// correct, should be replaced with real metrics exporter implementation. + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/sdk/version/version.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/trace/scope.h" +#include "opentelemetry/trace/tracer.h" +#include "opentelemetry/trace/tracer_provider.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +namespace { +nostd::shared_ptr get_tracer() { + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("foo_library", OPENTELEMETRY_SDK_VERSION); +} + +void f1() { auto scoped_span = trace::Scope(get_tracer()->StartSpan("f1")); } + +void f2() { + auto scoped_span = trace::Scope(get_tracer()->StartSpan("f2")); + + f1(); + f1(); +} +} // namespace + +void foo_library() { + auto scoped_span = trace::Scope(get_tracer()->StartSpan("library")); + + f2(); +} From 04c4c0f92c5efb2cc50a795712487aa7baf3b806 Mon Sep 17 00:00:00 2001 From: dentiny Date: Wed, 5 Mar 2025 00:55:40 +0000 Subject: [PATCH 3/4] copyright Signed-off-by: dentiny --- src/ray/stats/opentelemetry_metrics.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ray/stats/opentelemetry_metrics.cc b/src/ray/stats/opentelemetry_metrics.cc index d1e19266de032..82be819ee1ef4 100644 --- a/src/ray/stats/opentelemetry_metrics.cc +++ b/src/ray/stats/opentelemetry_metrics.cc @@ -1,3 +1,17 @@ +// Copyright 2025 The Ray 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. + // TODO(hjiang): This is an example file which demonstrates opentelemetry dependency is // correct, should be replaced with real metrics exporter implementation. From b9da27f00cfd395ecb3a77df77653efe62f7d4f6 Mon Sep 17 00:00:00 2001 From: dentiny Date: Wed, 5 Mar 2025 01:16:29 +0000 Subject: [PATCH 4/4] Add test to trigger CI Signed-off-by: dentiny --- src/ray/stats/tests/BUILD | 12 ++++++++++++ .../stats/tests/opentelemetry_metrics_test.cc | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/ray/stats/tests/BUILD create mode 100644 src/ray/stats/tests/opentelemetry_metrics_test.cc diff --git a/src/ray/stats/tests/BUILD b/src/ray/stats/tests/BUILD new file mode 100644 index 0000000000000..d2ca19b53bf54 --- /dev/null +++ b/src/ray/stats/tests/BUILD @@ -0,0 +1,12 @@ +load("//bazel:ray.bzl", "ray_cc_test") + +ray_cc_test( + name = "opentelemetry_metrics_test", + size = "small", + srcs = ["opentelemetry_metrics_test.cc"], + tags = ["team:core"], + deps = [ + "//:stats_opentelemetry", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/src/ray/stats/tests/opentelemetry_metrics_test.cc b/src/ray/stats/tests/opentelemetry_metrics_test.cc new file mode 100644 index 0000000000000..4e10430d260c3 --- /dev/null +++ b/src/ray/stats/tests/opentelemetry_metrics_test.cc @@ -0,0 +1,16 @@ +// Copyright 2025 The Ray 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. + +// TODO(hjiang): Just a dummy test used to trigger CI, replace with real implementation +// later.