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

Capture htmx logs and send to backend - integrate with Aspire #15

Open
egil opened this issue Apr 20, 2024 · 4 comments
Open

Capture htmx logs and send to backend - integrate with Aspire #15

egil opened this issue Apr 20, 2024 · 4 comments

Comments

@egil
Copy link
Owner

egil commented Apr 20, 2024

Make it possible to enable log capture from htmx via a config option, which will send the logs to the server, which can then share it with e.g. an Aspire dashboard or just output the logs along with the back end logs.

https://htmx.org/api/#logger

@khalidabuhakmeh
Copy link

This might not be a good idea. 😅

As you'd expect, an HTMX-powered UI has a lot of events. This is from a single button click.

Arc -2024-05-29 -11-30-40

Also, most of the information you get in these log messages is recursive by nature (think DOM elements), so it's very difficult to serialize this data. This leads you to being very selective as to what you send back.

<script type="module">
    // Write your JavaScript code.
    htmx.logger = function (elt, event, data) {
        const payload = {
            event: event, // string
            data: {
                page: window.location.href,
                element: data.elt.nodeName
            }
        }
    
        console.log(payload)
    
        fetch('/__htmx_log', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(payload)
        })
        .catch()
    }
</script>

It might be better to leave the debugging to the client.

@egil
Copy link
Owner Author

egil commented May 29, 2024

Guessed it's pretty loud, and yeah, I only think this would be something that should be used during development. But I think it would be neat to have logs show up in e.g., the aspire dashboard for easy consumption.

It's definitely a nice to have 😊

@khalidabuhakmeh
Copy link

Well, the web requests definitely would since they should have the correlation id attached to them. Is that what you're thinking?

@egil
Copy link
Owner Author

egil commented May 29, 2024

Have not thought deeply about it. But yes, something like that sounds right.

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

No branches or pull requests

2 participants