Skip to content

Commit 320ef70

Browse files
authored
feat: add sw_grpc plugin (#362)
1 parent 7dd9a30 commit 320ef70

22 files changed

+1535
-188
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- Drop support for 3.7 (#356)
77
- Support sampling rate setup. Provide `SW_SAMPLE_N_PER_3_SECS` environment variable to control it (#357)
88

9+
- Plugins:
10+
- Add gRPC plugin (#362)
11+
912
- Fixes:
1013
- Fix: user/password replacement is not allowed for relative URLs (#349)
1114
- Fix pulsar client does not support init arguments other than service_url (#351)

docs/en/setup/Configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export SW_AGENT_YourConfiguration=YourValue
9797
| plugin_fastapi_collect_http_params | SW_PLUGIN_FASTAPI_COLLECT_HTTP_PARAMS | <class 'bool'> | False | This config item controls that whether the FastAPI plugin should collect the parameters of the request. |
9898
| plugin_bottle_collect_http_params | SW_PLUGIN_BOTTLE_COLLECT_HTTP_PARAMS | <class 'bool'> | False | This config item controls that whether the Bottle plugin should collect the parameters of the request. |
9999
| plugin_celery_parameters_length | SW_PLUGIN_CELERY_PARAMETERS_LENGTH | <class 'int'> | 512 | The maximum length of `celery` functions parameters, longer than this will be truncated, 0 turns off |
100+
| plugin_grpc_ignored_methods | SW_PLUGIN_GRPC_IGNORED_METHODS | <class 'str'> | | Comma-delimited list of user-defined grpc methods to ignore, like /package.Service/Method1,/package.Service/Method2 |
100101
### Sampling Configurations
101102
| Configuration | Environment Variable | Type | Default Value | Description |
102103
| :------------ | :------------ | :------------ | :------------ | :------------ |

docs/en/setup/Plugins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ or a limitation of SkyWalking auto-instrumentation (welcome to contribute!)
2626
| [hug](https://falcon.readthedocs.io/en/stable/) | Python >=3.11 - NOT SUPPORTED YET; Python >=3.10 - ['2.5', '2.6']; Python >=3.7 - ['2.4.1', '2.5', '2.6']; | `sw_falcon` |
2727
| [fastapi](https://fastapi.tiangolo.com) | Python >=3.7 - ['0.89.*', '0.88.*']; | `sw_fastapi` |
2828
| [flask](https://flask.palletsprojects.com) | Python >=3.7 - ['2.0']; | `sw_flask` |
29+
| [grpcio](https://grpc.io/docs/languages/python) | Python >=3.8 - ['1.*']; | `sw_grpc` |
2930
| [happybase](https://happybase.readthedocs.io) | Python >=3.7 - ['1.2.0']; | `sw_happybase` |
3031
| [http_server](https://docs.python.org/3/library/http.server.html) | Python >=3.7 - ['*']; | `sw_http_server` |
3132
| [werkzeug](https://werkzeug.palletsprojects.com/) | Python >=3.7 - ['1.0.1', '2.0']; | `sw_http_server` |

poetry.lock

Lines changed: 183 additions & 183 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ httpx = "^0.23.3"
137137
confluent-kafka = "^2.0.2"
138138
neo4j = "^5.9.0"
139139
pulsar-client = "3.3.0"
140+
grpcio = "^1.49.1"
140141

141142
[tool.poetry.group.lint.dependencies]
142143
pylint = '2.13.9'

skywalking/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Component(Enum):
5555
AIORedis = 7017
5656
Websockets = 7018
5757
HTTPX = 7019
58+
Grpc = 23
5859

5960

6061
class Layer(Enum):
@@ -89,6 +90,6 @@ def is_exit(self):
8990

9091
class Log(object):
9192

92-
def __init__(self, timestamp: time = time.time(), items: List[LogItem] = None): # noqa
93+
def __init__(self, timestamp: time = time.time(), items: List[LogItem] = None): # noqa
9394
self.timestamp = timestamp
9495
self.items = items or []

skywalking/config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
RE_IGNORE_PATH: Pattern = re.compile('^$')
3939
RE_HTTP_IGNORE_METHOD: Pattern = RE_IGNORE_PATH
40+
RE_GRPC_IGNORED_METHODS: Pattern = RE_IGNORE_PATH
4041

4142
options = None # here to include 'options' in globals
4243
options = globals().copy()
@@ -212,6 +213,8 @@
212213
plugin_bottle_collect_http_params: bool = os.getenv('SW_PLUGIN_BOTTLE_COLLECT_HTTP_PARAMS', '').lower() == 'true'
213214
# The maximum length of `celery` functions parameters, longer than this will be truncated, 0 turns off
214215
plugin_celery_parameters_length: int = int(os.getenv('SW_PLUGIN_CELERY_PARAMETERS_LENGTH', '512'))
216+
# Comma-delimited list of user-defined grpc methods to ignore, like /package.Service/Method1,/package.Service/Method2
217+
plugin_grpc_ignored_methods: str = os.getenv('SW_PLUGIN_GRPC_IGNORED_METHODS', '').upper()
215218

216219
# BEGIN: Sampling Configurations
217220
# The number of samples to take in every 3 seconds, 0 turns off
@@ -284,6 +287,7 @@ def finalize_regex() -> None:
284287
reesc = re.compile(r'([.*+?^=!:${}()|\[\]\\])')
285288
suffix = r'^.+(?:' + '|'.join(reesc.sub(r'\\\1', s.strip()) for s in agent_ignore_suffix.split(',')) + ')$'
286289
method = r'^' + '|'.join(s.strip() for s in plugin_http_ignore_method.split(',')) + '$'
290+
grpc_method = r'^' + '|'.join(s.strip() for s in plugin_grpc_ignored_methods.split(',')) + '$'
287291
path = '^(?:' + \
288292
'|'.join( # replaces ","
289293
'/(?:[^/]*/)*'.join( # replaces "/**/"
@@ -297,15 +301,20 @@ def finalize_regex() -> None:
297301
) for p0 in agent_trace_ignore_path.split(',')
298302
) + ')$'
299303

300-
global RE_IGNORE_PATH, RE_HTTP_IGNORE_METHOD
304+
global RE_IGNORE_PATH, RE_HTTP_IGNORE_METHOD, RE_GRPC_IGNORED_METHODS
301305
RE_IGNORE_PATH = re.compile(f'{suffix}|{path}')
302306
RE_HTTP_IGNORE_METHOD = re.compile(method, re.IGNORECASE)
307+
RE_GRPC_IGNORED_METHODS = re.compile(grpc_method, re.IGNORECASE)
303308

304309

305310
def ignore_http_method_check(method: str):
306311
return RE_HTTP_IGNORE_METHOD.match(method)
307312

308313

314+
def ignore_grpc_method_check(method: str):
315+
return RE_GRPC_IGNORED_METHODS.match(method)
316+
317+
309318
def finalize() -> None:
310319
"""
311320
invokes finalizers

skywalking/meter/pvm/data_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ def register(self):
2323
for name in dir(self):
2424
if name.endswith('generator'):
2525
generator = getattr(self, name)()
26-
Gauge.Builder('instance_pvm_' + name[:-10], generator).build()
26+
Gauge.Builder(f'instance_pvm_{name[:-10]}', generator).build()

0 commit comments

Comments
 (0)