diff --git a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/AbstractHttpHeadersFilter.java b/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/AbstractHttpHeadersFilter.java deleted file mode 100644 index 128210962a..0000000000 --- a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/AbstractHttpHeadersFilter.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright 2017-2019 The OpenTracing Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package io.opentracing.contrib.spring.cloud.gateway; - -import io.opentracing.Span; -import io.opentracing.Tracer; -import org.springframework.cloud.gateway.filter.headers.HttpHeadersFilter; -import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; -import org.springframework.http.server.reactive.ServerHttpRequest; - -/** - * AbstractHttpHeadersFilter - * - * @author Weichao Li (liweichao0102@gmail.com) - * @since 2019/9/28 - */ -public abstract class AbstractHttpHeadersFilter implements HttpHeadersFilter { - - protected static final String SPAN_ATTRIBUTE = Span.class.getName(); - - protected static final String ROUTE_ATTRIBUTE = ServerWebExchangeUtils.class.getName() + ".gatewayRoute"; - - protected final Tracer tracer; - - protected AbstractHttpHeadersFilter(Tracer tracer) { - this.tracer = tracer; - } - - public String path(ServerHttpRequest.Builder request) { - return request.build().getPath().value(); - } - -} diff --git a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/GatewayTracingAutoConfiguration.java b/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/GatewayTracingAutoConfiguration.java deleted file mode 100644 index 3db7acb790..0000000000 --- a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/GatewayTracingAutoConfiguration.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2017-2019 The OpenTracing Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package io.opentracing.contrib.spring.cloud.gateway; - -import io.opentracing.Tracer; -import io.opentracing.contrib.spring.tracer.configuration.TracerAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.cloud.gateway.filter.GatewayFilterChain; -import org.springframework.cloud.gateway.filter.headers.HttpHeadersFilter; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * GatewayTracingAutoConfiguration - * - * @author Weichao Li (liweichao0102@gmail.com) - * @since 2019/9/27 - */ -@Configuration -@ConditionalOnWebApplication -@AutoConfigureAfter(TracerAutoConfiguration.class) -@ConditionalOnClass(GatewayFilterChain.class) -@ConditionalOnProperty(name = "opentracing.spring.cloud.gateway.enabled", havingValue = "true", matchIfMissing = true) -public class GatewayTracingAutoConfiguration { - - @Bean - @ConditionalOnClass(HttpHeadersFilter.class) - @ConditionalOnBean(Tracer.class) - HttpHeadersFilter traceRequestHttpHeadersFilter(Tracer tracer) { - return new TraceRequestHttpHeadersFilter(tracer); - } - - @Bean - @ConditionalOnClass(HttpHeadersFilter.class) - @ConditionalOnBean(Tracer.class) - HttpHeadersFilter traceResponseHttpHeadersFilter(Tracer tracer) { - return new TraceResponseHttpHeadersFilter(tracer); - } -} diff --git a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/TraceRequestHttpHeadersFilter.java b/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/TraceRequestHttpHeadersFilter.java deleted file mode 100644 index 19e0ebe572..0000000000 --- a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/TraceRequestHttpHeadersFilter.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright 2017-2019 The OpenTracing Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package io.opentracing.contrib.spring.cloud.gateway; - -import io.opentracing.Span; -import io.opentracing.Tracer; -import io.opentracing.contrib.spring.web.client.HttpHeadersCarrier; -import io.opentracing.propagation.Format; -import io.opentracing.tag.Tags; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.gateway.route.Route; -import org.springframework.http.HttpHeaders; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.web.server.ServerWebExchange; - - - -/** - * TraceRequestHttpHeadersFilter - * - * @author Weichao Li (liweichao0102@gmail.com) - * @since 2019/9/26 - */ -final class TraceRequestHttpHeadersFilter extends AbstractHttpHeadersFilter { - - private final Logger log = LoggerFactory.getLogger(TraceRequestHttpHeadersFilter.class); - - private static final String ROUTE_ID = "route.id"; - - private static final String COMPONENT = "java-spring-cloud-gateway"; - - protected TraceRequestHttpHeadersFilter(Tracer tracer) { - super(tracer); - } - - @Override - public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) { - log.debug("Will instrument spring cloud gateway the HTTP request headers"); - ServerHttpRequest.Builder builder = exchange.getRequest().mutate(); - Span span = this.tracer.buildSpan(path(builder)) - .asChildOf(tracer.activeSpan()) - .withTag(Tags.COMPONENT.getKey(), COMPONENT) - .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT) - .withTag(ROUTE_ID, getRouteId(exchange)) - .start(); - log.debug("Client span {} created for the request. New headers are {}", span, builder.build().getHeaders().toSingleValueMap()); - exchange.getAttributes().put(SPAN_ATTRIBUTE, span); - HttpHeaders headersWithInput = new HttpHeaders(); - try { - this.tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new HttpHeadersCarrier(headersWithInput)); - } catch (Exception ignore) { - log.error("TraceRequestHttpHeadersFilter error", ignore); - } - headersWithInput.addAll(input); - addHeadersWithInput(builder, headersWithInput); - return headersWithInput; - } - - private String getRouteId(ServerWebExchange exchange) { - String routeId = "unknown"; - Route route = exchange.getAttribute(ROUTE_ATTRIBUTE); - if (Objects.nonNull(route)) { - return route.getId(); - } - return routeId; - } - - private void addHeadersWithInput(ServerHttpRequest.Builder builder, - HttpHeaders headersWithInput) { - for (Map.Entry> entry : builder.build().getHeaders() - .entrySet()) { - String key = entry.getKey(); - List value = entry.getValue(); - headersWithInput.put(key, value); - } - } - - @Override - public boolean supports(Type type) { - return type.equals(Type.REQUEST); - } -} diff --git a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/TraceResponseHttpHeadersFilter.java b/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/TraceResponseHttpHeadersFilter.java deleted file mode 100644 index 10fa2d0b3c..0000000000 --- a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/java/io/opentracing/contrib/spring/cloud/gateway/TraceResponseHttpHeadersFilter.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2017-2019 The OpenTracing Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package io.opentracing.contrib.spring.cloud.gateway; - -import io.opentracing.Span; -import io.opentracing.Tracer; -import java.util.Objects; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpHeaders; -import org.springframework.web.server.ServerWebExchange; - - - -/** - * TraceResponseHttpHeadersFilter - * - * @author Weichao Li (liweichao0102@gmail.com) - * @since 2019/9/28 - */ -public class TraceResponseHttpHeadersFilter extends AbstractHttpHeadersFilter { - - private final Logger log = LoggerFactory.getLogger(TraceResponseHttpHeadersFilter.class); - - protected TraceResponseHttpHeadersFilter(Tracer tracer) { - super(tracer); - } - - @Override - public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) { - Object storedSpan = exchange.getAttribute(SPAN_ATTRIBUTE); - if (storedSpan == null) { - return input; - } - log.debug("Will instrument the response"); - Span span = (Span) storedSpan; - if (Objects.nonNull(span)) { - span.finish(); - } - log.debug("The response was handled for span " + storedSpan); - return input; - } - - @Override - public boolean supports(Type type) { - return type.equals(Type.RESPONSE); - } -} diff --git a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/discovery-plugin-strategy-starter-gateway-opentracing/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 73899c38cd..0000000000 --- a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "properties": [ - { - "name": "opentracing.spring.cloud.gateway.enabled", - "type": "java.lang.Boolean", - "description": "Add standard logging output to tracing system.", - "defaultValue": true - } - ] -} diff --git a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/resources/META-INF/spring.factories b/discovery-plugin-strategy-starter-gateway-opentracing/src/main/resources/META-INF/spring.factories index ecf094bacd..bdd2b88e91 100644 --- a/discovery-plugin-strategy-starter-gateway-opentracing/src/main/resources/META-INF/spring.factories +++ b/discovery-plugin-strategy-starter-gateway-opentracing/src/main/resources/META-INF/spring.factories @@ -1,3 +1,2 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.opentracing.contrib.spring.cloud.gateway.GatewayTracingAutoConfiguration,\ com.nepxion.discovery.plugin.gateway.opentracing.configuration.GatewayStrategyOpentracingAutoConfiguration \ No newline at end of file diff --git a/pom.xml b/pom.xml index b7ab1ad0a6..1651553641 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,7 @@ 1.5.0 1.1.4 1.7.0 - 0.3.9 + 0.3.10 Greenwich.SR3 2.1.1.RELEASE 2.1.10.RELEASE