Repository: pinpoint-apm/pinpoint
Issue: Parent application namespace header is not set correctly
Labels: bug
module:agent

#### What version of pinpoint are you using?
Affects 1.8.0, 1.8.1, 1.8.2

#### Describe the bug
Value set for `profiler.application.namespace` in *pinpoint.config*, is not propagated to a remote node via **Pinpoint-pAppNamespace**. Instead, the application name is propagated over to a remote node.
If both sender and receiver set `profiler.application.namespace` to the same value, it will not work as intended, and the receiver will start a new trace.

The bug has no affect if `profiler.application.namespace` option is not set.

#### What did you do to trigger the bug?
Steps to reproduce, for example:
1. Set `profiler.application.namespace` option to some value for sender and receiver.
2. Send HTTP calls from sender to receiver.

#### Expected behavior
The call between the sender and receiver is traced as a single transaction.

#### Screenshots
N/A

#### Logs
N/A

#### Additional context
`profiler.application.namespace` must be set and be the same value for both sender/receiver.


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java
index b37e3c97d9af..93e8988fc82e 100644
--- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java
+++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/request/DefaultRequestTraceWriter.java
@@ -23,11 +23,15 @@
 import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
 import com.navercorp.pinpoint.bootstrap.sampler.SamplingFlagUtils;
 import com.navercorp.pinpoint.common.util.Assert;
+import com.navercorp.pinpoint.common.util.StringUtils;
 
 /**
  * @author jaehong.kim
  */
 public class DefaultRequestTraceWriter<T> implements RequestTraceWriter<T> {
+
+    private static final String NOT_SET = null;
+
     private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
     private final boolean isDebug = logger.isDebugEnabled();
     private final ClientHeaderAdaptor<T> clientHeaderAdaptor;
@@ -36,7 +40,7 @@ public class DefaultRequestTraceWriter<T> implements RequestTraceWriter<T> {
     private final String applicationNamespace;
 
     public DefaultRequestTraceWriter(ClientHeaderAdaptor<T> clientHeaderAdaptor, TraceContext traceContext) {
-        this(clientHeaderAdaptor, traceContext.getApplicationName(), traceContext.getServerTypeCode(), traceContext.getApplicationName());
+        this(clientHeaderAdaptor, traceContext.getApplicationName(), traceContext.getServerTypeCode(), traceContext.getProfilerConfig().getApplicationNamespace());
     }
 
     public DefaultRequestTraceWriter(ClientHeaderAdaptor<T> clientHeaderAdaptor, String applicationName, short serverTypeCode, String applicationNamespace) {
@@ -44,7 +48,11 @@ public DefaultRequestTraceWriter(ClientHeaderAdaptor<T> clientHeaderAdaptor, Str
 
         this.applicationName = Assert.requireNonNull(applicationName, "applicationName must not be null");
         this.serverTypeCode = serverTypeCode;
-        this.applicationNamespace = Assert.requireNonNull(applicationNamespace, "applicationNamespace must not be null");
+        if (StringUtils.isEmpty(applicationNamespace)) {
+            this.applicationNamespace = NOT_SET;
+        } else {
+            this.applicationNamespace = applicationNamespace;
+        }
     }
 
     @Override
@@ -70,7 +78,7 @@ public void write(T header, final TraceId traceId, final String host) {
         clientHeaderAdaptor.setHeader(header, Header.HTTP_PARENT_APPLICATION_NAME.toString(), applicationName);
         clientHeaderAdaptor.setHeader(header, Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(serverTypeCode));
 
-        if (applicationNamespace != null) {
+        if (applicationNamespace != NOT_SET) {
             clientHeaderAdaptor.setHeader(header, Header.HTTP_PARENT_APPLICATION_NAMESPACE.toString(), applicationNamespace);
         }
 


Test patch: