-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opentelemetry tracer: add support for environment resource detector (#…
…29547) Commit Message: Allow specifying resource detectors for the OpenTelemetry tracer via a new configuration resource_detectors. The resource detector reads from the env variable OTEL_RESOURCE_ATTRIBUTES which is defined by the OTel specification. The detector returns a resource object populated with the detected attributes, which is sent as part of the OTLP request. Additional Description: This PR adds the "foundation" for building other resource detectors in Envoy. It is based on the OTel collector implementation. Users can configure multiple resource detectors, and they work together to "merge" all the detected attributes into a single resource object, which is then part of the OTLP message exported. Risk Level: Low Testing: Multiple unit tests, that cover all new code/scenarios. I also did manual testing, running Envoy locally with the OTel tracer + env resource detector enabled. Resource attributes detected from my environment is successfully exported as seen in the Jaeger screenshot. resource-detectors-env-jaeger Docs Changes: Not sure if I should add/where. Happy to do it. Release Notes: N/A Platform Specific Features: N/A [Optional Runtime guard:] N/A [Optional Fixes #28929] Here is how the new config is used: tracing: provider: name: envoy.tracers.opentelemetry typed_config: "@type": type.googleapis.com/envoy.config.trace.v3.OpenTelemetryConfig grpc_service: envoy_grpc: cluster_name: opentelemetry_collector timeout: 0.250s service_name: envoy-gRPC-exporter resource_detectors: # --> NEW CONFIG - name: envoy.tracers.opentelemetry.resource_detectors.environment typed_config: "@type": type.googleapis.com/envoy.extensions.tracers.opentelemetry.resource_detectors.v3.EnvironmentResourceDetectorConfig Signed-off-by: Joao Grassi <[email protected]>
- Loading branch information
1 parent
a3d7440
commit 4eaa1f8
Showing
32 changed files
with
1,233 additions
and
21 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
9 changes: 9 additions & 0 deletions
9
api/envoy/extensions/tracers/opentelemetry/resource_detectors/v3/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,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"], | ||
) |
25 changes: 25 additions & 0 deletions
25
...xtensions/tracers/opentelemetry/resource_detectors/v3/environment_resource_detector.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,25 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.tracers.opentelemetry.resource_detectors.v3; | ||
|
||
import "udpa/annotations/status.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.tracers.opentelemetry.resource_detectors.v3"; | ||
option java_outer_classname = "EnvironmentResourceDetectorProto"; | ||
option java_multiple_files = true; | ||
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/tracers/opentelemetry/resource_detectors/v3;resource_detectorsv3"; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Environment Resource Detector config] | ||
|
||
// Configuration for the Environment Resource detector extension. | ||
// The resource detector reads from the ``OTEL_RESOURCE_ATTRIBUTES`` | ||
// environment variable, as per the OpenTelemetry specification. | ||
// | ||
// See: | ||
// | ||
// `OpenTelemetry specification <https://github.com/open-telemetry/opentelemetry-specification/blob/v1.24.0/specification/resource/sdk.md#detecting-resource-information-from-the-environment>`_ | ||
// | ||
// [#extension: envoy.tracers.opentelemetry.resource_detectors.environment] | ||
message EnvironmentResourceDetectorConfig { | ||
} |
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
10 changes: 10 additions & 0 deletions
10
docs/root/api-v3/config/trace/opentelemetry/resource_detectors.rst
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 Resource Detectors | ||
================================ | ||
|
||
Resource detectors that can be configured with the OpenTelemetry Tracer: | ||
|
||
.. toctree:: | ||
:glob: | ||
:maxdepth: 3 | ||
|
||
../../../extensions/tracers/opentelemetry/resource_detectors/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 |
---|---|---|
|
@@ -12,3 +12,4 @@ HTTP tracers | |
:maxdepth: 2 | ||
|
||
v3/* | ||
opentelemetry/resource_detectors |
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
27 changes: 27 additions & 0 deletions
27
source/extensions/tracers/opentelemetry/resource_detectors/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,27 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_extension_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_extension_package() | ||
|
||
envoy_cc_library( | ||
name = "resource_detector_lib", | ||
srcs = [ | ||
"resource_provider.cc", | ||
], | ||
hdrs = [ | ||
"resource_detector.h", | ||
"resource_provider.h", | ||
], | ||
deps = [ | ||
"//envoy/config:typed_config_interface", | ||
"//envoy/server:tracer_config_interface", | ||
"//source/common/common:logger_lib", | ||
"//source/common/config:utility_lib", | ||
"@envoy_api//envoy/config/trace/v3:pkg_cc_proto", | ||
], | ||
) |
33 changes: 33 additions & 0 deletions
33
source/extensions/tracers/opentelemetry/resource_detectors/environment/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 = [ | ||
":environment_resource_detector_lib", | ||
"//envoy/registry", | ||
"//source/common/config:utility_lib", | ||
"@envoy_api//envoy/extensions/tracers/opentelemetry/resource_detectors/v3:pkg_cc_proto", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "environment_resource_detector_lib", | ||
srcs = ["environment_resource_detector.cc"], | ||
hdrs = ["environment_resource_detector.h"], | ||
deps = [ | ||
"//source/common/config:datasource_lib", | ||
"//source/extensions/tracers/opentelemetry/resource_detectors:resource_detector_lib", | ||
"@envoy_api//envoy/extensions/tracers/opentelemetry/resource_detectors/v3:pkg_cc_proto", | ||
], | ||
) |
35 changes: 35 additions & 0 deletions
35
source/extensions/tracers/opentelemetry/resource_detectors/environment/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,35 @@ | ||
#include "source/extensions/tracers/opentelemetry/resource_detectors/environment/config.h" | ||
|
||
#include "envoy/extensions/tracers/opentelemetry/resource_detectors/v3/environment_resource_detector.pb.h" | ||
#include "envoy/extensions/tracers/opentelemetry/resource_detectors/v3/environment_resource_detector.pb.validate.h" | ||
|
||
#include "source/common/config/utility.h" | ||
#include "source/extensions/tracers/opentelemetry/resource_detectors/environment/environment_resource_detector.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace OpenTelemetry { | ||
|
||
ResourceDetectorPtr EnvironmentResourceDetectorFactory::createResourceDetector( | ||
const Protobuf::Message& message, Server::Configuration::TracerFactoryContext& context) { | ||
|
||
auto mptr = Envoy::Config::Utility::translateAnyToFactoryConfig( | ||
dynamic_cast<const ProtobufWkt::Any&>(message), context.messageValidationVisitor(), *this); | ||
|
||
const auto& proto_config = MessageUtil::downcastAndValidate< | ||
const envoy::extensions::tracers::opentelemetry::resource_detectors::v3:: | ||
EnvironmentResourceDetectorConfig&>(*mptr, context.messageValidationVisitor()); | ||
|
||
return std::make_unique<EnvironmentResourceDetector>(proto_config, context); | ||
} | ||
|
||
/** | ||
* Static registration for the Env resource detector factory. @see RegisterFactory. | ||
*/ | ||
REGISTER_FACTORY(EnvironmentResourceDetectorFactory, ResourceDetectorFactory); | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
46 changes: 46 additions & 0 deletions
46
source/extensions/tracers/opentelemetry/resource_detectors/environment/config.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,46 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "envoy/extensions/tracers/opentelemetry/resource_detectors/v3/environment_resource_detector.pb.h" | ||
|
||
#include "source/extensions/tracers/opentelemetry/resource_detectors/resource_detector.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Tracers { | ||
namespace OpenTelemetry { | ||
|
||
/** | ||
* Config registration for the Environment resource detector. @see ResourceDetectorFactory. | ||
*/ | ||
class EnvironmentResourceDetectorFactory : public ResourceDetectorFactory { | ||
public: | ||
/** | ||
* @brief Create a Resource Detector that reads from the OTEL_RESOURCE_ATTRIBUTES | ||
* environment variable. | ||
* | ||
* @param message The resource detector configuration. | ||
* @param context The tracer factory context. | ||
* @return ResourceDetectorPtr | ||
*/ | ||
ResourceDetectorPtr | ||
createResourceDetector(const Protobuf::Message& message, | ||
Server::Configuration::TracerFactoryContext& context) override; | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override { | ||
return std::make_unique<envoy::extensions::tracers::opentelemetry::resource_detectors::v3:: | ||
EnvironmentResourceDetectorConfig>(); | ||
} | ||
|
||
std::string name() const override { | ||
return "envoy.tracers.opentelemetry.resource_detectors.environment"; | ||
} | ||
}; | ||
|
||
DECLARE_FACTORY(EnvironmentResourceDetectorFactory); | ||
|
||
} // namespace OpenTelemetry | ||
} // namespace Tracers | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.