This is an automated email from the ASF dual-hosted git repository.
kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 8f07c0432f Update otel_tracer plugin (#11873)
8f07c0432f is described below
commit 8f07c0432f32c534c0adb710be32563458056d5b
Author: Kit Chan <[email protected]>
AuthorDate: Mon Dec 9 22:20:03 2024 +0100
Update otel_tracer plugin (#11873)
* update otel_tracer plugin
* fix format
---
cmake/Findopentelemetry.cmake | 4 +++
doc/admin-guide/plugins/otel_tracer.en.rst | 40 +++++++++++-------------
plugins/experimental/otel_tracer/otel_tracer.cc | 31 ++++++++++++++++--
plugins/experimental/otel_tracer/tracer_common.h | 28 ++++++++++++-----
4 files changed, 73 insertions(+), 30 deletions(-)
diff --git a/cmake/Findopentelemetry.cmake b/cmake/Findopentelemetry.cmake
index b3ad49a572..ca48cd8444 100644
--- a/cmake/Findopentelemetry.cmake
+++ b/cmake/Findopentelemetry.cmake
@@ -33,6 +33,8 @@ set(OTEL_LIBS
opentelemetry_exporter_ostream_span
opentelemetry_exporter_otlp_http
opentelemetry_exporter_otlp_http_client
+ opentelemetry_exporter_otlp_http_log
+ opentelemetry_exporter_otlp_http_metric
opentelemetry_http_client_curl
opentelemetry_metrics
opentelemetry_otlp_recordable
@@ -41,6 +43,8 @@ set(OTEL_LIBS
opentelemetry_trace
opentelemetry_version
opentelemetry_common
+ opentelemetry_metrics
+ opentelemetry_logs
)
find_path(opentelemetry_INCLUDE_DIR NAMES opentelemetry/version.h)
diff --git a/doc/admin-guide/plugins/otel_tracer.en.rst
b/doc/admin-guide/plugins/otel_tracer.en.rst
index 6c127775b8..84ceb55aeb 100644
--- a/doc/admin-guide/plugins/otel_tracer.en.rst
+++ b/doc/admin-guide/plugins/otel_tracer.en.rst
@@ -50,28 +50,14 @@ Compiling the Plugin
To compile this plugin, we need nlohmann-json, protobuf and opentelemetry-cpp
-nlohmann-json:
-
-::
-
- cd
- wget https://github.com/nlohmann/json/archive/refs/tags/v3.9.1.tar.gz
- tar zxvf v3.9.1.tar.gz
- cd json-3.9.1
- mkdir build
- cd build
- cmake .. -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON
- make
- make install
-
protobuf:
::
cd
- wget
https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.19.4.tar.gz
- tar zxvf v3.19.4.tar.gz
- cd protobuf-3.19.4
+ wget
https://github.com/protocolbuffers/protobuf/archive/refs/tags/v3.21.12.tar.gz
+ tar zxvf v3.21.12.tar.gz
+ cd protobuf-3.21.12
./autogen.sh
./configure --enable-shared=no --enable-static=yes CXXFLAGS="-std=c++17
-fPIC" CFLAGS="-fPIC"
make
@@ -82,12 +68,12 @@ opentelemetry-cpp
::
cd
- wget
https://github.com/open-telemetry/opentelemetry-cpp/archive/refs/tags/v1.3.0.tar.gz
- tar zxvf v1.3.0.tar.gz
- cd opentelemetry-cpp-1.3.0
+ wget
https://github.com/open-telemetry/opentelemetry-cpp/archive/refs/tags/v1.11.0.tar.gz
+ tar zxvf v1.11.0.tar.gz
+ cd opentelemetry-cpp-1.11.0
mkdir build
cd build
- cmake .. -DBUILD_TESTING=OFF -DWITH_EXAMPLES=OFF -DWITH_JAEGER=OFF
-DWITH_OTLP=ON -DWITH_OTLP_GRPC=OFF -DWITH_OTLP_HTTP=ON
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CXX_STANDARD=17
-DCMAKE_CXX_STANDARD_REQUIRED=ON
+ cmake .. -DBUILD_TESTING=OFF -DWITH_EXAMPLES=OFF -DWITH_JAEGER=OFF
-DWITH_OTLP_GRPC=OFF -DWITH_OTLP_HTTP=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DWITH_ABSEIL=OFF
cmake --build . --target all
cmake --install . --config Debug --prefix /usr/local/
@@ -112,3 +98,15 @@ This is the service name that will be sent as part of the
information to the OTL
* ``-r=[sampling rate]`` (default: ``1.0``)
The value can be between 0.0 to 1.0. It controls the sampling rate of the
trace information.
+
+* ``-q=[queue size]`` (default: ``25``)
+
+The size of the batch processor queue.
+
+* ``-d=[delay]`` (default: ``3000``)
+
+The time interval between two consecutive exports in milliseconds.
+
+* ``-b=[batch size]`` (default: ``10``)
+
+The maximum batch size of every export. Should be smaller than queue size.
diff --git a/plugins/experimental/otel_tracer/otel_tracer.cc
b/plugins/experimental/otel_tracer/otel_tracer.cc
index a46e564a5f..a34ca44443 100644
--- a/plugins/experimental/otel_tracer/otel_tracer.cc
+++ b/plugins/experimental/otel_tracer/otel_tracer.cc
@@ -334,17 +334,23 @@ TSPluginInit(int argc, const char *argv[])
std::string url = "";
std::string service_name = "otel_tracer";
double rate = 1.0;
+ int qsize = 25;
+ int delay = 3000;
+ int bsize = 10;
if (argc > 1) {
int c;
static const struct option longopts[] = {
{const_cast<char *>("url"), required_argument, nullptr, 'u'},
{const_cast<char *>("service-name"), required_argument, nullptr, 's'},
{const_cast<char *>("sampling-rate"), required_argument, nullptr, 'r'},
+ {const_cast<char *>("queue-size"), required_argument, nullptr, 'q'},
+ {const_cast<char *>("delay"), required_argument, nullptr, 'd'},
+ {const_cast<char *>("batch-size"), required_argument, nullptr, 'b'},
{nullptr, 0, nullptr, 0 },
};
int longindex = 0;
- while ((c = getopt_long(argc, const_cast<char *const *>(argv), "u:s:r:",
longopts, &longindex)) != -1) {
+ while ((c = getopt_long(argc, const_cast<char *const *>(argv),
"u:s:r:q:d:b:", longopts, &longindex)) != -1) {
switch (c) {
case 'u':
url = optarg;
@@ -354,13 +360,34 @@ TSPluginInit(int argc, const char *argv[])
break;
case 'r':
rate = atof(optarg);
+ if (rate < 0) {
+ TSEmergency("[otel_tracer][%s] Invalid rate parameter",
__FUNCTION__);
+ }
+ break;
+ case 'q':
+ qsize = atoi(optarg);
+ if (qsize < 0) {
+ TSEmergency("[otel_tracer][%s] Invalid queue size parameter",
__FUNCTION__);
+ }
+ break;
+ case 'd':
+ delay = atoi(optarg);
+ if (delay < 0) {
+ TSEmergency("[otel_tracer][%s] Invalid delay parameter",
__FUNCTION__);
+ }
+ break;
+ case 'b':
+ bsize = atoi(optarg);
+ if (bsize < 0) {
+ TSEmergency("[otel_tracer][%s] Invalid batch size parameter",
__FUNCTION__);
+ }
break;
default:
break;
}
}
}
- InitTracer(url, service_name, rate);
+ InitTracer(url, service_name, rate, qsize, delay, bsize);
if (TSPluginRegister(&info) != TS_SUCCESS) {
TSError("[%s] Plugin registration failed", PLUGIN_NAME);
diff --git a/plugins/experimental/otel_tracer/tracer_common.h
b/plugins/experimental/otel_tracer/tracer_common.h
index dfa19ca0d7..cc88fb124e 100644
--- a/plugins/experimental/otel_tracer/tracer_common.h
+++ b/plugins/experimental/otel_tracer/tracer_common.h
@@ -23,6 +23,7 @@
#include "opentelemetry/exporters/ostream/span_exporter.h"
#include "opentelemetry/sdk/trace/simple_processor.h"
+#include "opentelemetry/sdk/trace/tracer_context.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/trace/provider.h"
@@ -35,6 +36,13 @@
#include "opentelemetry/sdk/trace/samplers/parent.h"
#include "opentelemetry/sdk/trace/samplers/trace_id_ratio.h"
+#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
+#include "opentelemetry/sdk/trace/simple_processor_factory.h"
+#include "opentelemetry/sdk/trace/batch_span_processor_factory.h"
+#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
+#include "opentelemetry/sdk/trace/tracer_context_factory.h"
+#include "opentelemetry/sdk/trace/tracer_provider_factory.h"
+
#include <cstring>
#include <iostream>
#include <vector>
@@ -112,7 +120,7 @@ struct ExtraRequestData {
};
void
-InitTracer(const std::string &url, const std::string &service_name, double
rate)
+InitTracer(const std::string &url, const std::string &service_name, double
rate, int qsize, int delay, int bsize)
{
otlp::OtlpHttpExporterOptions opts;
@@ -120,8 +128,13 @@ InitTracer(const std::string &url, const std::string
&service_name, double rate)
opts.url = url;
}
- auto exporter = std::unique_ptr<sdktrace::SpanExporter>(new
otlp::OtlpHttpExporter(opts));
- auto processor = std::unique_ptr<sdktrace::SpanProcessor>(new
sdktrace::SimpleSpanProcessor(std::move(exporter)));
+ auto exporter = otlp::OtlpHttpExporterFactory::Create(opts);
+
+ sdktrace::BatchSpanProcessorOptions options{};
+ options.max_queue_size = qsize;
+ options.schedule_delay_millis = std::chrono::milliseconds(delay);
+ options.max_export_batch_size = bsize;
+ auto processor =
sdktrace::BatchSpanProcessorFactory::Create(std::move(exporter), options);
std::vector<std::unique_ptr<sdktrace::SpanProcessor>> processors;
processors.push_back(std::move(processor));
@@ -132,11 +145,12 @@ InitTracer(const std::string &url, const std::string
&service_name, double rate)
{"version", (uint32_t)1 }
};
auto resource = opentelemetry::sdk::resource::Resource::Create(attributes);
+ auto context =
sdktrace::TracerContextFactory::Create(std::move(processors), resource,
+
std::unique_ptr<sdktrace::Sampler>(new sdktrace::ParentBasedSampler(
+
std::make_shared<sdktrace::TraceIdRatioBasedSampler>(rate))));
- auto context =
std::make_shared<sdktrace::TracerContext>(std::move(processors), resource,
-
std::unique_ptr<sdktrace::Sampler>(new sdktrace::ParentBasedSampler(
-
std::make_shared<sdktrace::TraceIdRatioBasedSampler>(rate))));
- auto provider = nostd::shared_ptr<trace::TracerProvider>(new
sdktrace::TracerProvider(context));
+ // create provider through factory
+ std::shared_ptr<trace::TracerProvider> provider =
sdktrace::TracerProviderFactory::Create(std::move(context));
// Set the global trace provider
trace::Provider::SetTracerProvider(provider);