forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extensions: add OpenTelemetry tracer extension for exporting OTLP tra…
…ces (envoyproxy#20281) Signed-off-by: Alex Ellis <[email protected]>
- Loading branch information
1 parent
6cc283c
commit f7a8db0
Showing
29 changed files
with
1,669 additions
and
13 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
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,26 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.config.trace.v3; | ||
|
||
import "envoy/config/core/v3/grpc_service.proto"; | ||
|
||
import "udpa/annotations/migrate.proto"; | ||
import "udpa/annotations/status.proto"; | ||
import "udpa/annotations/versioning.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.config.trace.v3"; | ||
option java_outer_classname = "OpentelemetryProto"; | ||
option java_multiple_files = true; | ||
option go_package = "github.com/envoyproxy/go-control-plane/envoy/config/trace/v3;tracev3"; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: OpenTelemetry tracer] | ||
|
||
// Configuration for the OpenTelemetry tracer. | ||
// [#extension: envoy.tracers.opentelemetry] | ||
message OpenTelemetryConfig { | ||
// The upstream gRPC cluster that will receive OTLP traces. | ||
// Note that the tracer drops traces if the server does not read data fast enough. | ||
core.v3.GrpcService grpc_service = 1 [(validate.rules).message = {required: true}]; | ||
} |
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,59 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_extension", | ||
"envoy_cc_library", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
# Trace driver for OpenTelemetry: https://opentelemetry.io/ | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_extension( | ||
name = "config", | ||
srcs = ["config.cc"], | ||
hdrs = ["config.h"], | ||
deps = [ | ||
":opentelemetry_tracer_lib", | ||
"//source/extensions/tracers/common:factory_base_lib", | ||
"@envoy_api//envoy/config/trace/v3:pkg_cc_proto", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "opentelemetry_tracer_lib", | ||
srcs = [ | ||
"opentelemetry_tracer_impl.cc", | ||
"span_context_extractor.cc", | ||
"tracer.cc", | ||
], | ||
hdrs = [ | ||
"opentelemetry_tracer_impl.h", | ||
"span_context.h", | ||
"span_context_extractor.h", | ||
"tracer.h", | ||
], | ||
deps = [ | ||
":grpc_trace_exporter", | ||
"//envoy/thread_local:thread_local_interface", | ||
"//source/common/config:utility_lib", | ||
"//source/common/tracing:http_tracer_lib", | ||
"//source/extensions/tracers/common:factory_base_lib", | ||
"@envoy_api//envoy/config/trace/v3:pkg_cc_proto", | ||
"@opentelemetry_proto//:trace_cc_proto", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "grpc_trace_exporter", | ||
srcs = ["grpc_trace_exporter.cc"], | ||
hdrs = ["grpc_trace_exporter.h"], | ||
deps = [ | ||
"//envoy/grpc:async_client_manager_interface", | ||
"//source/common/grpc:typed_async_client_lib", | ||
"//source/common/protobuf", | ||
"@opentelemetry_proto//:trace_cc_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,32 @@ | ||
#include "source/extensions/tracers/opentelemetry/config.h" | ||
|
||
#include "envoy/config/trace/v3/opentelemetry.pb.h" | ||
#include "envoy/config/trace/v3/opentelemetry.pb.validate.h" | ||
#include "envoy/registry/registry.h" | ||
|
||
#include "source/common/common/logger.h" | ||
#include "source/extensions/tracers/opentelemetry/opentelemetry_tracer_impl.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace OpenTelemetry { | ||
|
||
OpenTelemetryTracerFactory::OpenTelemetryTracerFactory() | ||
: FactoryBase("envoy.tracers.opentelemetry") {} | ||
|
||
Tracing::DriverSharedPtr OpenTelemetryTracerFactory::createTracerDriverTyped( | ||
const envoy::config::trace::v3::OpenTelemetryConfig& proto_config, | ||
Server::Configuration::TracerFactoryContext& context) { | ||
return std::make_shared<Driver>(proto_config, context); | ||
} | ||
|
||
/** | ||
* Static registration for the OpenTelemetry tracer. @see RegisterFactory. | ||
*/ | ||
REGISTER_FACTORY(OpenTelemetryTracerFactory, Server::Configuration::TracerFactory); | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
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 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "envoy/config/trace/v3/opentelemetry.pb.h" | ||
#include "envoy/config/trace/v3/opentelemetry.pb.validate.h" | ||
|
||
#include "source/extensions/tracers/common/factory_base.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace OpenTelemetry { | ||
|
||
/** | ||
* Config registration for the OpenTelemetry tracer. @see TracerFactory. | ||
*/ | ||
class OpenTelemetryTracerFactory | ||
: Logger::Loggable<Logger::Id::tracing>, | ||
public Common::FactoryBase<envoy::config::trace::v3::OpenTelemetryConfig> { | ||
public: | ||
OpenTelemetryTracerFactory(); | ||
|
||
private: | ||
// FactoryBase | ||
Tracing::DriverSharedPtr | ||
createTracerDriverTyped(const envoy::config::trace::v3::OpenTelemetryConfig& proto_config, | ||
Server::Configuration::TracerFactoryContext& context) override; | ||
}; | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
23 changes: 23 additions & 0 deletions
23
source/extensions/tracers/opentelemetry/grpc_trace_exporter.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,23 @@ | ||
#include "grpc_trace_exporter.h" | ||
#include "source/extensions/tracers/opentelemetry/grpc_trace_exporter.h" | ||
|
||
#include "source/common/common/logger.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace OpenTelemetry { | ||
|
||
OpenTelemetryGrpcTraceExporter::OpenTelemetryGrpcTraceExporter( | ||
const Grpc::RawAsyncClientSharedPtr& client) | ||
: client_(client, *Protobuf::DescriptorPool::generated_pool()->FindMethodByName( | ||
"opentelemetry.proto.collector.trace.v1.TraceService.Export")) {} | ||
|
||
bool OpenTelemetryGrpcTraceExporter::log(const ExportTraceServiceRequest& request) { | ||
return client_.log(request); | ||
} | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.