Skip to content

feat: added single method option to configuration.yaml #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/instana/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,26 @@ def parse_endpoints_of_service(
"""
if service == "kafka" and isinstance(methods, list):
for rule in methods:
for method, endpoint in itertools.product(
rule["methods"], rule["endpoints"]
):
ignore_endpoints.append(
f"{service.lower()}.{method.lower()}.{endpoint.lower()}"
)
ignore_endpoints.extend(parse_kafka_methods(rule))
else:
for method in methods:
ignore_endpoints.append(f"{service.lower()}.{method.lower()}")
return ignore_endpoints


def parse_kafka_methods(rule: Union[str, Dict[str, any]]) -> List[str]:
parsed_rule = []
if isinstance(rule, dict):
for method, endpoint in itertools.product(rule["methods"], rule["endpoints"]):
parsed_rule.append(f"kafka.{method.lower()}.{endpoint.lower()}")
elif isinstance(rule, list):
for method in rule:
parsed_rule.append(f"kafka.{method.lower()}.*")
else:
parsed_rule.append(f"kafka.{rule.lower()}.*")
return parsed_rule


def parse_ignored_endpoints(params: Union[Dict[str, Any], str]) -> List[str]:
"""
Parses input to prepare a list for ignored endpoints.
Expand Down
11 changes: 11 additions & 0 deletions tests/util/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
parse_endpoints_of_service,
parse_ignored_endpoints,
parse_ignored_endpoints_dict,
parse_kafka_methods,
parse_service_pair,
)

Expand Down Expand Up @@ -157,3 +158,13 @@ def test_parse_endpoints_of_service(self) -> None:
"kafka.method6.endpoint1",
"kafka.method6.endpoint2",
]

def test_parse_kafka_methods_as_dict(self) -> None:
test_rule_as_dict = {"methods": ["send"], "endpoints": ["topic1"]}
parsed_rule = parse_kafka_methods(test_rule_as_dict)
assert parsed_rule == ["kafka.send.topic1"]

def test_parse_kafka_methods_as_str(self) -> None:
test_rule_as_str = ["send"]
parsed_rule = parse_kafka_methods(test_rule_as_str)
assert parsed_rule == ["kafka.send.*"]
1 change: 1 addition & 0 deletions tests/util/test_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_load_configuration_legacy(self, caplog: pytest.LogCaptureFixture) -> No
"redis.get",
"redis.type",
"dynamodb.query",
"kafka.send.*",
"kafka.consume.span-topic",
"kafka.consume.topic1",
"kafka.consume.topic2",
Expand Down
1 change: 1 addition & 0 deletions tests/util/test_configuration-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ com.instana.tracing:
dynamodb:
- query
kafka:
- send
- methods: ["consume", "send"]
endpoints: ["span-topic", "topic1", "topic2"]
- methods: ["consume"]
Expand Down
Loading