forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying samplers for the OpenTelemetry tracer via a new conf…
…iguration. (envoyproxy#30259) Signed-off-by: thomas.ebner <[email protected]> Signed-off-by: Joao Grassi <[email protected]>
- Loading branch information
Showing
28 changed files
with
957 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
||
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_package( | ||
deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
) |
23 changes: 23 additions & 0 deletions
23
api/envoy/extensions/tracers/opentelemetry/samplers/v3/always_on_sampler.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.tracers.opentelemetry.samplers.v3; | ||
|
||
import "udpa/annotations/status.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.tracers.opentelemetry.samplers.v3"; | ||
option java_outer_classname = "AlwaysOnSamplerProto"; | ||
option java_multiple_files = true; | ||
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/tracers/opentelemetry/samplers/v3;samplersv3"; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Always On Sampler config] | ||
// Configuration for the "AlwaysOn" Sampler extension. | ||
// The sampler follows the "AlwaysOn" implementation from the OpenTelemetry | ||
// SDK specification. | ||
// | ||
// See: | ||
// `AlwaysOn sampler specification <https://opentelemetry.io/docs/specs/otel/trace/sdk/#alwayson>`_ | ||
// [#extension: envoy.tracers.opentelemetry.samplers.always_on] | ||
|
||
message AlwaysOnSamplerConfig { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
OpenTelemetry Samplers | ||
====================== | ||
|
||
Samplers that can be configured with the OpenTelemetry Tracer: | ||
|
||
.. toctree:: | ||
:glob: | ||
:maxdepth: 3 | ||
|
||
../../../extensions/tracers/opentelemetry/samplers/v3/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ HTTP tracers | |
|
||
v3/* | ||
opentelemetry/resource_detectors | ||
opentelemetry/samplers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_library( | ||
name = "sampler_lib", | ||
srcs = [ | ||
], | ||
hdrs = [ | ||
"sampler.h", | ||
], | ||
deps = [ | ||
"//envoy/config:typed_config_interface", | ||
"//envoy/server:tracer_config_interface", | ||
"//source/common/common:logger_lib", | ||
"//source/common/config:utility_lib", | ||
"@opentelemetry_proto//:trace_cc_proto", | ||
], | ||
) |
33 changes: 33 additions & 0 deletions
33
source/extensions/tracers/opentelemetry/samplers/always_on/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_extension", | ||
"envoy_cc_library", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_extension( | ||
name = "config", | ||
srcs = ["config.cc"], | ||
hdrs = ["config.h"], | ||
deps = [ | ||
":always_on_sampler_lib", | ||
"//envoy/registry", | ||
"//source/common/config:utility_lib", | ||
"@envoy_api//envoy/extensions/tracers/opentelemetry/samplers/v3:pkg_cc_proto", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "always_on_sampler_lib", | ||
srcs = ["always_on_sampler.cc"], | ||
hdrs = ["always_on_sampler.h"], | ||
deps = [ | ||
"//source/common/config:datasource_lib", | ||
"//source/extensions/tracers/opentelemetry:opentelemetry_tracer_lib", | ||
"//source/extensions/tracers/opentelemetry/samplers:sampler_lib", | ||
], | ||
) |
34 changes: 34 additions & 0 deletions
34
source/extensions/tracers/opentelemetry/samplers/always_on/always_on_sampler.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "source/extensions/tracers/opentelemetry/samplers/always_on/always_on_sampler.h" | ||
|
||
#include <memory> | ||
#include <sstream> | ||
#include <string> | ||
|
||
#include "source/common/config/datasource.h" | ||
#include "source/extensions/tracers/opentelemetry/span_context.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace OpenTelemetry { | ||
|
||
SamplingResult | ||
AlwaysOnSampler::shouldSample(const absl::optional<SpanContext> parent_context, | ||
const std::string& /*trace_id*/, const std::string& /*name*/, | ||
::opentelemetry::proto::trace::v1::Span::SpanKind /*kind*/, | ||
const std::map<std::string, std::string>& /*attributes*/, | ||
const std::vector<SpanContext>& /*links*/) { | ||
SamplingResult result; | ||
result.decision = Decision::RECORD_AND_SAMPLE; | ||
if (parent_context.has_value()) { | ||
result.tracestate = parent_context.value().tracestate(); | ||
} | ||
return result; | ||
} | ||
|
||
std::string AlwaysOnSampler::getDescription() const { return "AlwaysOnSampler"; } | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
38 changes: 38 additions & 0 deletions
38
source/extensions/tracers/opentelemetry/samplers/always_on/always_on_sampler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "envoy/server/factory_context.h" | ||
|
||
#include "source/common/common/logger.h" | ||
#include "source/common/config/datasource.h" | ||
#include "source/extensions/tracers/opentelemetry/samplers/sampler.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace OpenTelemetry { | ||
|
||
/** | ||
* @brief A sampler which samples every span. | ||
* https://opentelemetry.io/docs/specs/otel/trace/sdk/#alwayson | ||
* - Returns RECORD_AND_SAMPLE always. | ||
* - Description MUST be AlwaysOnSampler. | ||
* | ||
*/ | ||
class AlwaysOnSampler : public Sampler, Logger::Loggable<Logger::Id::tracing> { | ||
public: | ||
explicit AlwaysOnSampler(const Protobuf::Message& /*config*/, | ||
Server::Configuration::TracerFactoryContext& /*context*/) {} | ||
SamplingResult shouldSample(const absl::optional<SpanContext> parent_context, | ||
const std::string& trace_id, const std::string& name, | ||
::opentelemetry::proto::trace::v1::Span::SpanKind spankind, | ||
const std::map<std::string, std::string>& attributes, | ||
const std::vector<SpanContext>& links) override; | ||
std::string getDescription() const override; | ||
|
||
private: | ||
}; | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
27 changes: 27 additions & 0 deletions
27
source/extensions/tracers/opentelemetry/samplers/always_on/config.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "source/extensions/tracers/opentelemetry/samplers/always_on/config.h" | ||
|
||
#include "envoy/server/tracer_config.h" | ||
|
||
#include "source/common/config/utility.h" | ||
#include "source/extensions/tracers/opentelemetry/samplers/always_on/always_on_sampler.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace OpenTelemetry { | ||
|
||
SamplerSharedPtr | ||
AlwaysOnSamplerFactory::createSampler(const Protobuf::Message& config, | ||
Server::Configuration::TracerFactoryContext& context) { | ||
return std::make_shared<AlwaysOnSampler>(config, context); | ||
} | ||
|
||
/** | ||
* Static registration for the Env sampler factory. @see RegisterFactory. | ||
*/ | ||
REGISTER_FACTORY(AlwaysOnSamplerFactory, SamplerFactory); | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.