You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2022/04/26 05:29:42 UTC

[skywalking-python] branch rm-ns created (now 814c8e3)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a change to branch rm-ns
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git


      at 814c8e3  Remove namespace to instance properties and add pid

This branch includes the following new commits:

     new 814c8e3  Remove namespace to instance properties and add pid

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-python] 01/01: Remove namespace to instance properties and add pid

Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch rm-ns
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git

commit 814c8e39ee5da61a01cf175edfbd1536e7500240
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Tue Apr 26 13:29:28 2022 +0800

    Remove namespace to instance properties and add pid
---
 skywalking/client/grpc.py   |  9 ++++++++-
 skywalking/client/http.py   | 11 ++++++++---
 skywalking/client/kafka.py  |  8 +++++++-
 skywalking/trace/carrier.py |  2 +-
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/skywalking/client/grpc.py b/skywalking/client/grpc.py
index 5c743c5..ca115fe 100644
--- a/skywalking/client/grpc.py
+++ b/skywalking/client/grpc.py
@@ -15,6 +15,7 @@
 # limitations under the License.
 #
 
+import os
 import grpc
 
 from skywalking import config
@@ -39,10 +40,16 @@ class GrpcServiceManagementClient(ServiceManagementClient):
 
     def send_instance_props(self):
         # TODO: other properties periodically | matching behavior of java agent
+        properties = [
+            KeyStringValuePair(key='language', value='python'),
+            KeyStringValuePair(key='Process No.', value=str(os.getpid())),
+        ]
+        if config.agent_namespace:
+            properties.append(KeyStringValuePair(key='namespace', value=config.agent_namespace))
         self.service_stub.reportInstanceProperties(InstanceProperties(
             service=config.service_name,
             serviceInstance=config.service_instance,
-            properties=[KeyStringValuePair(key='language', value='python')],
+            properties=properties,
         ))
 
     def send_heart_beat(self):
diff --git a/skywalking/client/http.py b/skywalking/client/http.py
index be60bd7..21afab2 100644
--- a/skywalking/client/http.py
+++ b/skywalking/client/http.py
@@ -15,6 +15,7 @@
 # limitations under the License.
 #
 import json
+import os
 
 import requests
 from google.protobuf import json_format
@@ -36,12 +37,16 @@ class HttpServiceManagementClient(ServiceManagementClient):
         self.session = requests.Session()
 
     def send_instance_props(self):
+        properties = [
+            {'key': 'language', 'value': 'python'},
+            {'key': 'Process No.', 'value': str(os.getpid())},
+        ]
+        if config.agent_namespace:
+            properties.append({'key': 'namespace', 'value': config.agent_namespace})
         res = self.session.post(self.url_instance_props, json={
             'service': config.service_name,
             'serviceInstance': config.service_instance,
-            'properties': [
-                {'key': 'language', 'value': 'python'},
-            ]
+            'properties': properties,
         })
         if logger_debug_enabled:
             logger.debug('heartbeat response: %s', res)
diff --git a/skywalking/client/kafka.py b/skywalking/client/kafka.py
index 22d2f73..2aaa7db 100644
--- a/skywalking/client/kafka.py
+++ b/skywalking/client/kafka.py
@@ -66,10 +66,16 @@ class KafkaServiceManagementClient(ServiceManagementClient):
         self.send_instance_props()
 
     def send_instance_props(self):
+        properties = [
+            KeyStringValuePair(key='language', value='python'),
+            KeyStringValuePair(key='Process No.', value=str(os.getpid())),
+        ]
+        if config.agent_namespace:
+            properties.append(KeyStringValuePair(key='namespace', value=config.agent_namespace))
         instance = InstanceProperties(
             service=config.service_name,
             serviceInstance=config.service_instance,
-            properties=[KeyStringValuePair(key='language', value='python')],
+            properties=properties,
         )
 
         key = bytes(self.topic_key_register + instance.serviceInstance, encoding='utf-8')
diff --git a/skywalking/trace/carrier.py b/skywalking/trace/carrier.py
index 1cfcd13..83a17e0 100644
--- a/skywalking/trace/carrier.py
+++ b/skywalking/trace/carrier.py
@@ -23,7 +23,7 @@ from skywalking.utils.lang import b64encode, b64decode
 
 class CarrierItem(object):
     def __init__(self, key: str = '', val: str = ''):
-        self.key = f'{config.agent_namespace}-{key}' if config.agent_namespace else key  # type: str
+        self.key = key  # type: str
         self.val = val  # type: str
 
     @property