|
33 | 33 | import org.apache.skywalking.apm.agent.core.util.CollectionUtil; |
34 | 34 | import org.apache.skywalking.apm.agent.core.util.MethodUtil; |
35 | 35 | import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; |
36 | | -import org.apache.skywalking.apm.plugin.spring.mvc.commons.EnhanceRequireObjectCache; |
37 | | -import org.apache.skywalking.apm.plugin.spring.mvc.commons.RequestUtil; |
38 | | -import org.apache.skywalking.apm.plugin.spring.mvc.commons.SpringMVCPluginConfig; |
| 36 | +import org.apache.skywalking.apm.plugin.spring.mvc.commons.*; |
39 | 37 | import org.apache.skywalking.apm.plugin.spring.mvc.commons.exception.IllegalMethodStackDepthException; |
40 | 38 | import org.apache.skywalking.apm.plugin.spring.mvc.commons.exception.ServletResponseNotFoundException; |
41 | 39 | import org.springframework.http.server.reactive.ServerHttpRequest; |
@@ -113,53 +111,12 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr |
113 | 111 |
|
114 | 112 | if (IN_SERVLET_CONTAINER && IS_JAVAX && HttpServletRequest.class.isAssignableFrom(request.getClass())) { |
115 | 113 | final HttpServletRequest httpServletRequest = (HttpServletRequest) request; |
116 | | - CarrierItem next = contextCarrier.items(); |
117 | | - while (next.hasNext()) { |
118 | | - next = next.next(); |
119 | | - next.setHeadValue(httpServletRequest.getHeader(next.getHeadKey())); |
120 | | - } |
121 | | - |
122 | | - String operationName = this.buildOperationName(method, httpServletRequest.getMethod(), |
123 | | - (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField()); |
124 | | - AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); |
125 | | - Tags.URL.set(span, httpServletRequest.getRequestURL().toString()); |
126 | | - Tags.HTTP.METHOD.set(span, httpServletRequest.getMethod()); |
127 | | - span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); |
128 | | - SpanLayer.asHttp(span); |
| 114 | + handleBeforeMethod(objInst, method, HttpServletRequestWrappers.wrap(httpServletRequest), contextCarrier); |
129 | 115 |
|
130 | | - if (SpringMVCPluginConfig.Plugin.SpringMVC.COLLECT_HTTP_PARAMS) { |
131 | | - RequestUtil.collectHttpParam(httpServletRequest, span); |
132 | | - } |
133 | | - |
134 | | - if (!CollectionUtil.isEmpty(SpringMVCPluginConfig.Plugin.Http.INCLUDE_HTTP_HEADERS)) { |
135 | | - RequestUtil.collectHttpHeaders(httpServletRequest, span); |
136 | | - } |
137 | 116 | } else if (IN_SERVLET_CONTAINER && IS_JAKARTA && jakarta.servlet.http.HttpServletRequest.class.isAssignableFrom(request.getClass())) { |
138 | 117 | final jakarta.servlet.http.HttpServletRequest httpServletRequest = (jakarta.servlet.http.HttpServletRequest) request; |
139 | | - CarrierItem next = contextCarrier.items(); |
140 | | - while (next.hasNext()) { |
141 | | - next = next.next(); |
142 | | - next.setHeadValue(httpServletRequest.getHeader(next.getHeadKey())); |
143 | | - } |
144 | | - |
145 | | - String operationName = |
146 | | - this.buildOperationName(method, httpServletRequest.getMethod(), |
147 | | - (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField()); |
148 | | - AbstractSpan span = |
149 | | - ContextManager.createEntrySpan(operationName, contextCarrier); |
150 | | - Tags.URL.set(span, httpServletRequest.getRequestURL().toString()); |
151 | | - Tags.HTTP.METHOD.set(span, httpServletRequest.getMethod()); |
152 | | - span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); |
153 | | - SpanLayer.asHttp(span); |
| 118 | + handleBeforeMethod(objInst, method, HttpServletRequestWrappers.wrap(httpServletRequest), contextCarrier); |
154 | 119 |
|
155 | | - if (SpringMVCPluginConfig.Plugin.SpringMVC.COLLECT_HTTP_PARAMS) { |
156 | | - RequestUtil.collectHttpParam(httpServletRequest, span); |
157 | | - } |
158 | | - |
159 | | - if (!CollectionUtil |
160 | | - .isEmpty(SpringMVCPluginConfig.Plugin.Http.INCLUDE_HTTP_HEADERS)) { |
161 | | - RequestUtil.collectHttpHeaders(httpServletRequest, span); |
162 | | - } |
163 | 120 | } else if (ServerHttpRequest.class.isAssignableFrom(request.getClass())) { |
164 | 121 | final ServerHttpRequest serverHttpRequest = (ServerHttpRequest) request; |
165 | 122 | CarrierItem next = contextCarrier.items(); |
@@ -198,6 +155,30 @@ public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allAr |
198 | 155 | } |
199 | 156 | } |
200 | 157 |
|
| 158 | + private void handleBeforeMethod(EnhancedInstance objInst, Method method, |
| 159 | + HttpServletRequestWrapper httpServletRequest, ContextCarrier contextCarrier){ |
| 160 | + CarrierItem next = contextCarrier.items(); |
| 161 | + while (next.hasNext()) { |
| 162 | + next = next.next(); |
| 163 | + next.setHeadValue(httpServletRequest.getHeader(next.getHeadKey())); |
| 164 | + } |
| 165 | + |
| 166 | + String operationName = this.buildOperationName(method, httpServletRequest.getMethod(),(EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField()); |
| 167 | + AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier); |
| 168 | + Tags.URL.set(span, httpServletRequest.getRequestURL().toString()); |
| 169 | + Tags.HTTP.METHOD.set(span, httpServletRequest.getMethod()); |
| 170 | + span.setComponent(ComponentsDefine.SPRING_MVC_ANNOTATION); |
| 171 | + SpanLayer.asHttp(span); |
| 172 | + |
| 173 | + if (SpringMVCPluginConfig.Plugin.SpringMVC.COLLECT_HTTP_PARAMS) { |
| 174 | + RequestUtil.collectHttpParam(httpServletRequest, span); |
| 175 | + } |
| 176 | + |
| 177 | + if (!CollectionUtil.isEmpty(SpringMVCPluginConfig.Plugin.Http.INCLUDE_HTTP_HEADERS)) { |
| 178 | + RequestUtil.collectHttpHeaders(httpServletRequest, span); |
| 179 | + } |
| 180 | + } |
| 181 | + |
201 | 182 | @Override |
202 | 183 | public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, |
203 | 184 | Object ret) throws Throwable { |
|
0 commit comments