Skip to content
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

Regression: sys.exit(0) sets span error to SystemExit #4493

Closed
grihabor opened this issue Mar 18, 2025 · 0 comments · Fixed by #4494
Closed

Regression: sys.exit(0) sets span error to SystemExit #4493

grihabor opened this issue Mar 18, 2025 · 0 comments · Fixed by #4494
Labels
bug Something isn't working

Comments

@grihabor
Copy link
Contributor

grihabor commented Mar 18, 2025

Describe your environment

OS: (e.g, Ubuntu)
Python version: (e.g., Python 3.13.2)
SDK version: (e.g., 1.31.0)
API version: (e.g., 1.31.0)

What happened?

After upgrade from 1.30.0 to 1.31.0 this code started producing a span with SystemExit error:

with tracer.start_as_current_span("test-exit-code"):
    sys.exit(0)

Related to #4406

Steps to Reproduce

def main():
    resource = Resource(attributes={SERVICE_NAME: "test-exit-code"})
    tracerProvider = TracerProvider(resource=resource)
    stream = StringIO()
    processor = BatchSpanProcessor(ConsoleSpanExporter(out=stream))
    tracerProvider.add_span_processor(processor)
    trace.set_tracer_provider(tracerProvider)
    tracer = trace.get_tracer(__name__)
    try:
        with tracer.start_as_current_span("test-exit-code"):
            sys.exit(0)
    except SystemExit:
        pass

    while stream.getvalue() == "":
        time.sleep(0.5)

    span = json.loads(stream.getvalue())
    print(span)

Expected Result

  {
      "name": "test-exit-code",
      "context": {
          "trace_id": "0x644b4d5832f13a490133e4b44d72a476",
          "span_id": "0x34b0785025ce90ab",
          "trace_state": "[]"
      },
      "kind": "SpanKind.INTERNAL",
      "parent_id": null,
      "start_time": "2025-03-18T13:02:28.415717Z",
      "end_time": "2025-03-18T13:02:28.415733Z",
      "status": {
          "status_code": "UNSET"
      },
      "attributes": {},
      "events": [],
      "links": [],
      "resource": {
          "attributes": {
              "service.name": "test-exit-code"
          },
          "schema_url": ""
      }
  }

Actual Result

  {
      "name": "test-exit-code",
      "context": {
          "trace_id": "0xaa4145b80399a253002020b3afc45226",
          "span_id": "0xe492dbcd05893ead",
          "trace_state": "[]"
      },
      "kind": "SpanKind.INTERNAL",
      "parent_id": null,
      "start_time": "2025-03-18T13:03:48.253080Z",
      "end_time": "2025-03-18T13:03:48.254344Z",
      "status": {
          "status_code": "ERROR",
          "description": "SystemExit: 0"
      },
      "attributes": {},
      "events": [
          {
              "name": "exception",
              "timestamp": "2025-03-18T13:03:48.254331Z",
              "attributes": {
                  "exception.type": "SystemExit",
                  "exception.message": "0",
                  "exception.stacktrace": "Traceback (most recent call last):\n  File \"/home/grihabor/.cache/pants/named_caches/pex_root/venvs/1/s/7156ea6e/venv/lib/python3.11/site-packages/opentelemetry/ace/__init__.py\", line 587, in use_span\n    yield span\n  File \"/home/grihabor/.cache/pants/named_caches/pex_root/venvs/1/s/7156ea6e/venv/lib/python3.11/site-packages/opentelemetry/sdk/trace/__init__.\", line 1105, in start_as_current_span\n    yield span\n  File \"src/python/observability/otel/exit_test.py\", line 21, in test_exit_code\n    sys.exit(0)\nSystemExit: 0\n",
                  "exception.escaped": "False"
              }
          }
      ],
      "links": [],
      "resource": {
          "attributes": {
              "service.name": "test-exit-code"
          },
          "schema_url": ""
      }
  }

Additional context

No response

Would you like to implement a fix?

None

@grihabor grihabor added the bug Something isn't working label Mar 18, 2025
@grihabor grihabor changed the title Regression: sys.exit(1) sets span error to SystemExit Regression: sys.exit(0) sets span error to SystemExit Mar 18, 2025
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 a pull request may close this issue.

1 participant