@@ -182,34 +182,36 @@ private SamplingRuleApplier(
182182 @ SuppressWarnings ("deprecation" ) // TODO
183183 boolean matches (Attributes attributes , Resource resource ) {
184184 int matchedAttributes = 0 ;
185- String httpTarget = null ;
186- String httpUrl = null ;
187- String httpMethod = null ;
188- String host = null ;
189185
190- for (Map .Entry <AttributeKey <?>, Object > entry : attributes .asMap ().entrySet ()) {
191- if (entry .getKey ().equals (HTTP_TARGET ) || entry .getKey ().equals (UrlAttributes .URL_PATH )) {
192- httpTarget = (String ) entry .getValue ();
193- } else if (entry .getKey ().equals (HTTP_URL ) || entry .getKey ().equals (UrlAttributes .URL_FULL )) {
194- httpUrl = (String ) entry .getValue ();
195- } else if (entry .getKey ().equals (HTTP_METHOD )
196- || entry .getKey ().equals (HttpAttributes .HTTP_REQUEST_METHOD )) {
197- httpMethod = (String ) entry .getValue ();
198- // according to semantic conventions, if the HTTP request method is not known to
199- // instrumentation, it must be set to _OTHER and the
200- // HTTP_REQUEST_METHOD_ORIGINAL should contain the original method
201- if (httpMethod .equals (_OTHER_REQUEST_METHOD )) {
202- httpMethod = attributes .get (HttpAttributes .HTTP_REQUEST_METHOD_ORIGINAL );
203- }
204- } else if (entry .getKey ().equals (NET_HOST_NAME )
205- || entry .getKey ().equals (ServerAttributes .SERVER_ADDRESS )) {
206- host = (String ) entry .getValue ();
207- } else if (entry .getKey ().equals (HTTP_HOST )
208- || entry .getKey ().equals (ServerAttributes .SERVER_ADDRESS )) {
209- // TODO (trask) remove support for deprecated http.host attribute
210- host = (String ) entry .getValue ();
186+ String httpTarget = attributes .get (UrlAttributes .URL_PATH );
187+ if (httpTarget == null ) {
188+ httpTarget = attributes .get (HTTP_TARGET );
189+ }
190+
191+ String httpUrl = attributes .get (UrlAttributes .URL_FULL );
192+ if (httpUrl == null ) {
193+ httpUrl = attributes .get (HTTP_URL );
194+ }
195+
196+ String httpMethod = attributes .get (HttpAttributes .HTTP_REQUEST_METHOD );
197+ if (httpMethod == null ) {
198+ httpMethod = attributes .get (HTTP_METHOD );
199+ }
200+
201+ if (httpMethod != null && httpMethod .equals (_OTHER_REQUEST_METHOD )) {
202+ httpMethod = attributes .get (HttpAttributes .HTTP_REQUEST_METHOD_ORIGINAL );
203+ }
204+
205+ String host = attributes .get (ServerAttributes .SERVER_ADDRESS );
206+ if (host == null ) {
207+ host = attributes .get (NET_HOST_NAME );
208+ if (host == null ) {
209+ host = attributes .get (HTTP_HOST );
211210 }
211+ }
212+
212213
214+ for (Map .Entry <AttributeKey <?>, Object > entry : attributes .asMap ().entrySet ()) {
213215 Matcher matcher = attributeMatchers .get (entry .getKey ().getKey ());
214216 if (matcher == null ) {
215217 continue ;
0 commit comments