Skip to content

Add formatted logging for hyperdrive crash reports.#636

Merged
sentilesdal merged 18 commits intomainfrom
matt-improve-error-logging
Jul 6, 2023
Merged

Add formatted logging for hyperdrive crash reports.#636
sentilesdal merged 18 commits intomainfrom
matt-improve-error-logging

Conversation

@sentilesdal
Copy link
Copy Markdown
Contributor

@sentilesdal sentilesdal commented Jul 6, 2023

This PR adds some crash logging capabilities for hyperdrive. In addition, setup_logging was refactored and tested, as was format_float_as_string. In order to add hyperdrive crash logging, you would just add the line below any setup_logging call:

setup_logging()
# add this line
setup_hyperdrive_crash_report_logging()

then, when logging errors, you'd also add a call to log_hyperdrive_crash_report:

    except TransactionError as err:
        formatted_amount = format_utils.format_float_as_string(amount)
        pool_info = hyperdrive_contract.getPoolInfo()
        pool_config = hyperdrive_contract.getPoolConfig()
        logging.error(
            "Failed to execute %s: %s\n => Amount: %s\n => Agent: %s\n => Pool: %s",
            trade_type,
            err,
            formatted_amount,
            agent,
            dict(pool_info),
        )
        # add this!
        log_hyperdrive_crash_report(
            amount=amount,
            trade_type=trade_type,
            error=err,
            agent_address=agent.address,
            pool_info=pool_info,
            pool_config=pool_config,
        )
        raise err

this will get you logs to .logging/hyperdrive_test_crash_report.log that look like this:

23-07-06 12:21:01: CRITICAL: logs.log_hyperdrive_crash_report:
Failed to execute CLOSE_LONG: Message
 Amount: 1.23
 Agent: 0x0000000000000000000000000000000000000000
 PoolInfo: {
    "blockNumber": 1234,
    "timestamp": 12345678,
    "shareReserves": null,
    "bondReserves": null,
    "lpTotalSupply": null,
    "sharePrice": null,
    "longsOutstanding": null,
    "longAverageMaturityTime": null,
    "shortsOutstanding": null,
    "shortAverageMaturityTime": null,
    "shortBaseVolume": null,
    "withdrawalSharesReadyToWithdraw": null,
    "withdrawalSharesProceeds": null
}
 PoolConfig: {
    "contractAddress": "0x0000000000000000000000000000000000000000",
    "baseToken": null,
    "initializeSharePrice": null,
    "positionDuration": null,
    "checkpointDuration": null,
    "timeStretch": null,
    "governance": null,
    "feeCollector": null,
    "curveFee": null,
    "flatFee": null,
    "governanceFee": null,
    "oracleSize": null,
    "updateGap": null,
    "invTimeStretch": null,
    "termLength": null
}

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
elf-simulations ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 6, 2023 10:00pm

@sentilesdal sentilesdal requested review from dpaiton and slundqui July 6, 2023 19:27
Comment thread elfpy/utils/outputs.py Outdated
Comment thread elfpy/utils/logs.py Outdated
Copy link
Copy Markdown

@slundqui slundqui left a comment

Choose a reason for hiding this comment

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

Looks great!

@sentilesdal sentilesdal marked this pull request as ready for review July 6, 2023 21:45
@sentilesdal sentilesdal merged commit 076dc46 into main Jul 6, 2023
@sentilesdal sentilesdal deleted the matt-improve-error-logging branch July 6, 2023 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants