-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from DataDog/willgittoes-dd/b3-headers-flags
Add environment variables for B3 header propagation
- Loading branch information
Showing
9 changed files
with
237 additions
and
67 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
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,57 @@ | ||
#include "tracer_options.h" | ||
|
||
#include <iterator> | ||
#include <sstream> | ||
|
||
namespace ot = opentracing; | ||
|
||
namespace datadog { | ||
namespace opentracing { | ||
|
||
ot::expected<TracerOptions, const char *> applyTracerOptionsFromEnvironment( | ||
const TracerOptions &input) { | ||
TracerOptions opts = input; | ||
|
||
auto agent_host = std::getenv("DD_AGENT_HOST"); | ||
if (agent_host != nullptr && std::strlen(agent_host) > 0) { | ||
opts.agent_host = agent_host; | ||
} | ||
|
||
auto trace_agent_port = std::getenv("DD_TRACE_AGENT_PORT"); | ||
if (trace_agent_port != nullptr && std::strlen(trace_agent_port) > 0) { | ||
try { | ||
opts.agent_port = std::stoi(trace_agent_port); | ||
} catch (const std::invalid_argument &ia) { | ||
return ot::make_unexpected("Value for DD_TRACE_AGENT_PORT is invalid"); | ||
} catch (const std::out_of_range &oor) { | ||
return ot::make_unexpected("Value for DD_TRACE_AGENT_PORT is out of range"); | ||
} | ||
} | ||
|
||
auto extract = std::getenv("DD_PROPAGATION_STYLE_EXTRACT"); | ||
if (extract != nullptr && std::strlen(extract) > 0) { | ||
std::stringstream words{extract}; | ||
auto style_maybe = asPropagationStyle(std::vector<std::string>{ | ||
std::istream_iterator<std::string>{words}, std::istream_iterator<std::string>{}}); | ||
if (!style_maybe) { | ||
return ot::make_unexpected("Value for DD_PROPAGATION_STYLE_EXTRACT is invalid"); | ||
} | ||
opts.extract = style_maybe.value(); | ||
} | ||
|
||
auto inject = std::getenv("DD_PROPAGATION_STYLE_INJECT"); | ||
if (inject != nullptr && std::strlen(inject) > 0) { | ||
std::stringstream words{inject}; | ||
auto style_maybe = asPropagationStyle(std::vector<std::string>{ | ||
std::istream_iterator<std::string>{words}, std::istream_iterator<std::string>{}}); | ||
if (!style_maybe) { | ||
return ot::make_unexpected("Value for DD_PROPAGATION_STYLE_INJECT is invalid"); | ||
} | ||
opts.inject = style_maybe.value(); | ||
} | ||
|
||
return opts; | ||
} | ||
|
||
} // namespace opentracing | ||
} // namespace datadog |
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,36 @@ | ||
#ifndef DD_TRACER_OPTIONS_H | ||
#define DD_TRACER_OPTIONS_H | ||
|
||
#include <datadog/opentracing.h> | ||
#include <opentracing/expected/expected.hpp> | ||
|
||
namespace ot = opentracing; | ||
|
||
namespace datadog { | ||
namespace opentracing { | ||
|
||
template <class Iterable> | ||
ot::expected<std::set<PropagationStyle>> asPropagationStyle(Iterable styles) { | ||
std::set<PropagationStyle> propagation_styles; | ||
for (const std::string& style : styles) { | ||
if (style == "Datadog") { | ||
propagation_styles.insert(PropagationStyle::Datadog); | ||
} else if (style == "B3") { | ||
propagation_styles.insert(PropagationStyle::B3); | ||
} else { | ||
return ot::make_unexpected(std::make_error_code(std::errc::invalid_argument)); | ||
} | ||
} | ||
if (propagation_styles.size() == 0) { | ||
return ot::make_unexpected(std::make_error_code(std::errc::invalid_argument)); | ||
} | ||
return propagation_styles; | ||
}; | ||
|
||
ot::expected<TracerOptions, const char*> applyTracerOptionsFromEnvironment( | ||
const TracerOptions& input); | ||
|
||
} // namespace opentracing | ||
} // namespace datadog | ||
|
||
#endif // DD_TRACER_OPTIONS_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
Oops, something went wrong.