1- package datadog .trace .common . metrics ;
1+ package datadog .trace .core . tagprocessor ;
22
33import static datadog .trace .bootstrap .instrumentation .api .Tags .HTTP_ENDPOINT ;
44import static datadog .trace .bootstrap .instrumentation .api .Tags .HTTP_ROUTE ;
55import static datadog .trace .bootstrap .instrumentation .api .Tags .HTTP_URL ;
66
7+ import datadog .trace .api .Config ;
78import datadog .trace .core .CoreSpan ;
9+ import datadog .trace .core .DDSpanContext ;
810import java .util .ArrayList ;
911import java .util .List ;
12+ import java .util .regex .Matcher ;
1013import java .util .regex .Pattern ;
1114import org .slf4j .Logger ;
1215import org .slf4j .LoggerFactory ;
1316
1417/**
1518 * Utility class for HTTP endpoint tagging logic. Handles route eligibility checks and URL path
16- * parameterization for trace metrics .
19+ * parameterization for spans .
1720 *
1821 * <p>This implementation ensures: 1. Only applies to HTTP service entry spans (server spans) 2.
1922 * Limits cardinality through URL path parameterization 3. Uses http.route when available and
@@ -48,12 +51,16 @@ private HttpEndpointTagging() {
4851 * @return true if route is eligible, false otherwise
4952 */
5053 public static boolean isRouteEligible (String route ) {
51- if (route == null || route . trim (). isEmpty () ) {
54+ if (route == null ) {
5255 return false ;
5356 }
5457
5558 route = route .trim ();
5659
60+ if (route .isEmpty ()) {
61+ return false ;
62+ }
63+
5764 // Route must start with / to be a valid path
5865 if (!route .startsWith ("/" )) {
5966 return false ;
@@ -64,11 +71,6 @@ public static boolean isRouteEligible(String route) {
6471 return false ;
6572 }
6673
67- // Reject routes that are just wildcards
68- if (route .matches ("^[*/]+$" )) {
69- return false ;
70- }
71-
7274 // Route is eligible for endpoint tagging
7375 return true ;
7476 }
@@ -145,11 +147,16 @@ public static String parameterizeUrlPath(String path) {
145147 * @return parameterized endpoint path or '/'
146148 */
147149 public static String computeEndpointFromUrl (String url ) {
148- if (url == null || url . trim (). isEmpty () ) {
150+ if (url == null ) {
149151 return "/" ;
150152 }
151153
152- java .util .regex .Matcher matcher = URL_PATTERN .matcher (url .trim ());
154+ url = url .trim ();
155+ if (url .isEmpty ()) {
156+ return "/" ;
157+ }
158+
159+ Matcher matcher = URL_PATTERN .matcher (url );
153160 if (!matcher .matches ()) {
154161 log .debug ("Failed to parse URL for endpoint computation: {}" , url );
155162 return "/" ;
@@ -193,29 +200,22 @@ public static void setEndpointTag(CoreSpan<?> span) {
193200
194201 /**
195202 * Sets the HTTP endpoint tag on a span context based on configuration flags. This overload
196- * accepts DDSpanContext for use in TagInterceptor and other core components.
203+ * accepts DDSpanContext for use in tag post-processors and other core components.
197204 *
198205 * @param spanContext The span context to potentially tag
199206 * @param config The tracer configuration containing feature flags
200207 */
201- public static void setEndpointTag (
202- datadog .trace .core .DDSpanContext spanContext , datadog .trace .api .Config config ) {
208+ public static void setEndpointTag (DDSpanContext spanContext , Config config ) {
203209 if (!config .isResourceRenamingEnabled ()) {
204210 return ;
205211 }
206212
207213 Object route = spanContext .unsafeGetTag (HTTP_ROUTE );
208- boolean shouldUseRoute = false ;
209214
210215 // Check if we should use route (when not forcing simplified endpoints)
211216 if (!config .isResourceRenamingAlwaysSimplifiedEndpoint ()
212217 && route != null
213218 && isRouteEligible (route .toString ())) {
214- shouldUseRoute = true ;
215- }
216-
217- // If we should use route and not set endpoint tag, return early
218- if (shouldUseRoute ) {
219219 return ;
220220 }
221221
@@ -236,23 +236,17 @@ && isRouteEligible(route.toString())) {
236236 * @param span The span to potentially tag
237237 * @param config The tracer configuration containing feature flags
238238 */
239- public static void setEndpointTag (CoreSpan <?> span , datadog . trace . api . Config config ) {
239+ public static void setEndpointTag (CoreSpan <?> span , Config config ) {
240240 if (!config .isResourceRenamingEnabled ()) {
241241 return ;
242242 }
243243
244244 Object route = span .getTag (HTTP_ROUTE );
245- boolean shouldUseRoute = false ;
246245
247246 // Check if we should use route (when not forcing simplified endpoints)
248247 if (!config .isResourceRenamingAlwaysSimplifiedEndpoint ()
249248 && route != null
250249 && isRouteEligible (route .toString ())) {
251- shouldUseRoute = true ;
252- }
253-
254- // If we should use route and not set endpoint tag, return early
255- if (shouldUseRoute ) {
256250 return ;
257251 }
258252
0 commit comments