Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
29 changes: 22 additions & 7 deletions agents/grpc/src/grpc_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "absl/log/initialize.h"
#include "opentelemetry/sdk/metrics/data/metric_data.h"
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/sdk/resource/semantic_conventions.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_client.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_client_factory.h"
#include "opentelemetry/exporters/otlp/otlp_grpc_exporter.h"
Expand All @@ -33,6 +34,7 @@ using opentelemetry::sdk::metrics::ResourceMetrics;
using opentelemetry::sdk::metrics::ScopeMetrics;
using opentelemetry::sdk::resource::Resource;
using opentelemetry::sdk::resource::ResourceAttributes;
using opentelemetry::sdk::resource::SemanticConventions::kServiceName;
using opentelemetry::sdk::trace::Recordable;
using opentelemetry::v1::exporter::otlp::OtlpGrpcClient;
using opentelemetry::v1::exporter::otlp::OtlpGrpcClientFactory;
Expand Down Expand Up @@ -292,21 +294,20 @@ void PopulatePackagesEvent(grpcagent::PackagesEvent* packages_event,
return;
}

DebugJSON("Packages Info: \n%s\n", packages);

// Fill in the fields of the InfoResponse.
PopulateCommon(packages_event->mutable_common(), "packages", req_id);

grpcagent::PackagesBody* body = packages_event->mutable_body();
for (const auto& package : packages) {
DebugJSON("Populating Package: \n%s\n", package);
grpcagent::Package* proto_package = body->add_packages();
if (package.contains("path")) {
if (package.contains("path") && package["path"].is_string()) {
proto_package->set_path(package["path"].get<std::string>());
}
if (package.contains("name")) {
if (package.contains("name") && package["name"].is_string()) {
proto_package->set_name(package["name"].get<std::string>());
}
if (package.contains("version")) {
if (package.contains("version") && package["version"].is_string()) {
proto_package->set_version(package["version"].get<std::string>());
}
if (package.contains("main") && package["main"].is_string()) {
Expand All @@ -316,11 +317,13 @@ void PopulatePackagesEvent(grpcagent::PackagesEvent* packages_event,
if (package.contains("dependencies") &&
package["dependencies"].is_array()) {
for (const auto& dep : package["dependencies"]) {
proto_package->add_dependencies(dep.get<std::string>());
if (dep.is_string()) {
proto_package->add_dependencies(dep.get<std::string>());
}
}
}

if (package.contains("required")) {
if (package.contains("required") && package["required"].is_boolean()) {
proto_package->set_required(package["required"].get<bool>());
}
}
Expand Down Expand Up @@ -1109,6 +1112,18 @@ int GrpcAgent::config(const json& config) {
setup_blocked_loop_hooks();
}

if (utils::find_any_fields_in_diff(diff, { "/app" })) {
auto it = config_.find("app");
if (it != config_.end()) {
std::string app_name = it->get<std::string>();
ResourceAttributes attrs = {
{ kServiceName, app_name },
};

USE(otlp::UpdateResource(std::move(attrs)));
}
}

// Configure tracing flags
if (trace_flags_ == 0 ||
utils::find_any_fields_in_diff(diff, tracing_fields)) {
Expand Down
11 changes: 7 additions & 4 deletions agents/grpc/src/grpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ std::shared_ptr<Channel>
std::shared_ptr<Channel> channel;
ChannelArguments grpc_arguments;
// Configure the keepalive of the Client Channel. The keepalive time period is
// set to 20 seconds, with a timeout of 10 seconds. Additionally, pings will
// be sent even if there are no calls in flight on an active connection.
grpc_arguments.SetInt(GRPC_ARG_KEEPALIVE_TIME_MS, 20 * 1000 /*20 sec*/);
grpc_arguments.SetInt(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 10 * 1000 /*10 sec*/);
// set to 30 seconds, with a timeout of 15 seconds. Additionally, pings will
// be sent even if there are no calls nor headers/data in flight on an active
// connection. Important: these settings should match the ones configured
// server-side.
grpc_arguments.SetInt(GRPC_ARG_KEEPALIVE_TIME_MS, 30 * 1000 /* 30 sec*/);
grpc_arguments.SetInt(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 15 * 1000 /* 15 sec*/);
grpc_arguments.SetInt(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1);
grpc_arguments.SetInt(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, 0);
if (!options.use_ssl_credentials) {
channel = CreateCustomChannel(options.endpoint,
InsecureChannelCredentials(),
Expand Down
13 changes: 13 additions & 0 deletions agents/otlp/src/otlp_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace trace = OPENTELEMETRY_NAMESPACE::trace;
namespace resource = sdk::resource;
namespace instrumentationscope = sdk::instrumentationscope;
namespace detail = trace::propagation::detail;
using resource::ResourceAttributes;
using resource::SemanticConventions::kServiceName;
using resource::SemanticConventions::kServiceInstanceId;
using resource::SemanticConventions::kServiceVersion;
Expand Down Expand Up @@ -170,6 +171,18 @@ int OTLPAgent::config(const nlohmann::json& config) {
config_otlp_agent(config_);
}

if (utils::find_any_fields_in_diff(diff, { "/app" })) {
auto it = config_.find("app");
if (it != config_.end()) {
std::string app_name = it->get<std::string>();
ResourceAttributes attrs = {
{ kServiceName, app_name },
};

USE(otlp::UpdateResource(std::move(attrs)));
}
}

// Configure tracing flags
if (span_collector_ == nullptr ||
utils::find_any_fields_in_diff(diff, tracing_fields)) {
Expand Down
3 changes: 2 additions & 1 deletion agents/otlp/src/otlp_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ Resource* UpdateResource(ResourceAttributes&& attrs) {
// value "unknown_service". (See Resource::Create() method in the SDK).
auto resource = GetResource();
auto attributes = resource->GetAttributes();
if (attributes.find(kServiceName) != attributes.end()) {
if (attributes.find(kServiceName) != attributes.end() &&
attrs.find(kServiceName) == attrs.end()) {
attrs.SetAttribute(kServiceName,
std::get<std::string>(attributes[kServiceName]));
}
Expand Down
23 changes: 23 additions & 0 deletions agents/zmq/src/zmq_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ constexpr size_t span_msg_q_min_size = 200;

const char MSG_1[] = "{"
"\"agentId\":\"%s\""
",\"app\":\"%s\""
",\"requestId\": \"%s\""
",\"command\":\"%s\""
",\"recorded\":{\"seconds\":%" PRIu64",\"nanoseconds\":%" PRIu64"}"
Expand All @@ -89,6 +90,7 @@ const char MSG_1[] = "{"

const char MSG_2[] = "{"
"\"agentId\":\"%s\""
",\"app\":\"%s\""
",\"requestId\": null"
",\"command\":\"%s\""
",\"recorded\":{\"seconds\":%" PRIu64",\"nanoseconds\":%" PRIu64"}"
Expand All @@ -100,6 +102,7 @@ const char MSG_2[] = "{"

const char MSG_3[] = "{"
"\"agentId\":\"%s\""
",\"app\":\"%s\""
",\"requestId\": \"%s\""
",\"command\":\"%s\""
",\"duration\":%" PRIu64
Expand All @@ -111,6 +114,7 @@ const char MSG_3[] = "{"

const char MSG_4[] = "{"
"\"agentId\":\"%s\""
",\"app\":\"%s\""
",\"requestId\": \"%s\""
",\"command\":\"%s\""
",\"recorded\":{\"seconds\":%" PRIu64",\"nanoseconds\":%" PRIu64"}"
Expand All @@ -120,13 +124,15 @@ const char MSG_4[] = "{"

const char MSG_5[] = "{"
"\"agentId\":\"%s\""
",\"app\":\"%s\""
",\"recorded\":{\"seconds\":%" PRIu64",\"nanoseconds\":%" PRIu64"}"
",\"version\":%d"
",\"error\":{\"message\":\"%s\",\"code\":%d}"
"}";

const char MSG_6[] = "{"
"\"agentId\":\"%s\""
",\"app\":\"%s\""
",\"command\":\"exit\""
",\"exit_code\":%d"
",\"version\":%d"
Expand All @@ -136,6 +142,7 @@ const char MSG_6[] = "{"

const char MSG_7[] = "{"
"\"agentId\":\"%s\""
",\"app\":\"%s\""
",\"command\":\"exit\""
",\"exit_code\":%d"
",\"version\":%d"
Expand Down Expand Up @@ -1077,6 +1084,7 @@ int ZmqAgent::send_command_message(const char* command,
msg_size_,
MSG_2,
agent_id_.c_str(),
app_name_.c_str(),
command,
std::get<0>(recorded),
std::get<1>(recorded),
Expand All @@ -1090,6 +1098,7 @@ int ZmqAgent::send_command_message(const char* command,
msg_size_,
MSG_1,
agent_id_.c_str(),
app_name_.c_str(),
request_id,
command,
std::get<0>(recorded),
Expand Down Expand Up @@ -1271,6 +1280,13 @@ int ZmqAgent::config(const json& config) {
setup_blocked_loop_hooks();
}

if (utils::find_any_fields_in_diff(diff, { "/app" })) {
auto it = config_.find("app");
if (it != config_.end()) {
app_name_ = it->get<std::string>();
}
}

// Don't config other endpoints if command handle is not to be configured
if (command_handle_ != nullptr) {
if (ZmqHandle::needs_reset(diff, ZmqDataHandle::restart_fields)) {
Expand Down Expand Up @@ -1555,6 +1571,7 @@ void ZmqAgent::send_error_message(const std::string& msg,
msg_size_,
MSG_5,
agent_id_.c_str(),
app_name_.c_str(),
std::get<0>(recorded),
std::get<1>(recorded),
version_,
Expand All @@ -1571,6 +1588,7 @@ void ZmqAgent::send_error_message(const std::string& msg,
msg_size_,
MSG_5,
agent_id_.c_str(),
app_name_.c_str(),
std::get<0>(recorded),
std::get<1>(recorded),
version_,
Expand All @@ -1594,6 +1612,7 @@ int ZmqAgent::send_error_command_message(const std::string& req_id,
msg_size_,
MSG_4,
agent_id_.c_str(),
app_name_.c_str(),
req_id.c_str(),
command.c_str(),
std::get<0>(recorded),
Expand All @@ -1612,6 +1631,7 @@ int ZmqAgent::send_error_command_message(const std::string& req_id,
msg_size_,
MSG_4,
agent_id_.c_str(),
app_name_.c_str(),
req_id.c_str(),
command.c_str(),
std::get<0>(recorded),
Expand Down Expand Up @@ -1664,6 +1684,7 @@ void ZmqAgent::send_exit() {
msg_size_,
MSG_7,
agent_id_.c_str(),
app_name_.c_str(),
exit_code,
version_,
profile);
Expand All @@ -1675,6 +1696,7 @@ void ZmqAgent::send_exit() {
msg_size_,
MSG_6,
agent_id_.c_str(),
app_name_.c_str(),
exit_code,
version_,
jmsg.dump().c_str(),
Expand Down Expand Up @@ -2064,6 +2086,7 @@ void ZmqAgent::do_got_prof(ProfileType type,
msg_size_,
MSG_3,
agent_id_.c_str(),
app_name_.c_str(),
prof_stor.req_id.c_str(),
cmd,
uv_now(&loop_) - prof_stor.timestamp,
Expand Down
1 change: 1 addition & 0 deletions agents/zmq/src/zmq_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ class ZmqAgent {
std::atomic<bool> exiting_;

const std::string agent_id_;
std::string app_name_;

// For Auth
std::string auth_url_;
Expand Down
28 changes: 28 additions & 0 deletions deps/opentelemetry-cpp/.devcontainer/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM otel/cpp_format_tools

ARG GRPC_VERSION=v1.55.0
ARG PROTOBUF_VERSION=23.4
ARG ABSEIL_CPP_VERSION=20240116.1

ENV PROTOBUF_VERSION=${PROTOBUF_VERSION}
ENV ABSEIL_CPP_VERSION=${ABSEIL_CPP_VERSION}

COPY ci /opt/ci

RUN apt update && apt install -y wget \
ninja-build \
libcurl4-openssl-dev \
markdownlint

RUN cd /opt/ci && bash setup_cmake.sh
RUN cd /opt/ci && bash setup_ci_environment.sh
RUN cd /opt && bash ci/setup_googletest.sh \
&& bash ci/setup_grpc.sh -r ${GRPC_VERSION}

ADD https://github.com/bazelbuild/bazelisk/releases/download/v1.22.1/bazelisk-linux-amd64 /usr/local/bin

RUN git config --global core.autocrlf input \
&& chmod +x /usr/local/bin/bazelisk-linux-amd64
26 changes: 26 additions & 0 deletions deps/opentelemetry-cpp/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.162.0/containers/javascript-node
{
"name": "opentelemetry-cpp",
"build": {
"context": "..",
"dockerfile": "Dockerfile.dev",
"args": {
"GRPC_VERSION": "v1.55.0",
"PROTOBUF_VERSION": "23.4",
"ABSEIL_CPP_VERSION":"20240116.1"
}
},
"settings": {
"terminal.integrated.shell.linux": "/bin/sh"
},
"extensions": [
"ms-vscode.cpptools",
"ms-azuretools.vscode-docker",
"ms-vscode.cpptools-extension-pack"
],

"remoteUser": "root"
}
6 changes: 6 additions & 0 deletions deps/opentelemetry-cpp/.iwyu.imp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
[
# Work around for C++ STL
{ "include": ["<bits/chrono.h>", "private", "<chrono>", "public"] },
{ "include": ["<bits/std_abs.h>", "private", "<cstdlib>", "public"] },
{ "include": ["<ext/alloc_traits.h>", "private", "<memory>", "public"] },
{ "include": ["<bits/types/struct_tm.h>", "private", "<time.h>", "public"] },
{ "include": ["<bits/types/struct_FILE.h>", "private", "<stdio.h>", "public"] },

# Local opentelemetry-cpp style

Expand All @@ -14,6 +18,8 @@
{ "include": ["<gtest/gtest-test-part.h>", "private", "<gtest/gtest.h>", "public"] },
{ "include": ["<gtest/gtest-param-test.h>", "private", "<gtest/gtest.h>", "public"] },
{ "include": ["<gtest/gtest_pred_impl.h>", "private", "<gtest/gtest.h>", "public"] },
{ "include": ["<gtest/gtest-typed-test.h>", "private", "<gtest/gtest.h>", "public"] },
{ "include": ["<gtest/gtest-assertion-result.h>", "private", "<gtest/gtest.h>", "public"] },

# We prefer to include <gmock/gmock.h> for simplicity
{ "include": ["<gmock/gmock-function-mocker.h>", "private", "<gmock/gmock.h>", "public"] },
Expand Down
25 changes: 25 additions & 0 deletions deps/opentelemetry-cpp/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

module(
name = "opentelemetry-cpp",
version = "1.17.0",
compatibility_level = 0,
repo_name = "io_opentelemetry_cpp",
)

bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "com_google_absl")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "curl", version = "8.8.0")
bazel_dep(name = "grpc", version = "1.63.1.bcr.1", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "github_nlohmann_json")
bazel_dep(name = "opentelemetry-proto", version = "1.5.0", repo_name = "com_github_opentelemetry_proto")
bazel_dep(name = "opentracing-cpp", version = "1.6.0", repo_name = "com_github_opentracing")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "prometheus-cpp", version = "1.3.0", repo_name = "com_github_jupp0r_prometheus_cpp")
bazel_dep(name = "protobuf", version = "26.0", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "zlib", version = "1.3.1.bcr.1")

bazel_dep(name = "google_benchmark", version = "1.8.3", dev_dependency = True, repo_name = "com_github_google_benchmark")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1", dev_dependency = True, repo_name = "com_google_googletest")
Loading
Loading