@@ -132,16 +132,11 @@ func InitDatadogOTel(cfg DatadogOTelConfig) error {
132132
133133// WrapHTTPHandler instruments inbound HTTP requests using otelhttp and produces spans.
134134func WrapHTTPHandler (next http.Handler ) http.Handler {
135- // Regexes mirror ./utils/count_apis.sh so OTel span names group the same way as the offline API log rollups:
136- // - collapse multiple slashes
137- // - trim trailing slash
138- // - mask common asset extensions -> ".{asset}"
139- // - normalize Swagger assets "/vN/swagger.{asset}" -> "/vN/swagger" (keep version; do NOT map to /v*)
140- // - mask UUIDs, numeric IDs, Salesforce IDs, LFX IDs, and literal "null" segments
141135 reMultiSlash := regexp .MustCompile (`/{2,}` )
142136 reAssetExt := regexp .MustCompile (`\.(png|svg|css|js|json|xml|htm|html)$` )
143137 reSwaggerAsset := regexp .MustCompile (`^(/v[0-9]+)/swagger\.\{asset\}$` )
144- // UUIDs: classify valid vs invalid (E2E often probes invalid IDs)
138+ reSwaggerJSONResource := regexp .MustCompile (`^(/v[0-9]+/swagger\.json)/.+$` )
139+ reSwaggerTemplatedResource := regexp .MustCompile (`^(/v[0-9]+/swagger\.\{asset\})/.+$` )
145140 reUUIDValid := regexp .MustCompile (`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}` )
146141 reUUIDLike := regexp .MustCompile (`/[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}(/|$)` )
147142 reUUIDHexDash36 := regexp .MustCompile (`/[0-9a-fA-F-]{36}(/|$)` )
@@ -151,8 +146,15 @@ func WrapHTTPHandler(next http.Handler) http.Handler {
151146 reLFXIDValid := regexp .MustCompile (`/lf[A-Za-z0-9]{16,22}(/|$)` )
152147 reLFXIDLike := regexp .MustCompile (`/lf[^/]{1,32}(/|$)` )
153148 reNull := regexp .MustCompile (`/null(/|$)` )
149+ reUndefined := regexp .MustCompile (`/undefined(/|$)` )
154150 reInvalidUUIDSeg := regexp .MustCompile (`/(?:invalid-uuid(?:-format)?|not-a-uuid)(/|$)` )
155151 reInvalidSFIDSeg := regexp .MustCompile (`/invalid-sfid(?:-format)?(/|$)` )
152+ reUsersUsername := regexp .MustCompile (`^(/v[0-9]+/users/username)/[^/]+$` )
153+ reCompanyName := regexp .MustCompile (`^(/v[0-9]+/company/name)/[^/]+$` )
154+ reCompanyUserCLAManagerDesignee := regexp .MustCompile (`^(/v[0-9]+/company/[^/]+/user)/[^/]+(/claGroupID/[^/]+/is-cla-manager-designee)$` )
155+ reProjectCLAManagerUser := regexp .MustCompile (`^(/v[0-9]+/company/[^/]+/project/[^/]+/cla-manager)/[^/]+$` )
156+ reRepositoryProviderGithubSignNumeric := regexp .MustCompile (`^(/v[0-9]+/repository-provider/github/sign/[^/]+)/[0-9]+(/[^/]+)$` )
157+ reSignedIndividualGithubNumeric := regexp .MustCompile (`^(/v[0-9]+/signed/individual/[^/]+)/[0-9]+(/[^/]+)$` )
156158
157159 boolishTrue := func (v string ) bool {
158160 switch strings .ToLower (strings .TrimSpace (v )) {
@@ -177,29 +179,32 @@ func WrapHTTPHandler(next http.Handler) http.Handler {
177179 p = strings .TrimSuffix (p , "/" )
178180 }
179181
180- // Asset extensions (including swagger.json/xml/html) -> ".{asset}"
182+ p = reSwaggerJSONResource .ReplaceAllString (p , "$1/{resource}" )
183+ p = reSwaggerTemplatedResource .ReplaceAllString (p , "$1/{resource}" )
184+ p = reUsersUsername .ReplaceAllString (p , "$1/{name}" )
185+ p = reCompanyName .ReplaceAllString (p , "$1/{name}" )
186+ p = reCompanyUserCLAManagerDesignee .ReplaceAllString (p , "$1/{name}$2" )
187+ p = reProjectCLAManagerUser .ReplaceAllString (p , "$1/{name}" )
188+ p = reRepositoryProviderGithubSignNumeric .ReplaceAllString (p , "$1/{n}$2" )
189+ p = reSignedIndividualGithubNumeric .ReplaceAllString (p , "$1/{n}$2" )
181190 p = reAssetExt .ReplaceAllString (p , ".{asset}" )
182-
183- // Keep the version (/v1, /v2, ...) but normalize swagger asset paths.
184191 if m := reSwaggerAsset .FindStringSubmatch (p ); m != nil {
185192 p = m [1 ] + "/swagger"
186193 }
187194
188- // Dynamic segment masking (use template placeholders, not "*")
189- // UUIDs: valid vs invalid
190195 p = reUUIDValid .ReplaceAllString (p , "{uuid}" )
191196 p = reUUIDLike .ReplaceAllString (p , "/{invalid-uuid}$1" )
192197 p = reUUIDHexDash36 .ReplaceAllString (p , "/{invalid-uuid}$1" )
193- p = reNumericID .ReplaceAllString (p , "/{id}$1" )
194- p = reNumericID .ReplaceAllString (p , "/{id}$1" )
195- // Salesforce IDs: valid vs invalid
198+ for prev := "" ; p != prev ; {
199+ prev = p
200+ p = reNumericID .ReplaceAllString (p , "/{id}$1" )
201+ }
196202 p = reSFIDValid .ReplaceAllString (p , "/{sfid}$1" )
197203 p = reSFIDLike .ReplaceAllString (p , "/{invalid-sfid}$1" )
198- // LFX IDs: valid vs invalid
199204 p = reLFXIDValid .ReplaceAllString (p , "/{lfxid}$1" )
200205 p = reLFXIDLike .ReplaceAllString (p , "/{invalid-lfxid}$1" )
201206 p = reNull .ReplaceAllString (p , "/{null}$1" )
202- // Known "invalid" test tokens (Cypress) -> placeholders
207+ p = reUndefined . ReplaceAllString ( p , "/{undefined}$1" )
203208 p = reInvalidUUIDSeg .ReplaceAllString (p , "/{invalid-uuid}$1" )
204209 p = reInvalidSFIDSeg .ReplaceAllString (p , "/{invalid-sfid}$1" )
205210
0 commit comments