Skip to content

Commit

Permalink
Cheer pick 2.3.4 (#193)
Browse files Browse the repository at this point in the history
* prepare to release 3.0.3

* cheery pick from Fix issue 177

* Fix mvc extract spancontext

* Fix zipkin report throwable
  • Loading branch information
glmapper authored Mar 22, 2019
1 parent bda08c1 commit f4e3d45
Show file tree
Hide file tree
Showing 29 changed files with 136 additions and 105 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>tracer-all-parent</artifactId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
<packaging>pom</packaging>
<name>tracer-all-parent</name>
<description>Alipay SOFATracer Log Implemented by OpenTracing</description>
Expand All @@ -33,7 +33,7 @@

<properties>
<opentracing.version>0.22.0</opentracing.version>
<sofa.tracer.version>3.0.3-SNAPSHOT</sofa.tracer.version>
<sofa.tracer.version>3.0.3</sofa.tracer.version>
<java.compiler.source.version>1.8</java.compiler.source.version>
<java.compiler.target.version>1.8</java.compiler.target.version>
<jmh.version>1.9.3</jmh.version>
Expand Down
2 changes: 1 addition & 1 deletion sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import com.alipay.common.tracer.core.SofaTracer;
import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration;
import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext;
import com.alipay.common.tracer.core.registry.AbstractTextB3Formatter;
import com.alipay.common.tracer.core.registry.ExtendFormat;
import com.alipay.common.tracer.core.span.CommonSpanTags;
import com.alipay.common.tracer.core.span.SofaTracerSpan;
import com.alipay.common.tracer.core.utils.StringUtils;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -66,11 +66,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
// sr
springMvcSpan = springMvcTracer.serverReceive(spanContext);

if (!isRootSpan(request)) {
springMvcSpan.getSofaTracerSpanContext()
.setSpanId(spanContext.nextChildContextId());
}

if (StringUtils.isBlank(this.appName)) {
this.appName = SofaTracerConfiguration
.getProperty(SofaTracerConfiguration.TRACER_APPNAME_KEY);
Expand Down Expand Up @@ -103,18 +98,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
}
}

private boolean isRootSpan(HttpServletRequest request) {
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
if (key.equals("X-B3-TraceId") && StringUtils.isNotBlank(value)) {
return false;
}
}
return true;
}

@Override
public void destroy() {
// no operation
Expand Down Expand Up @@ -142,7 +125,7 @@ public SofaTracerSpanContext getSpanContextFromRequest(HttpServletRequest reques
headers.put(key, value);
}
// Delay the initialization of the SofaTracerSpanContext to execute the serverReceive method
if (headers.isEmpty() || !headers.containsKey("X-B3-TraceId")) {
if (headers.isEmpty() || !isContainSofaTracerMark(headers)) {
return null;
}

Expand All @@ -152,6 +135,18 @@ public SofaTracerSpanContext getSpanContextFromRequest(HttpServletRequest reques
return spanContext;
}

/**
* To check is contain sofaTracer mark
* @param headers
* @return
*/
private boolean isContainSofaTracerMark(HashMap<String, String> headers) {
return (headers.containsKey(AbstractTextB3Formatter.TRACE_ID_KEY_HEAD.toLowerCase()) || headers
.containsKey(AbstractTextB3Formatter.TRACE_ID_KEY_HEAD))
&& (headers.containsKey(AbstractTextB3Formatter.SPAN_ID_KEY_HEAD.toLowerCase()) || headers
.containsKey(AbstractTextB3Formatter.SPAN_ID_KEY_HEAD));
}

class ResponseWrapper extends HttpServletResponseWrapper {

int contentLength = 0;
Expand Down
2 changes: 1 addition & 1 deletion sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body,
return execution.execute(request, gzipped.toByteArray());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.alipay.sofa.tracer.plugins.zipkin.sender;

import com.alipay.common.tracer.core.appender.self.SelfLog;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -64,9 +65,7 @@ public Call<Void> sendSpans(List<byte[]> encodedSpans) {
byte[] message = BytesMessageEncoder.JSON.encode(encodedSpans);
post(message);
} catch (Throwable e) {
if (e instanceof Error) {
throw (Error) e;
}
SelfLog.error("Failed to report span to remote server. Current rest url is " + url, e);
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions tracer-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>tracer-all</artifactId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
<packaging>jar</packaging>

<name>SOFATracer in one without SOFABoot starter</name>
Expand Down
2 changes: 1 addition & 1 deletion tracer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>tracer-all-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.0.3-SNAPSHOT</version>
<version>3.0.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,32 @@ public abstract class AbstractTextB3Formatter implements RegistryExtractorInject
/**
* 128/64 bit traceId lower-hex string (required)
*/
static final String TRACE_ID_KEY_HEAD = "X-B3-TraceId";
public static final String TRACE_ID_KEY_HEAD = "X-B3-TraceId";
/**
* 64 bit spanId lower-hex string (required)
*/
static final String SPAN_ID_KEY_HEAD = "X-B3-SpanId";
public static final String SPAN_ID_KEY_HEAD = "X-B3-SpanId";
/**
* 64 bit parentSpanId lower-hex string (absent on root span)
*/
static final String PARENT_SPAN_ID_KEY_HEAD = "X-B3-ParentSpanId";
public static final String PARENT_SPAN_ID_KEY_HEAD = "X-B3-ParentSpanId";
/**
* "1" means report this span to the tracing system, "0" means do not. (absent means defer the
* decision to the receiver of this header).
*/
static final String SAMPLED_KEY_HEAD = "X-B3-Sampled";
public static final String SAMPLED_KEY_HEAD = "X-B3-Sampled";
/**
* "1" implies sampled and is a request to override collection-tier sampling policy.
*/
static final String FLAGS_KEY_HEAD = "X-B3-Flags";
static final String FLAGS_KEY_HEAD = "X-B3-Flags";
/**
* Baggage items prefix
*/
static final String BAGGAGE_KEY_PREFIX = "baggage-";
static final String BAGGAGE_KEY_PREFIX = "baggage-";
/**
* System Baggage items prefix
*/
static final String BAGGAGE_SYS_KEY_PREFIX = "baggage-sys-";
static final String BAGGAGE_SYS_KEY_PREFIX = "baggage-sys-";

@Override
public SofaTracerSpanContext extract(TextMap carrier) {
Expand Down
Loading

0 comments on commit f4e3d45

Please sign in to comment.