Skip to content

Fix unexpected 'No active span' IllegalStateError #311

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 9 commits into from
Jun 13, 2023

Conversation

ZEALi
Copy link
Contributor

@ZEALi ZEALi commented Jun 2, 2023

The skywalking.trace.context.SpanContext.active_span() method has been refactored in v1.0.0. Its equivalent method has been changed to peek() . When peek() returns None, the active_span() method throws IllegalStateError exception directly.

This change is not backward compatible, SOME plugins that rely on the returned None value of active_span() WILL be broken ( sw_flask, sw_sanic, sw_tornado, sw_django, etc.).

For example, when running Flask by gunicorn which not monkey-patched as well as for sw_http_server plugin, calling get_context().active_span in _sw_handle_exception() will raise an IllegalStateError exception directly and break the original logic of the container's handle_exception() .

In v0.8.0, no exception was thrown, so the caller could check if entry_span is not None and perform further processing.

Therefore, I suggest retaining the behavioral pattern of the active_span() method in v0.8.0 , and providing parameters in the added peek() method to support scenarios where exceptions need to be thrown (such as in sw_logging / sw_loguru).

@kezhenxu94 kezhenxu94 requested a review from Superskyyy June 2, 2023 08:12
@kezhenxu94 kezhenxu94 added the bug Something isn't working label Jun 2, 2023
@kezhenxu94 kezhenxu94 added this to the 1.1.0 milestone Jun 2, 2023
@@ -83,7 +83,7 @@ def build_log_tags() -> LogTags:
# exceptions before any span is even created, just ignore these fields and
# avoid appending 'no active span' traceback that could be confusing.
# Or simply the log is generated outside any span context.
active_span_id = context.active_span.sid
active_span_id = context.peek(raise_if_none=True).sid
Copy link

Choose a reason for hiding this comment

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

5% of developers fix this issue

reportOptionalMemberAccess: "sid" is not a known member of "None"


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

@@ -79,7 +79,7 @@ def _sw_sink(message):
# exceptions before any span is even created, just ignore these fields and
# avoid appending 'no active span' traceback that could be confusing.
# Or simply the log is generated outside any span context.
active_span_id = context.active_span.sid
active_span_id = context.peek(raise_if_none=True).sid
Copy link

Choose a reason for hiding this comment

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

5% of developers fix this issue

reportOptionalMemberAccess: "sid" is not a known member of "None"


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

active_span = context.active_span
if active_span is not None:
active_span_id = active_span.sid
primary_endpoint_name = context.primary_endpoint.get_name()
Copy link

Choose a reason for hiding this comment

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

5% of developers fix this issue

reportOptionalMemberAccess: "get_name" is not a known member of "None"


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

active_span = context.active_span
if active_span is not None:
active_span_id = active_span.sid
primary_endpoint_name = context.primary_endpoint.get_name()
Copy link

Choose a reason for hiding this comment

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

5% of developers fix this issue

reportOptionalMemberAccess: "get_name" is not a known member of "None"


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

@Superskyyy
Copy link
Member

Good catch! Thanks for the fix.

@wu-sheng
Copy link
Member

CI fails, please fix them first.

@Superskyyy
Copy link
Member

Probably needs a full rerun, the old image got deleted last time.

@Superskyyy
Copy link
Member

Kafka cases are flaky, not related to this PR or agent functionalities, will fix.

@Superskyyy Superskyyy merged commit 788182f into apache:master Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants