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 2020/07/19 08:20:17 UTC
[skywalking-python] branch master updated: Add ignore_suffix Config
(#40)
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
The following commit(s) were added to refs/heads/master by this push:
new 0b0ccdd Add ignore_suffix Config (#40)
0b0ccdd is described below
commit 0b0ccddbb43ae367e0e214d5e592ef582e4e38e1
Author: huawei <al...@gmail.com>
AuthorDate: Sun Jul 19 16:20:11 2020 +0800
Add ignore_suffix Config (#40)
---
README.md | 2 ++
skywalking/config/__init__.py | 2 ++
skywalking/trace/context/__init__.py | 23 ++++++++++++++++++++++-
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 3d8db02..e03b4f5 100755
--- a/README.md
+++ b/README.md
@@ -60,6 +60,8 @@ Environment Variable | Description | Default
| `SW_AGENT_DISABLE_PLUGINS` | The name patterns in CSV pattern, plugins whose name matches one of the pattern won't be installed | `''` |
| `SW_MYSQL_TRACE_SQL_PARAMETERS` | Indicates whether to collect the sql parameters or not | `False` |
| `SW_MYSQL_SQL_PARAMETERS_MAX_LENGTH` | The maximum length of the collected parameter, parameters longer than the specified length will be truncated | `512` |
+| `SW_IGNORE_SUFFIX` | If the operation name of the first span is included in this set, this segment should be ignored. | `.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.html,.svg` |
+
## Supported Libraries
diff --git a/skywalking/config/__init__.py b/skywalking/config/__init__.py
index 75791f2..5eccc9d 100644
--- a/skywalking/config/__init__.py
+++ b/skywalking/config/__init__.py
@@ -29,6 +29,8 @@ disable_plugins = (os.getenv('SW_AGENT_DISABLE_PLUGINS') or '').split(',') # ty
mysql_trace_sql_parameters = True if os.getenv('SW_MYSQL_TRACE_SQL_PARAMETERS') and \
os.getenv('SW_MYSQL_TRACE_SQL_PARAMETERS') == 'True' else False # type: bool
mysql_sql_parameters_max_length = int(os.getenv('SW_MYSQL_SQL_PARAMETERS_MAX_LENGTH') or '512') # type: int
+ignore_suffix = os.getenv('SW_IGNORE_SUFFIX') or '.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,' \
+ '.mp4,.html,.svg ' # type: str
def init(
diff --git a/skywalking/trace/context/__init__.py b/skywalking/trace/context/__init__.py
index bd458db..a6acdcf 100644
--- a/skywalking/trace/context/__init__.py
+++ b/skywalking/trace/context/__init__.py
@@ -19,7 +19,7 @@ import logging
import threading
from typing import List
-from skywalking import agent
+from skywalking import agent, config
from skywalking.trace.carrier import Carrier
from skywalking.trace.segment import Segment
from skywalking.trace.span import Span, Kind, NoopSpan, EntrySpan, ExitSpan
@@ -35,6 +35,10 @@ class SpanContext(object):
self._sid = Counter()
def new_local_span(self, op: str) -> Span:
+ span = self.ignore_check(op, Kind.Local)
+ if span is not None:
+ return span
+
parent = self.spans[-1] if self.spans else None # type: Span
return Span(
@@ -46,6 +50,10 @@ class SpanContext(object):
)
def new_entry_span(self, op: str, carrier: 'Carrier' = None) -> Span:
+ span = self.ignore_check(op, Kind.Entry)
+ if span is not None:
+ return span
+
parent = self.spans[-1] if self.spans else None # type: Span
span = parent if parent is not None and parent.kind.is_entry else EntrySpan(
@@ -61,6 +69,10 @@ class SpanContext(object):
return span
def new_exit_span(self, op: str, peer: str, carrier: 'Carrier' = None) -> Span:
+ span = self.ignore_check(op, Kind.Exit)
+ if span is not None:
+ return span
+
parent = self.spans[-1] if self.spans else None # type: Span
span = parent if parent is not None and parent.kind.is_exit else ExitSpan(
@@ -76,6 +88,15 @@ class SpanContext(object):
return span
+ def ignore_check(self, op: str, kind: Kind):
+ suffix_idx = op.rfind(".")
+ if suffix_idx > -1 and config.ignore_suffix.find(op[suffix_idx:]) > -1:
+ return NoopSpan(
+ context=NoopContext(),
+ kind=kind,
+ )
+ return None
+
def start(self, span: Span):
if span not in self.spans:
self.spans.append(span)