import os
import sentry_sdk

sentry_sdk.init(dsn=os.environ["SENTRY_DSN"], traces_sample_rate=1.0,
                enable_logs=True, send_default_pii=False)
with sentry_sdk.start_transaction(name="railway-example", op="task"):
    with sentry_sdk.start_span(op="work", description="child span"):
        sentry_sdk.logger.info("Railway structured log from Python")
        try:
            raise RuntimeError("Railway error example from Python")
        except RuntimeError:
            sentry_sdk.capture_exception()


def check_flush(pending, timeout):
    raise RuntimeError("Telemetry flush timed out")


sentry_sdk.flush(timeout=30, callback=check_flush)
print("SDK flush completed; verify Issues, Logs, and Traces")
