@@ -81,6 +81,33 @@ void inject_trace_tags(
8181 }
8282}
8383
84+ void maybe_calculate_http_endpoint (HttpEndpointCalculationMode renaming_mode,
85+ SpanData& local_root) {
86+ // calculate http.endpoint if:
87+ // a) the feature is not disabled, and
88+ // b) the tag http.endpoint is not already set, and
89+ // c) http.url is set, and
90+ // d) http.route is not set or resource_renaming_mode is ALWAYS_CALCULATE
91+ if (renaming_mode == HttpEndpointCalculationMode::DISABLED ||
92+ local_root.tags .find (tags::http_endpoint) != local_root.tags .end ()) {
93+ return ;
94+ }
95+ auto http_url_tag = local_root.tags .find (tags::http_url);
96+ const bool should_calculate_endpoint =
97+ http_url_tag != local_root.tags .end () &&
98+ (renaming_mode == HttpEndpointCalculationMode::ALWAYS_CALCULATE ||
99+ local_root.tags .find (tags::http_route) == local_root.tags .end ());
100+
101+ if (should_calculate_endpoint) {
102+ Expected<HTTPClient::URL> url_result =
103+ HTTPClient::URL::parse (http_url_tag->second );
104+ if (url_result.has_value ()) {
105+ const std::string& path = url_result->path ;
106+ local_root.tags [tags::http_endpoint] =
107+ infer_endpoint (path.empty () ? " /" : path);
108+ }
109+ }
110+ }
84111} // namespace
85112
86113TraceSegment::TraceSegment (
@@ -250,30 +277,7 @@ void TraceSegment::span_finished() {
250277 span.tags [tags::internal::runtime_id] = runtime_id_.string ();
251278 }
252279
253- // calculate http.endpoint if:
254- // a) the feature is not disabled, and
255- // b) the tag http.endpoint is not already set, and
256- // c) http.url is set, and
257- // d) http.route is not set or resource_renaming_mode is ALWAYS_CALCULATE
258- if (resource_renaming_mode_ != HttpEndpointCalculationMode::DISABLED &&
259- local_root.tags .find (tags::http_endpoint) == local_root.tags .end ()) {
260- auto http_url_tag = local_root.tags .find (tags::http_url);
261- const bool should_calculate_endpoint =
262- http_url_tag != local_root.tags .end () &&
263- (resource_renaming_mode_ ==
264- HttpEndpointCalculationMode::ALWAYS_CALCULATE ||
265- local_root.tags .find (tags::http_route) == local_root.tags .end ());
266-
267- if (should_calculate_endpoint) {
268- Expected<HTTPClient::URL> url_result =
269- HTTPClient::URL::parse (http_url_tag->second );
270- if (url_result.has_value ()) {
271- const std::string& path = url_result->path ;
272- local_root.tags [tags::http_endpoint] =
273- infer_endpoint (path.empty () ? " /" : path);
274- }
275- }
276- }
280+ maybe_calculate_http_endpoint (resource_renaming_mode_, local_root);
277281
278282 if (config_manager_->report_traces ()) {
279283 telemetry::distribution::add (metrics::tracer::trace_chunk_size,
0 commit comments