Skip to content

Commit

Permalink
formatting, renaming
Browse files Browse the repository at this point in the history
Signed-off-by: thomas.ebner <[email protected]>
  • Loading branch information
samohte committed Oct 19, 2023
1 parent b2a9fc6 commit cd89e8c
Show file tree
Hide file tree
Showing 42 changed files with 1,042 additions and 167 deletions.
16 changes: 1 addition & 15 deletions api/envoy/config/trace/v3/opentelemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ package envoy.config.trace.v3;
import "envoy/config/core/v3/extension.proto";
import "envoy/config/core/v3/grpc_service.proto";

import "google/protobuf/any.proto";

import "udpa/annotations/status.proto";
import "validate/validate.proto";


option java_package = "io.envoyproxy.envoy.config.trace.v3";
option java_outer_classname = "OpentelemetryProto";
Expand All @@ -19,16 +15,6 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: OpenTelemetry tracer]

message Sampler {
// The name of the sampler to instantiate.
string name = 1 [(validate.rules).string = {min_len: 1}];

// Sampler specific configuration which depends on the sampler being
// instantiated. See the supported sampler for further documentation.
// Not required for sampler that don't need a config.
google.protobuf.Any typed_config = 2;
}

// Configuration for the OpenTelemetry tracer.
// [#extension: envoy.tracers.opentelemetry]
message OpenTelemetryConfig {
Expand All @@ -43,5 +29,5 @@ message OpenTelemetryConfig {

// optional sampler which is used in the opentelemetry tracer
// [#extension-category: envoy.tracers.opentelemetry.samplers]
optional core.v3.TypedExtensionConfig sampler = 3;
core.v3.TypedExtensionConfig sampler = 3;
}
2 changes: 2 additions & 0 deletions api/envoy/extensions/tracers/opentelemetry/samplers/v3/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 = "AlwaysOnSamplerConfigProto";
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 = "DynatraceSamplerConfigProto";
option java_outer_classname = "DynatraceSamplerProto";
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;
Expand All @@ -14,4 +14,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// [#extension: envoy.tracers.opentelemetry.samplers.dynatrace]

message DynatraceSamplerConfig {
string tenant_id = 1;

string cluster_id = 2;
}
1 change: 1 addition & 0 deletions api/versioning/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ proto_library(
"//envoy/extensions/stat_sinks/graphite_statsd/v3:pkg",
"//envoy/extensions/stat_sinks/open_telemetry/v3:pkg",
"//envoy/extensions/stat_sinks/wasm/v3:pkg",
"//envoy/extensions/tracers/opentelemetry/samplers/v3:pkg",
"//envoy/extensions/transport_sockets/alts/v3:pkg",
"//envoy/extensions/transport_sockets/http_11_proxy/v3:pkg",
"//envoy/extensions/transport_sockets/internal_upstream/v3:pkg",
Expand Down
10 changes: 10 additions & 0 deletions docs/root/api-v3/config/trace/opentelemetry/samplers.rst
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/*
1 change: 1 addition & 0 deletions docs/root/api-v3/config/trace/trace.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ HTTP tracers
:maxdepth: 2

v3/*
opentelemetry/samplers
4 changes: 2 additions & 2 deletions source/extensions/extensions_build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ EXTENSIONS = {
"envoy.tracers.xray": "//source/extensions/tracers/xray:config",
"envoy.tracers.skywalking": "//source/extensions/tracers/skywalking:config",
"envoy.tracers.opentelemetry": "//source/extensions/tracers/opentelemetry:config",

#
# Sampler
#

"envoy.tracers.opentelemetry.samplers.always_on": "//source/extensions/tracers/opentelemetry/samplers/always_on:config",
"envoy.tracers.opentelemetry.samplers.dynatrace": "//source/extensions/tracers/opentelemetry/samplers/dynatrace:config",

#
# Transport sockets
#
Expand Down
19 changes: 14 additions & 5 deletions source/extensions/extensions_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,20 @@ envoy.tracers.opentelemetry:
status: wip
type_urls:
- envoy.config.trace.v3.OpenTelemetryConfig
envoy.tracers.opentelemetry.samplers.always_on:
categories:
- envoy.tracers.opentelemetry.samplers
security_posture: unknown
status: wip
type_urls:
- envoy.extensions.tracers.opentelemetry.samplers.v3.AlwaysOnSamplerConfig
envoy.tracers.opentelemetry.samplers.dynatrace:
categories:
- envoy.tracers.opentelemetry.samplers
security_posture: unknown
status: wip
type_urls:
- envoy.extensions.tracers.opentelemetry.samplers.v3.DynatraceSamplerConfig
envoy.tracers.skywalking:
categories:
- envoy.tracers
Expand Down Expand Up @@ -1650,8 +1664,3 @@ envoy.config_mux.sotw_grpc_mux_factory:
- envoy.config_mux
security_posture: unknown
status: stable
envoy.tracers.opentelemetry.samplers.all:
categories:
- envoy.tracers.opentelemetry.samplers
security_posture: unknown
status: wip
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,30 @@ Driver::Driver(const envoy::config::trace::v3::OpenTelemetryConfig& opentelemetr
auto sampler_config = opentelemetry_config.sampler();
auto* factory = Envoy::Config::Utility::getFactory<SamplerFactory>(sampler_config);
if (!factory) {
throw EnvoyException(
fmt::format("Sampler factory not found: '{}'", sampler_config.name()));
throw EnvoyException(fmt::format("Sampler factory not found: '{}'", sampler_config.name()));
}
sampler = factory->createSampler(sampler_config.typed_config());
sampler = factory->createSampler(sampler_config.typed_config(), context);
}

tls_slot_ptr_->set([opentelemetry_config, &factory_context, this, sampler](Event::Dispatcher& dispatcher) {
OpenTelemetryGrpcTraceExporterPtr exporter;
if (opentelemetry_config.has_grpc_service()) {
Grpc::AsyncClientFactoryPtr&& factory =
factory_context.clusterManager().grpcAsyncClientManager().factoryForGrpcService(
opentelemetry_config.grpc_service(), factory_context.scope(), true);
const Grpc::RawAsyncClientSharedPtr& async_client_shared_ptr =
factory->createUncachedRawAsyncClient();
exporter = std::make_unique<OpenTelemetryGrpcTraceExporter>(async_client_shared_ptr);
}
tls_slot_ptr_->set(
[opentelemetry_config, &factory_context, this, sampler](Event::Dispatcher& dispatcher) {
OpenTelemetryGrpcTraceExporterPtr exporter;
if (opentelemetry_config.has_grpc_service()) {
Grpc::AsyncClientFactoryPtr&& factory =
factory_context.clusterManager().grpcAsyncClientManager().factoryForGrpcService(
opentelemetry_config.grpc_service(), factory_context.scope(), true);
const Grpc::RawAsyncClientSharedPtr& async_client_shared_ptr =
factory->createUncachedRawAsyncClient();
exporter = std::make_unique<OpenTelemetryGrpcTraceExporter>(async_client_shared_ptr);
}

TracerPtr tracer = std::make_unique<Tracer>(
std::move(exporter), factory_context.timeSource(), factory_context.api().randomGenerator(),
factory_context.runtime(), dispatcher, tracing_stats_, opentelemetry_config.service_name(), sampler);
TracerPtr tracer = std::make_unique<Tracer>(
std::move(exporter), factory_context.timeSource(),
factory_context.api().randomGenerator(), factory_context.runtime(), dispatcher,
tracing_stats_, opentelemetry_config.service_name(), sampler);

return std::make_shared<TlsTracer>(std::move(tracer));
});
return std::make_shared<TlsTracer>(std::move(tracer));
});
}

Tracing::SpanPtr Driver::startSpan(const Tracing::Config& config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
#include "envoy/thread_local/thread_local.h"
#include "envoy/tracing/trace_driver.h"


#include "samplers/sampler.h"

#include "source/common/common/logger.h"
#include "source/common/singleton/const_singleton.h"
#include "source/extensions/tracers/common/factory_base.h"
#include "source/extensions/tracers/opentelemetry/grpc_trace_exporter.h"
#include "source/extensions/tracers/opentelemetry/tracer.h"

#include "samplers/sampler.h"

namespace Envoy {
namespace Extensions {
namespace Tracers {
Expand Down
4 changes: 1 addition & 3 deletions source/extensions/tracers/opentelemetry/samplers/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ envoy_extension_package()
envoy_cc_library(
name = "sampler_lib",
srcs = [

],
hdrs = [
"sampler.h",
Expand All @@ -21,7 +20,6 @@ envoy_cc_library(
"//envoy/server:tracer_config_interface",
"//source/common/common:logger_lib",
"//source/common/config:utility_lib",
"@envoy_api//envoy/config/trace/v3:pkg_cc_proto",
"@opentelemetry_proto//:trace_cc_proto",
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ envoy_cc_library(
hdrs = ["always_on_sampler.h"],
deps = [
"//source/common/config:datasource_lib",
"//source/extensions/tracers/opentelemetry/samplers:sampler_lib",
"//source/extensions/tracers/opentelemetry:opentelemetry_tracer_lib",
"@envoy_api//envoy/extensions/tracers/opentelemetry/samplers/v3:pkg_cc_proto",
"//source/extensions/tracers/opentelemetry/samplers:sampler_lib",
],
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@ namespace Tracers {
namespace OpenTelemetry {

SamplingResult
AlwaysOnSampler::shouldSample(absl::StatusOr<SpanContext>& parent_context,
AlwaysOnSampler::shouldSample(const absl::StatusOr<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::set<SpanContext> /*links*/) {
SamplingResult result;
result.decision = Decision::RECORD_AND_SAMPLE;
if (parent_context.ok()) {
result.trace_state = parent_context.value().tracestate();
result.tracestate = parent_context.value().tracestate();
}
return result;
}

std::string AlwaysOnSampler::getDescription() const {
return "AlwaysOnSampler";
}
std::string AlwaysOnSampler::getDescription() const { return "AlwaysOnSampler"; }

} // namespace OpenTelemetry
} // namespace Tracers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ namespace OpenTelemetry {
class AlwaysOnSampler : public Sampler, Logger::Loggable<Logger::Id::tracing> {
public:
explicit AlwaysOnSampler(const Protobuf::Message& /*config*/) {}
SamplingResult shouldSample(absl::StatusOr<SpanContext>& parent_context,
SamplingResult shouldSample(const absl::StatusOr<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::set<SpanContext> links) override;
const std::map<std::string, std::string>& attributes,
const std::set<SpanContext> links) override;
std::string getDescription() const override;

private:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "config.h"

#include "envoy/server/tracer_config.h"

#include "source/common/config/utility.h"

#include "always_on_sampler.h"
Expand All @@ -9,8 +11,10 @@ namespace Extensions {
namespace Tracers {
namespace OpenTelemetry {

SamplerPtr AlwaysOnSamplerFactory::createSampler(
const Protobuf::Message& config) {
SamplerPtr
AlwaysOnSamplerFactory::createSampler(const Protobuf::Message& config,
Server::Configuration::TracerFactoryContext& context) {
(void)context;
return std::make_shared<AlwaysOnSampler>(config);
}

Expand All @@ -22,4 +26,4 @@ REGISTER_FACTORY(AlwaysOnSamplerFactory, SamplerFactory);
} // namespace OpenTelemetry
} // namespace Tracers
} // namespace Extensions
} // namespace Envoy
} // namespace Envoy
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

