Skip to content

Commit ec3618a

Browse files
authored
Format with ruff (#1505)
1 parent 5c62b43 commit ec3618a

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ share/python-wheels/
3333
*.egg
3434
MANIFEST
3535
version.txt
36+
version.py
37+
_version.py
3638

3739
# PyInstaller
3840
# Usually these files are written by a python script from a template

newrelic/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4126,8 +4126,12 @@ def _process_module_builtin_defaults():
41264126
"newrelic.hooks.framework_azurefunctions",
41274127
"instrument_azure_functions_worker_dispatcher",
41284128
)
4129-
_process_module_definition("pyzeebe.client.client", "newrelic.hooks.external_pyzeebe", "instrument_pyzeebe_client_client")
4130-
_process_module_definition("pyzeebe.worker.job_executor", "newrelic.hooks.external_pyzeebe", "instrument_pyzeebe_worker_job_executor")
4129+
_process_module_definition(
4130+
"pyzeebe.client.client", "newrelic.hooks.external_pyzeebe", "instrument_pyzeebe_client_client"
4131+
)
4132+
_process_module_definition(
4133+
"pyzeebe.worker.job_executor", "newrelic.hooks.external_pyzeebe", "instrument_pyzeebe_worker_job_executor"
4134+
)
41314135

41324136

41334137
def _process_module_entry_points():

newrelic/hooks/external_pyzeebe.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import logging
1717

1818
from newrelic.api.application import application_instance
19-
from newrelic.api.web_transaction import WebTransaction
2019
from newrelic.api.function_trace import FunctionTrace
2120
from newrelic.api.transaction import current_transaction
21+
from newrelic.api.web_transaction import WebTransaction
2222
from newrelic.common.object_wrapper import wrap_function_wrapper
2323

2424
_logger = logging.getLogger(__name__)
@@ -28,22 +28,26 @@
2828

2929
# Adds client method params as txn or span attributes
3030
def _add_client_input_attributes(method_name, trace, args, kwargs):
31-
bpmn_id = extract_agent_attribute_from_methods(args, kwargs, method_name, ("run_process", "run_process_with_result"), "bpmn_process_id", 0)
31+
bpmn_id = extract_agent_attribute_from_methods(
32+
args, kwargs, method_name, ("run_process", "run_process_with_result"), "bpmn_process_id", 0
33+
)
3234
if bpmn_id:
3335
trace._add_agent_attribute("zeebe.client.bpmnProcessId", bpmn_id)
3436

3537
msg_name = extract_agent_attribute_from_methods(args, kwargs, method_name, ("publish_message"), "name", 0)
3638
if msg_name:
3739
trace._add_agent_attribute("zeebe.client.messageName", msg_name)
3840

