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,36 @@ def set_trace_configurations(self) -> None:
134134
135135 self .set_disable_trace_configurations ()
136136 self .set_stack_trace_configurations ()
137+ if "INSTANA_ALLOW_INTERNAL_SPANS" not in os .environ :
138+ self .add_internal_span_filter ()
139+
140+ def add_internal_span_filter (self ) -> None :
141+ if "exclude" not in self .span_filters :
142+ self .span_filters ["exclude" ] = []
143+ self .span_filters ["exclude" ].extend (
144+ [
145+ {
146+ "name" : "filter-internal-spans-by-url" ,
147+ "attributes" : [
148+ {
149+ "key" : "http.url" ,
150+ "values" : ["com.instana" ],
151+ "match_type" : "contains" ,
152+ }
153+ ],
154+ },
155+ {
156+ "name" : "filter-internal-spans-by-host" ,
157+ "attributes" : [
158+ {
159+ "key" : "http.host" ,
160+ "values" : ["com.instana" ],
161+ "match_type" : "contains" ,
162+ }
163+ ],
164+ },
165+ ]
166+ )
137167
138168 def _apply_env_stack_trace_config (self ) -> None :
139169 """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
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class TestBaseOptions:
2323 @pytest .fixture (autouse = True )
2424 def _resource (self ) -> Generator [None , None , None ]:
2525 self .base_options = None
26+ os .environ ["INSTANA_ALLOW_INTERNAL_SPANS" ] = "True"
2627 yield
2728 if "tracing" in config .keys ():
2829 del config ["tracing" ]
You can’t perform that action at this time.
0 commit comments