-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
tracing: Support dynamically loading tracing libraries. #2252
Merged
Merged
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
3dfbfbc
Support dynamically loading tracing libraries.
rnburn 4aa5578
Add v2 configuration support for dynamically loaded tracers.
rnburn 3473a7d
Don't change v1 configuration.
rnburn c1ad0d3
Merge branch 'master' of https://github.com/envoyproxy/envoy into dyn…
rnburn 5810042
s/DYNAMIC/DYNAMIC_OT/
rnburn a8a1dad
Update opentracing-cpp dependency.
rnburn d0d9a12
Switch to use inline tracer configuration.
rnburn 4b538a3
Add dynamic tracer tests.
rnburn c0b0595
Fix mocktracer dependencies.
rnburn b679ae0
Merge branch 'master' of https://github.com/envoyproxy/envoy into dyn…
rnburn 538582e
Suppress false positive from undefined behavior sanitizer.
rnburn db7de0d
Merge branch 'master' of https://github.com/envoyproxy/envoy into dyn…
rnburn 0a46919
Remove code to find mocktracer library.
rnburn 41555a1
Add test coverage that creates spans with the mocktracer.
rnburn af4344b
Fix prototypes.
rnburn caa2205
Const correctness.
rnburn e3bb7f5
Modify mocktracer's json format.
rnburn 88c1deb
Merge branch 'master' of https://github.com/envoyproxy/envoy into dyn…
rnburn 61264a9
Fix commit hashes.
rnburn 3ede32e
Use std::make_unique.
rnburn 3474e39
Update opentracing-cpp.
rnburn 3f80927
Make requiresClusterName const.
rnburn b0d1890
Add missing test coverage.
rnburn e758593
Add release notes.
rnburn ebefe2f
Fix coverage.
rnburn d9e9a18
Fix formatting of error messages.
rnburn 899ce3f
Point back to opentracing-cpp's main repository.
rnburn b6ca9ca
Merge branch 'master' of https://github.com/envoyproxy/envoy into dyn…
rnburn ace09fb
Fix format.
rnburn 8dd4318
Add TODO note for example.
rnburn 21c9d67
Add test coverage for setTag.
rnburn 4567d6f
Add test coverage for LightStepLogger.
rnburn 1b491d9
Move method to cc file.
rnburn 8f7fa81
Fix typo.
rnburn 5f2d430
Fix tests for lightstep_tracer_impl.
rnburn f1a158c
Fix build.
rnburn 6878e86
Add missing test coverage.
rnburn fca28e5
Merge branch 'master' of https://github.com/envoyproxy/envoy into dyn…
rnburn 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 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,38 @@ | ||
#include "common/tracing/dynamic_opentracing_driver_impl.h" | ||
|
||
#include "common/common/assert.h" | ||
|
||
namespace Envoy { | ||
namespace Tracing { | ||
|
||
DynamicOpenTracingDriver::DynamicOpenTracingDriver(Stats::Store& stats, const std::string& library, | ||
const std::string& tracer_config) | ||
: OpenTracingDriver{stats} { | ||
std::string error_message; | ||
opentracing::expected<opentracing::DynamicTracingLibraryHandle> library_handle_maybe = | ||
opentracing::DynamicallyLoadTracingLibrary(library.c_str(), error_message); | ||
if (!library_handle_maybe) { | ||
throw EnvoyException{formatErrorMessage(library_handle_maybe.error(), error_message)}; | ||
} | ||
library_handle_ = std::move(*library_handle_maybe); | ||
|
||
opentracing::expected<std::shared_ptr<opentracing::Tracer>> tracer_maybe = | ||
library_handle_.tracer_factory().MakeTracer(tracer_config.c_str(), error_message); | ||
if (!tracer_maybe) { | ||
throw EnvoyException{formatErrorMessage(tracer_maybe.error(), error_message)}; | ||
} | ||
tracer_ = std::move(*tracer_maybe); | ||
RELEASE_ASSERT(tracer_ != nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this |
||
} | ||
|
||
std::string DynamicOpenTracingDriver::formatErrorMessage(std::error_code error_code, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be in the anonymous namespace, it's not using any state from the instance. |
||
const std::string& error_message) { | ||
if (error_message.empty()) { | ||
return fmt::format("{}", error_code.message()); | ||
} else { | ||
return fmt::format("{}: {}", error_code.message(), error_message); | ||
} | ||
} | ||
|
||
} // namespace Tracing | ||
} // 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,41 @@ | ||
#pragma once | ||
|
||
#include "envoy/runtime/runtime.h" | ||
#include "envoy/thread_local/thread_local.h" | ||
#include "envoy/tracing/http_tracer.h" | ||
#include "envoy/upstream/cluster_manager.h" | ||
|
||
#include "common/tracing/opentracing_driver_impl.h" | ||
|
||
#include "opentracing/dynamic_load.h" | ||
|
||
namespace Envoy { | ||
namespace Tracing { | ||
|
||
/** | ||
* This driver provides support for dynamically loading tracing libraries into Envoy that provide an | ||
* implementation of the OpenTracing API (see https://github.com/opentracing/opentracing-cpp). | ||
* TODO(rnburn): Add an example showing how to use a tracer library with this driver. | ||
*/ | ||
class DynamicOpenTracingDriver : public OpenTracingDriver { | ||
public: | ||
DynamicOpenTracingDriver(Stats::Store& stats, const std::string& library, | ||
const std::string& tracer_config); | ||
|
||
static std::string formatErrorMessage(std::error_code error_code, | ||
const std::string& error_message); | ||
|
||
// Tracer::OpenTracingDriver | ||
opentracing::Tracer& tracer() override { return *tracer_; } | ||
|
||
PropagationMode propagationMode() const override { | ||
return OpenTracingDriver::PropagationMode::TracerNative; | ||
} | ||
|
||
private: | ||
opentracing::DynamicTracingLibraryHandle library_handle_; | ||
std::shared_ptr<opentracing::Tracer> tracer_; | ||
}; | ||
|
||
} // namespace Tracing | ||
} // 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
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
37 changes: 37 additions & 0 deletions
37
source/server/config/http/dynamic_opentracing_http_tracer.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,37 @@ | ||
#include "server/config/http/dynamic_opentracing_http_tracer.h" | ||
|
||
#include <string> | ||
|
||
#include "envoy/registry/registry.h" | ||
|
||
#include "common/common/utility.h" | ||
#include "common/config/well_known_names.h" | ||
#include "common/tracing/dynamic_opentracing_driver_impl.h" | ||
#include "common/tracing/http_tracer_impl.h" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
namespace Configuration { | ||
|
||
Tracing::HttpTracerPtr DynamicOpenTracingHttpTracerFactory::createHttpTracer( | ||
const Json::Object& json_config, Server::Instance& server, | ||
Upstream::ClusterManager& /*cluster_manager*/) { | ||
const std::string library = json_config.getString("library"); | ||
const std::string config = json_config.getObject("config")->asJsonString(); | ||
Tracing::DriverPtr dynamic_driver{ | ||
std::make_unique<Tracing::DynamicOpenTracingDriver>(server.stats(), library, config)}; | ||
return std::make_unique<Tracing::HttpTracerImpl>(std::move(dynamic_driver), server.localInfo()); | ||
} | ||
|
||
std::string DynamicOpenTracingHttpTracerFactory::name() { | ||
return Config::HttpTracerNames::get().DYNAMIC_OT; | ||
} | ||
|
||
/** | ||
* Static registration for the dynamic opentracing http tracer. @see RegisterFactory. | ||
*/ | ||
static Registry::RegisterFactory<DynamicOpenTracingHttpTracerFactory, HttpTracerFactory> register_; | ||
|
||
} // namespace Configuration | ||
} // namespace Server | ||
} // namespace Envoy |
29 changes: 29 additions & 0 deletions
29
source/server/config/http/dynamic_opentracing_http_tracer.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,29 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "envoy/server/instance.h" | ||
|
||
#include "server/configuration_impl.h" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
namespace Configuration { | ||
|
||
/** | ||
* Config registration for the dynamic opentracing tracer. @see HttpTracerFactory. | ||
*/ | ||
class DynamicOpenTracingHttpTracerFactory : public HttpTracerFactory { | ||
public: | ||
// HttpTracerFactory | ||
Tracing::HttpTracerPtr createHttpTracer(const Json::Object& json_config, Server::Instance& server, | ||
Upstream::ClusterManager& cluster_manager) override; | ||
|
||
std::string name() override; | ||
|
||
bool requiresClusterName() const override { return false; } | ||
}; | ||
|
||
} // namespace Configuration | ||
} // namespace Server | ||
} // 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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nit: FYI, most of Envoy doesn't use brace style when calling super.