-
Notifications
You must be signed in to change notification settings - Fork 5.3k
opentelemetry tracer: add support for environment resource detector #29547
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
Merged
RyanTheOptimist
merged 44 commits into
envoyproxy:main
from
dynatrace-oss-contrib:feat/otel-resource-detectors-env
Oct 27, 2023
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
808577f
Add resource detector extension
joaopgrassi 8c2fdc4
Use detectors to build the OTel resource
joaopgrassi 197942d
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi 277d9ce
Refactor to use core.v3.TypedExtensionConfig
joaopgrassi 995c4b6
Refactor to use core.v3.TypedExtensionConfig - fix unit tests
joaopgrassi 687a0f7
Manually add res detectors proto package to build file
joaopgrassi 40c4373
PR suggestions
joaopgrassi e3b92cb
Reduce scope of try-catch to minimum
joaopgrassi 0febb7c
Avoid copying the resource to all threads/tracers
joaopgrassi a340411
Fix format issues
joaopgrassi ae8b16a
Fix spelling mistakes and add OTEL to dictionary
joaopgrassi a8bf06b
Fix proto lint issues
joaopgrassi 62365cf
Refactor passing resource provider to Driver
joaopgrassi 0183959
Add docs
joaopgrassi 3144798
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi 7a8ae5a
Fix doc lint
joaopgrassi e2de7aa
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi 23e7b2b
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi c71695b
Fix imports
joaopgrassi ca96947
Fix pointers
joaopgrassi 96d2bc6
adapt env var parsing
joaopgrassi 1690cdd
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi 512e692
Set schema url regardless of resource being empty or not
joaopgrassi d79e015
PR suggestions
joaopgrassi 04e0480
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi bed0ab8
Add comments to tests
joaopgrassi a5923fc
Fix lint issues
joaopgrassi e1c31c9
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi 5dbb2ea
Add changelog
joaopgrassi b6171be
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi d20885e
Prevent start up when failing to detect resource from the environment
joaopgrassi 8c79eaa
Remove left over todo
joaopgrassi 4dfa9d5
Fix proto docs
joaopgrassi 8835647
Improve test env var cleanup
joaopgrassi 7cdfe98
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi c7b38b5
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi a374106
Add docs to resource struct
joaopgrassi 4d2fa4a
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi 6efb398
Fix spelling
joaopgrassi 0020e55
Merge branch 'main' into feat/otel-resource-detectors-env
joaopgrassi e678e48
Use cleanup class to clean up env variables after each test
joaopgrassi dcb52f8
Handle empty env var on windows
joaopgrassi f278a46
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi f43274e
Merge remote-tracking branch 'upstream/main' into feat/otel-resource-…
joaopgrassi 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
9 changes: 9 additions & 0 deletions
9
api/envoy/extensions/tracers/opentelemetry/resource_detectors/v3/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,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 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 @@ | ||
| 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. | ||
joaopgrassi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // | ||
| // 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 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
10 changes: 10 additions & 0 deletions
10
docs/root/api-v3/config/trace/opentelemetry/resource_detectors.rst
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 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 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/resource_detectors | ||
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
27 changes: 27 additions & 0 deletions
27
source/extensions/tracers/opentelemetry/resource_detectors/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,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 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( | ||
joaopgrassi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "//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 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,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( | ||
joaopgrassi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 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,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.
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.