39-
correlation_key = extract_agent_attribute_from_methods(args, kwargs, method_name, ("publish_message"), "correlation_key", 1)
41+
correlation_key = extract_agent_attribute_from_methods(
42+
args, kwargs, method_name, ("publish_message"), "correlation_key", 1
43+
)
4044
if correlation_key:
4145
trace._add_agent_attribute("zeebe.client.correlationKey", correlation_key)
42-
46+
4347
message_id = extract_agent_attribute_from_methods(args, kwargs, method_name, ("publish_message"), "message_id", 4)
4448
if message_id:
4549
trace._add_agent_attribute("zeebe.client.messageId", message_id)
46-
50+
4751
resource = extract_agent_attribute_from_methods(args, {}, method_name, ("deploy_resource"), None, 0)
4852
if resource:
4953
try:
@@ -61,7 +65,13 @@ def extract_agent_attribute_from_methods(args, kwargs, method_name, methods, par
6165
value = args[index]
6266
return value
6367
except Exception:
64-
_logger.warning("Exception occurred in PyZeebe instrumentation: failed to extract %s from %s. Report this issue to New Relic support.", param, method_name, exc_info=True)
68+
_logger.warning(
69+
"Exception occurred in PyZeebe instrumentation: failed to extract %s from %s. Report this issue to New Relic support.",
70+
param,
71+
method_name,
72+
exc_info=True,
73+
)
74+
6575

6676
# Async wrapper that instruments router/worker annotations`
6777
async def _nr_wrapper_execute_one_job(wrapped, instance, args, kwargs):

tests/external_pyzeebe/_mocks.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131

3232
# Dummy RPC stub coroutines
3333
async def dummy_create_process_instance(
34-
self, bpmn_process_id: str, variables: dict = None, version: int = -1, tenant_id: str = None # noqa: RUF013
34+
self,
35+
bpmn_process_id: str,
36+
variables: dict = None, # noqa: RUF013
37+
version: int = -1,
38+
tenant_id: str = None, # noqa: RUF013
3539
):
3640
"""Simulate ZeebeAdapter.create_process_instance"""
3741
return DummyCreateProcessInstanceResponse
@@ -40,17 +44,17 @@ async def dummy_create_process_instance(
4044
async def dummy_create_process_instance_with_result(
4145
self,
4246
bpmn_process_id: str,
43-
variables: dict = None, # noqa: RUF013
47+
variables: dict = None, # noqa: RUF013
4448
version: int = -1,
4549
timeout: int = 0,
4650
variables_to_fetch=None,
47-
tenant_id: str = None, # noqa: RUF013
51+
tenant_id: str = None, # noqa: RUF013
4852
):
4953
"""Simulate ZeebeAdapter.create_process_instance_with_result"""
5054
return DummyCreateProcessInstanceWithResultResponse
5155

5256

53-
async def dummy_deploy_resource(*resource_file_path: str, tenant_id: str = None): # noqa: RUF013
57+
async def dummy_deploy_resource(*resource_file_path: str, tenant_id: str = None): # noqa: RUF013
5458
"""Simulate ZeebeAdapter.deploy_resource"""
5559
# Create dummy deployment metadata for each provided resource path
5660
deployments = [
@@ -73,10 +77,10 @@ async def dummy_publish_message(
7377
self,
7478
name: str,
7579
correlation_key: str,
76-
variables: dict = None, # noqa: RUF013
80+
variables: dict = None, # noqa: RUF013
7781
time_to_live_in_milliseconds: int = 60000,
78-
message_id: str = None, # noqa: RUF013
79-
tenant_id: str = None, # noqa: RUF013
82+
message_id: str = None, # noqa: RUF013
83+
tenant_id: str = None, # noqa: RUF013
8084
):
8185
"""Simulate ZeebeAdapter.publish_message"""
8286
# Return the dummy response (contains message key)

tests/external_pyzeebe/test_client.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
)
2121
from pyzeebe import ZeebeClient, create_insecure_channel
2222
from pyzeebe.grpc_internals.zeebe_adapter import ZeebeAdapter
23-
from testing_support.validators.validate_span_events import validate_span_events
2423
from testing_support.validators.validate_custom_event import validate_custom_event_count
24+
from testing_support.validators.validate_span_events import validate_span_events
2525
from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics
2626

2727
from newrelic.api.background_task import background_task
@@ -114,7 +114,14 @@ async def _test():
114114
@validate_transaction_metrics(
115115
"test_zeebe_client:publish_message", rollup_metrics=[("ZeebeClient/publish_message", 1)], background_task=True
116116
)
117-
@validate_span_events(exact_agents={"zeebe.client.messageName": "test_message", "zeebe.client.correlationKey": "999999", "zeebe.client.messageId": "abc123"}, count=1)
117+
@validate_span_events(
118+
exact_agents={
119+
"zeebe.client.messageName": "test_message",
120+
"zeebe.client.correlationKey": "999999",
121+
"zeebe.client.messageId": "abc123",
122+
},
123+
count=1,
124+
)
118125
def test_publish_message(monkeypatch, loop):
119126
monkeypatch.setattr(ZeebeAdapter, "publish_message", dummy_publish_message)
120127

@@ -125,6 +132,7 @@ async def _test():
125132

126133
loop.run_until_complete(_test())
127134

135+
128136
@validate_custom_event_count(count=0)
129137
def test_publish_message_outside_txn(monkeypatch, loop):
130138
monkeypatch.setattr(ZeebeAdapter, "publish_message", dummy_publish_message)
@@ -133,4 +141,4 @@ async def _test():
133141
result = await client.publish_message(name="test_message", correlation_key="999999", message_id="abc123")
134142
assert result.key == 999999
135143

136-
loop.run_until_complete(_test())
144+
loop.run_until_complete(_test())

0 commit comments

Comments
 (0)