Skip to content

Commit

Permalink
fix spring mvc appname lost (#108)
Browse files Browse the repository at this point in the history
* fix spring mvc appname lost

* fix appname case fail in ci

* remove unuseful codes
  • Loading branch information
straybirdzls authored and glmapper committed Nov 8, 2018
1 parent 95534fd commit c41b3e7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
.getProperty(SofaTracerConfiguration.TRACER_APPNAME_KEY);
Assert.isTrue(!StringUtils.isBlank(applicationName),
SofaTracerConfiguration.TRACER_APPNAME_KEY + " must be configured!");
SofaTracerConfiguration.setProperty(SofaTracerConfiguration.TRACER_APPNAME_KEY,
applicationName);

// set loggingPath
String loggingPath = environment.getProperty("logging.path");
if (StringUtils.isNotBlank(loggingPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package com.alipay.sofa.tracer.boot.base;

import com.alipay.common.tracer.core.appender.TracerLogRootDaemon;
import com.alipay.common.tracer.core.configuration.SofaTracerConfiguration;
import com.alipay.common.tracer.core.reporter.digest.manager.SofaTracerDigestReporterAsyncManager;
import com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterCycleTimesManager;
import com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager;
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcTracer;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -103,4 +105,15 @@ protected static void reflectSpringMVCClear() throws NoSuchFieldException,
fieldStat.setAccessible(true);
fieldStat.set(statReporterManager, new ConcurrentHashMap<>());
}

@AfterClass
public static void afterClass() throws Exception {
clearTracerProperties();
}

private static void clearTracerProperties() throws Exception {
Field propertiesField = SofaTracerConfiguration.class.getDeclaredField("properties");
propertiesField.setAccessible(true);
propertiesField.set(null, new ConcurrentHashMap<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import com.alipay.sofa.tracer.plugins.springmvc.SpringMvcLogEnum;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

Expand All @@ -39,6 +41,9 @@
@ActiveProfiles("zipkin")
public class SpringMvcFilterTest extends AbstractTestBase {

@Value("${spring.application.name}")
private String appName;

@Test
public void testSofaRestGet() throws Exception {
assertNotNull(testRestTemplate);
Expand All @@ -57,5 +62,8 @@ public void testSofaRestGet() throws Exception {
List<String> contents = FileUtils
.readLines(customFileLog(SpringMvcLogEnum.SPRING_MVC_DIGEST.getDefaultLogName()));
assertTrue(contents.size() == 1);

String logAppName = contents.get(0).split(",")[1];
assertEquals(appName, logAppName);
}
}

0 comments on commit c41b3e7

Please sign in to comment.