#include <string>

#include "source/extensions/tracers/opentelemetry/samplers/sampler.h"

#include "envoy/extensions/tracers/opentelemetry/samplers/v3/always_on_sampler.pb.h"
#include "envoy/registry/registry.h"

#include "source/extensions/tracers/opentelemetry/samplers/sampler.h"

namespace Envoy {
namespace Extensions {
Expand All @@ -22,21 +23,19 @@ class AlwaysOnSamplerFactory : public SamplerFactory {
* @param context
* @return SamplerPtr
*/
SamplerPtr
createSampler(const Protobuf::Message& config) override;
SamplerPtr createSampler(const Protobuf::Message& config,
Server::Configuration::TracerFactoryContext& context) override;

ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return std::make_unique<envoy::extensions::tracers::opentelemetry::samplers::v3::
AlwaysOnSamplerConfig>();
}
std::string name() const override {
return "envoy.tracers.opentelemetry.samplers.always_on";
return std::make_unique<
envoy::extensions::tracers::opentelemetry::samplers::v3::AlwaysOnSamplerConfig>();
}
std::string name() const override { return "envoy.tracers.opentelemetry.samplers.always_on"; }
};

DECLARE_FACTORY(AlwaysOnSamplerFactory);

} // namespace OpenTelemetry
} // namespace Tracers
} // namespace Extensions
} // namespace Envoy
} // namespace Envoy
17 changes: 13 additions & 4 deletions source/extensions/tracers/opentelemetry/samplers/dynatrace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ envoy_cc_extension(

envoy_cc_library(
name = "dynatrace_sampler_lib",
srcs = ["dynatrace_sampler.cc"],
hdrs = ["dynatrace_sampler.h"],
srcs = [
"dynatrace_sampler.cc",
"murmur.cc",
"tracestate.cc",
],
hdrs = [
"dynatrace_sampler.h",
"dynatrace_tracestate.h",
"murmur.h",
"tracestate.h",
],
deps = [
"//source/common/config:datasource_lib",
"//source/extensions/tracers/opentelemetry/samplers:sampler_lib",
"//source/extensions/tracers/opentelemetry:opentelemetry_tracer_lib",
"//source/extensions/tracers/opentelemetry/samplers:sampler_lib",
"@envoy_api//envoy/extensions/tracers/opentelemetry/samplers/v3:pkg_cc_proto",
],
)
)
Loading

0 comments on commit cd89e8c

Please sign in to comment.