Skip to content
Open
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
18 changes: 1 addition & 17 deletions src/instana/instrumentation/urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,7 @@ def urlopen_with_instana(
tracer, parent_span, span_name = get_tracer_tuple()

# If we're not tracing, just return; boto3 has it's own visibility
# Also, skip creating spans for internal Instana calls when
# 'com.instana' appears in either the full URL, the path argument,
# or the connection host.
request_url_or_path = (
kwargs.get("request_url")
or kwargs.get("url")
or (args[1] if len(args) >= 2 else "")
or ""
)
host = getattr(instance, "host", "") or ""

if (
not tracer
or span_name == "boto3"
or "com.instana" in request_url_or_path
or "com.instana" in host
):
if not tracer or span_name == "boto3":
return wrapped(*args, **kwargs)

parent_context = parent_span.get_span_context() if parent_span else None
Expand Down
29 changes: 29 additions & 0 deletions src/instana/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ def set_trace_configurations(self) -> None:

self.set_disable_trace_configurations()
self.set_stack_trace_configurations()
self._add_instana_agent_span_filter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing it better, I think you must keep the same mindset as before.

Instead of calling the (previously requested by me) _add_instana_agent_span_filter() function, call a set_span_filter_configurations() and this one must call the _add_instana_agent_span_filter() . Just follow the lead of the other "set_*_configurations" functions.


def _add_instana_agent_span_filter(self) -> None:
if "exclude" not in self.span_filters:
self.span_filters["exclude"] = []
self.span_filters["exclude"].extend(
[
{
"name": "filter-internal-spans-by-url",
"attributes": [
{
"key": "http.url",
"values": ["com.instana"],
"match_type": "contains",
}
],
},
{
"name": "filter-internal-spans-by-host",
"attributes": [
{
"key": "http.host",
"values": ["com.instana"],
"match_type": "contains",
}
],
},
]
)

def _apply_env_stack_trace_config(self) -> None:
"""Apply stack trace configuration from environment variables."""
Expand Down
8 changes: 4 additions & 4 deletions src/instana/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def parse_filtered_endpoints_string(params: Union[str, os.PathLike]) -> List[str
return span_filters


def parse_filtered_endpoints_dict(filter_dict: dict[str, Any]) -> dict[str, list[Any]]:
def parse_filtered_endpoints_dict(filter_dict: Dict[str, Any]) -> Dict[str, List[Any]]:
"""
Parses 'exclude' and 'include' blocks from the filter dict.

Expand Down Expand Up @@ -134,7 +134,7 @@ def parse_filtered_endpoints_dict(filter_dict: dict[str, Any]) -> dict[str, list

def parse_filtered_endpoints(
params: Union[Dict[str, Any], str],
) -> Union[List[str], dict[str, list[Any]]]:
) -> Union[List[str], Dict[str, List[Any]]]:
"""
Parses input to prepare a list for ignored endpoints.

Expand All @@ -157,7 +157,7 @@ def parse_filtered_endpoints(

def parse_filtered_endpoints_from_yaml(
file_path: str,
) -> Union[List[str], dict[str, list[Any]]]:
) -> Union[List[str], Dict[str, List[Any]]]:
"""
Parses configuration yaml file and prepares a list of ignored endpoints.

Expand All @@ -175,7 +175,7 @@ def parse_filtered_endpoints_from_yaml(
span_filters = parse_filtered_endpoints(span_filters_dict)
return span_filters
else:
return []
return {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "default" return of parse_filtered_endpoints() is a list, so I think it's interesting to keep the same here.



def parse_span_filter_env_vars() -> Dict[str, List[Any]]:
Expand Down
17 changes: 11 additions & 6 deletions tests/clients/test_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,12 +1006,15 @@ def test_internal_span_creation_with_url_in_hostname(self) -> None:

spans = self.recorder.queued_spans()

assert len(spans) == 1
assert len(spans) == 2

filtered_spans = agent.filter_spans(spans)
assert len(filtered_spans) == 1

test_span = spans[0]
test_span = filtered_spans[0]
assert test_span.data["sdk"]["name"] == "test"

urllib3_spans = [span for span in spans if span.n == "urllib3"]
urllib3_spans = [span for span in filtered_spans if span.n == "urllib3"]
assert len(urllib3_spans) == 0

def test_internal_span_creation_with_url_in_path(self) -> None:
Expand All @@ -1024,11 +1027,13 @@ def test_internal_span_creation_with_url_in_path(self) -> None:
pass

spans = self.recorder.queued_spans()
assert len(spans) == 2

assert len(spans) == 1
filtered_spans = agent.filter_spans(spans)
assert len(filtered_spans) == 1

test_span = spans[0]
test_span = filtered_spans[0]
assert test_span.data["sdk"]["name"] == "test"

urllib3_spans = [span for span in spans if span.n == "urllib3"]
urllib3_spans = [span for span in filtered_spans if span.n == "urllib3"]
assert len(urllib3_spans) == 0
Loading
Loading