提交 c2fb772e 编写于 作者: Z zhangxin10

提交web请求埋点

上级 a9bad1cd
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>skywalking-sdk-plugin</artifactId>
<groupId>com.ai.cloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>web-plugin</artifactId>
<packaging>jar</packaging>
<name>spring-plugin</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-auth</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
package com.ai.cloud.skywalking.plugin.web;
import com.ai.cloud.skywalking.buriedpoint.RPCBuriedPointReceiver;
import com.ai.cloud.skywalking.model.ContextData;
import com.ai.cloud.skywalking.model.Identification;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
public class SkyWalkingFilter implements Filter {
private String tracingName;
private static final String DEFAULT_TRACE_NAME = "SkyWalking-TRACING-NAME";
public void init(FilterConfig filterConfig) throws ServletException {
tracingName = filterConfig.getInitParameter("tracing-name");
if (tracingName == null || tracingName.length() <= 0) {
tracingName = DEFAULT_TRACE_NAME;
}
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
RPCBuriedPointReceiver receiver = null;
try {
HttpServletRequest request = (HttpServletRequest) servletRequest;
String contextDataStr = request.getHeader(tracingName);
ContextData contextData = null;
if (contextDataStr != null && contextDataStr.length() > 0) {
contextData = new ContextData(contextDataStr);
}
receiver = new RPCBuriedPointReceiver();
receiver.beforeReceived(contextData, generateIdentification(request));
filterChain.doFilter(servletRequest, servletResponse);
} catch (Throwable e) {
receiver.handleException(e);
throw new ServletException(e);
} finally {
receiver.afterReceived();
}
}
private Identification generateIdentification(HttpServletRequest request) {
return Identification.newBuilder()
.viewPoint(request.getRequestURL().toString())
.spanType('W')
.build();
}
public void destroy() {
// do-nothing
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册