@@ -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
126167Expected<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 ;
0 commit comments