Skip to content

Commit accbb7e

Browse files
committed
add new env vars (without using them), and refactor propagation style parsing
1 parent 39a6dd0 commit accbb7e

File tree

3 files changed

+52
-38
lines changed

3 files changed

+52
-38
lines changed

src/datadog/environment.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ namespace environment {
2929
MACRO(DD_ENV) \
3030
MACRO(DD_PROPAGATION_STYLE_EXTRACT) \
3131
MACRO(DD_PROPAGATION_STYLE_INJECT) \
32+
MACRO(DD_TRACE_PROPAGATION_STYLE_EXTRACT) \
33+
MACRO(DD_TRACE_PROPAGATION_STYLE_INJECT) \
34+
MACRO(DD_TRACE_PROPAGATION_STYLE) \
3235
MACRO(DD_SERVICE) \
3336
MACRO(DD_SPAN_SAMPLING_RULES) \
3437
MACRO(DD_SPAN_SAMPLING_RULES_FILE) \

src/datadog/tracer_config.cpp

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,47 @@ Expected<std::unordered_map<std::string, std::string>> parse_tags(
121121
return tags;
122122
}
123123

124+
Expected<void> finalize_propagation_styles(FinalizedTracerConfig &result,
125+
const TracerConfig &config) {
126+
result.extraction_styles = config.extraction_styles;
127+
if (auto styles_env = lookup(environment::DD_PROPAGATION_STYLE_EXTRACT)) {
128+
auto styles = parse_propagation_styles(*styles_env);
129+
if (auto *error = styles.if_error()) {
130+
std::string prefix;
131+
prefix += "Unable to parse ";
132+
append(prefix, name(environment::DD_PROPAGATION_STYLE_EXTRACT));
133+
prefix += " environment variable: ";
134+
return error->with_prefix(prefix);
135+
}
136+
result.extraction_styles = *styles;
137+
}
138+
139+
result.injection_styles = config.injection_styles;
140+
if (auto styles_env = lookup(environment::DD_PROPAGATION_STYLE_INJECT)) {
141+
auto styles = parse_propagation_styles(*styles_env);
142+
if (auto *error = styles.if_error()) {
143+
std::string prefix;
144+
prefix += "Unable to parse ";
145+
append(prefix, name(environment::DD_PROPAGATION_STYLE_INJECT));
146+
prefix += " environment variable: ";
147+
return error->with_prefix(prefix);
148+
}
149+
result.injection_styles = *styles;
150+
}
151+
152+
if (!result.extraction_styles.datadog && !result.extraction_styles.b3 &&
153+
!result.extraction_styles.none) {
154+
return Error{Error::MISSING_SPAN_EXTRACTION_STYLE,
155+
"At least one extraction style must be specified."};
156+
} else if (!result.injection_styles.datadog && !result.injection_styles.b3 &&
157+
!result.injection_styles.none) {
158+
return Error{Error::MISSING_SPAN_INJECTION_STYLE,
159+
"At least one injection style must be specified."};
160+
}
161+
162+
return {};
163+
}
164+
124165
} // namespace
125166

126167
Expected<FinalizedTracerConfig> finalize_config(const TracerConfig &config) {
@@ -195,40 +236,9 @@ Expected<FinalizedTracerConfig> finalize_config(const TracerConfig &config) {
195236
return std::move(span_sampler_config.error());
196237
}
197238

198-
result.extraction_styles = config.extraction_styles;
199-
if (auto styles_env = lookup(environment::DD_PROPAGATION_STYLE_EXTRACT)) {
200-
auto styles = parse_propagation_styles(*styles_env);
201-
if (auto *error = styles.if_error()) {
202-
std::string prefix;
203-
prefix += "Unable to parse ";
204-
append(prefix, name(environment::DD_PROPAGATION_STYLE_EXTRACT));
205-
prefix += " environment variable: ";
206-
return error->with_prefix(prefix);
207-
}
208-
result.extraction_styles = *styles;
209-
}
210-
211-
result.injection_styles = config.injection_styles;
212-
if (auto styles_env = lookup(environment::DD_PROPAGATION_STYLE_INJECT)) {
213-
auto styles = parse_propagation_styles(*styles_env);
214-
if (auto *error = styles.if_error()) {
215-
std::string prefix;
216-
prefix += "Unable to parse ";
217-
append(prefix, name(environment::DD_PROPAGATION_STYLE_INJECT));
218-
prefix += " environment variable: ";
219-
return error->with_prefix(prefix);
220-
}
221-
result.injection_styles = *styles;
222-
}
223-
224-
if (!result.extraction_styles.datadog && !result.extraction_styles.b3 &&
225-
!result.extraction_styles.none) {
226-
return Error{Error::MISSING_SPAN_EXTRACTION_STYLE,
227-
"At least one extraction style must be specified."};
228-
} else if (!result.injection_styles.datadog && !result.injection_styles.b3 &&
229-
!result.injection_styles.none) {
230-
return Error{Error::MISSING_SPAN_INJECTION_STYLE,
231-
"At least one injection style must be specified."};
239+
auto maybe_error = finalize_propagation_styles(result, config);
240+
if (!maybe_error) {
241+
return maybe_error.error();
232242
}
233243

234244
result.report_hostname = config.report_hostname;

src/datadog/tracer_config.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ struct TracerConfig {
5959

6060
// `injection_styles` indicates with which tracing systems trace propagation
6161
// will be compatible when injecting (sending) trace context.
62-
// `injection_styles` is overridden by the `DD_PROPAGATION_STYLE_INJECT`
63-
// environment variable.
62+
// `injection_styles` is overridden by the `DD_TRACE_PROPAGATION_STYLE_INJECT`
63+
// and `DD_TRACE_PROPAGATION_STYLE` environment variables.
6464
PropagationStyles injection_styles;
6565

6666
// `extraction_styles` indicates with which tracing systems trace propagation
6767
// will be compatible when extracting (receiving) trace context.
68-
// `extraction_styles` is overridden by the `DD_PROPAGATION_STYLE_EXTRACT`
69-
// environment variable.
68+
// `extraction_styles` is overridden by the
69+
// `DD_TRACE_PROPAGATION_STYLE_EXTRACT` and `DD_TRACE_PROPAGATION_STYLE`
70+
// environment variables.
7071
PropagationStyles extraction_styles;
7172

7273
// `report_hostname` indicates whether the tracer will include the result of

0 commit comments

Comments
 (0)