forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
add sampler interface and AlwaysOnSampler #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2499ea1
add sampler interface and AlwaysOnSampler
samohte e0f41ba
review feedback: mainly docs, new lines
samohte 4d17c89
remove optional, run proto_format script, change extension name in e…
samohte 806b9f5
remove redundant setSampled(), already called in startSpan
samohte 713498a
change datatype from set to vector
samohte 0905147
extract sampler creation to tryCreateSamper
samohte 99c14e8
turn callSampler into a free function (not a member of Tracer)
samohte 6969f55
change shouldSample(): absl::StatusOr -> absl::optional
samohte 226cc78
tracer: do not call setSampled() if a tracer is set
samohte cdc8c58
fix spell check findings.
samohte 3500d48
modify rst files, doc build works now
samohte 7b8c758
Enforce line break in rendered docu
samohte 156500d
fix wording
samohte 6942e4f
add title to Always On Sampler config
samohte f7950e9
Add comment to tests
samohte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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") | ||
|
samohte marked this conversation as resolved.
|
||
|
|
||
| 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ HTTP tracers | |
| :maxdepth: 2 | ||
|
|
||
| v3/* | ||
| opentelemetry/samplers | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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", | ||
|
samohte marked this conversation as resolved.
|
||
| ], | ||
| ) | ||
34 changes: 34 additions & 0 deletions
34
source/extensions/tracers/opentelemetry/samplers/always_on/always_on_sampler.cc
This file contains hidden or 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 | ||
|
samohte marked this conversation as resolved.
|
||
| 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 hidden or 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 | ||
|
samohte marked this conversation as resolved.
|
||
| * - 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 hidden or 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); | ||
|
joaopgrassi marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.