File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,23 +94,7 @@ def urlopen_with_instana(
9494 tracer , parent_span , span_name = get_tracer_tuple ()
9595
9696 # If we're not tracing, just return; boto3 has it's own visibility
97- # Also, skip creating spans for internal Instana calls when
98- # 'com.instana' appears in either the full URL, the path argument,
99- # or the connection host.
100- request_url_or_path = (
101- kwargs .get ("request_url" )
102- or kwargs .get ("url" )
103- or (args [1 ] if len (args ) >= 2 else "" )
104- or ""
105- )
106- host = getattr (instance , "host" , "" ) or ""
107-
108- if (
109- not tracer
110- or span_name == "boto3"
111- or "com.instana" in request_url_or_path
112- or "com.instana" in host
113- ):
97+ if not tracer or span_name == "boto3" :
11498 return wrapped (* args , ** kwargs )
11599
116100 parent_context = parent_span .get_span_context () if parent_span else None
Original file line number Diff line number Diff line change @@ -134,6 +134,35 @@ def set_trace_configurations(self) -> None:
134134
135135 self .set_disable_trace_configurations ()
136136 self .set_stack_trace_configurations ()
137+ self ._add_instana_agent_span_filter ()
138+
139+ def _add_instana_agent_span_filter (self ) -> None :
140+ if "exclude" not in self .span_filters :
141+ self .span_filters ["exclude" ] = []
142+ self .span_filters ["exclude" ].extend (
143+ [
144+ {
145+ "name" : "filter-internal-spans-by-url" ,
146+ "attributes" : [
147+ {
148+ "key" : "http.url" ,
149+ "values" : ["com.instana" ],
150+ "match_type" : "contains" ,
151+ }
152+ ],
153+ },
154+ {
155+ "name" : "filter-internal-spans-by-host" ,
156+ "attributes" : [
157+ {
158+ "key" : "http.host" ,
159+ "values" : ["com.instana" ],
160+ "match_type" : "contains" ,
161+ }
162+ ],
163+ },
164+ ]
165+ )
137166
138167 def _apply_env_stack_trace_config (self ) -> None :
139168 """Apply stack trace configuration from environment variables."""
Original file line number Diff line number Diff line change @@ -1006,12 +1006,15 @@ def test_internal_span_creation_with_url_in_hostname(self) -> None:
10061006
10071007 spans = self .recorder .queued_spans ()
10081008
1009- assert len (spans ) == 1
1009+ assert len (spans ) == 2
1010+
1011+ filtered_spans = agent .filter_spans (spans )
1012+ assert len (filtered_spans ) == 1
10101013
1011- test_span = spans [0 ]
1014+ test_span = filtered_spans [0 ]
10121015 assert test_span .data ["sdk" ]["name" ] == "test"
10131016
1014- urllib3_spans = [span for span in spans if span .n == "urllib3" ]
1017+ urllib3_spans = [span for span in filtered_spans if span .n == "urllib3" ]
10151018 assert len (urllib3_spans ) == 0
10161019
10171020 def test_internal_span_creation_with_url_in_path (self ) -> None :
@@ -1024,11 +1027,13 @@ def test_internal_span_creation_with_url_in_path(self) -> None:
10241027 pass
10251028
10261029 spans = self .recorder .queued_spans ()
1030+ assert len (spans ) == 2
10271031
1028- assert len (spans ) == 1
1032+ filtered_spans = agent .filter_spans (spans )
1033+ assert len (filtered_spans ) == 1
10291034
1030- test_span = spans [0 ]
1035+ test_span = filtered_spans [0 ]
10311036 assert test_span .data ["sdk" ]["name" ] == "test"
10321037
1033- urllib3_spans = [span for span in spans if span .n == "urllib3" ]
1038+ urllib3_spans = [span for span in filtered_spans if span .n == "urllib3" ]
10341039 assert len (urllib3_spans ) == 0
You can’t perform that action at this time.
0 commit comments