From 07342b68b0bbaed8ed5222d53787aa41aa9ebe68 Mon Sep 17 00:00:00 2001 From: Varsha GS Date: Mon, 26 Aug 2024 09:42:29 +0530 Subject: [PATCH] fix: handle suppression Signed-off-by: Varsha GS --- src/instana/propagators/base_propagator.py | 8 +++----- src/instana/tracer.py | 6 +++--- tests/frameworks/test_flask.py | 4 +--- tests/frameworks/test_wsgi.py | 1 - 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/instana/propagators/base_propagator.py b/src/instana/propagators/base_propagator.py index eb779d1d..3e4fcdc8 100644 --- a/src/instana/propagators/base_propagator.py +++ b/src/instana/propagators/base_propagator.py @@ -181,8 +181,6 @@ def __determine_span_context( correlation = True ( - ctx_trace_id, - ctx_span_id, ctx_level, ctx_synthetic, ctx_trace_parent, @@ -192,9 +190,11 @@ def __determine_span_context( ctx_correlation_id, ctx_traceparent, ctx_tracestate, - ) = [None] * 11 + ) = [None] * 9 ctx_level = self._get_ctx_level(level) + ctx_trace_id = trace_id + ctx_span_id = span_id if ( trace_id @@ -204,8 +204,6 @@ def __determine_span_context( ): # ctx.trace_id = trace_id[-16:] # only the last 16 chars # ctx.span_id = span_id[-16:] # only the last 16 chars - ctx_trace_id = trace_id - ctx_span_id = span_id ctx_synthetic = synthetic # if len(trace_id) > 16: diff --git a/src/instana/tracer.py b/src/instana/tracer.py index 5f08f729..a5bdf895 100644 --- a/src/instana/tracer.py +++ b/src/instana/tracer.py @@ -120,10 +120,10 @@ def start_span( ) -> InstanaSpan: parent_context = span_context if span_context else get_current_span().get_span_context() - if parent_context is not None and not isinstance(parent_context, SpanContext): + if parent_context and not isinstance(parent_context, SpanContext): raise TypeError("parent_context must be an Instana SpanContext or None.") - if parent_context is not None and not parent_context.is_valid: + if parent_context and not parent_context.is_valid and not parent_context.suppression: # We probably have an INVALID_SPAN_CONTEXT. parent_context = None @@ -213,7 +213,7 @@ def _add_stack(self, span: InstanaSpan, limit: Optional[int] = 30) -> None: def _create_span_context(self, parent_context: SpanContext) -> SpanContext: """Creates a new SpanContext based on the given parent context.""" - if parent_context is not None and parent_context.trace_id is not None: + if parent_context and parent_context.is_valid: trace_id = parent_context.trace_id span_id = generate_id() trace_flags = parent_context.trace_flags diff --git a/tests/frameworks/test_flask.py b/tests/frameworks/test_flask.py index da1fd3c2..145d0e33 100644 --- a/tests/frameworks/test_flask.py +++ b/tests/frameworks/test_flask.py @@ -191,7 +191,6 @@ def test_get_request_with_query_params(self) -> None: # We should NOT have a path template for this route assert wsgi_span.data["http"]["path_tpl"] is None - @unittest.skip("Suppression is not yet handled") def test_get_request_with_suppression(self) -> None: headers = {'X-INSTANA-L':'0'} response = self.http.urlopen('GET', testenv["flask_server"] + '/', headers=headers) @@ -213,7 +212,7 @@ def test_get_request_with_suppression(self) -> None: # Assert that there are no spans in the recorded list assert spans == [] - @unittest.skip("Suppression is not yet handled") + @unittest.skip("Handled when type of trace and span ids are modified to str") def test_get_request_with_suppression_and_w3c(self) -> None: headers = { 'X-INSTANA-L':'0', @@ -239,7 +238,6 @@ def test_get_request_with_suppression_and_w3c(self) -> None: # Assert that there are no spans in the recorded list assert spans == [] - @unittest.skip("Synthetic requests are not yet handled") def test_synthetic_request(self) -> None: headers = { 'X-INSTANA-SYNTHETIC': '1' diff --git a/tests/frameworks/test_wsgi.py b/tests/frameworks/test_wsgi.py index 186d84f7..7e9f3484 100644 --- a/tests/frameworks/test_wsgi.py +++ b/tests/frameworks/test_wsgi.py @@ -86,7 +86,6 @@ def test_get_request(self) -> None: assert wsgi_span.data["http"]["error"] is None assert wsgi_span.stack is None - @pytest.mark.skip("Suppression is not yet handled") def test_synthetic_request(self) -> None: headers = { 'X-INSTANA-SYNTHETIC': '1'