Skip to content

Conversation

@sgoral-splunk
Copy link
Contributor

this feature adds exception logging functionality

Copy link
Member

@artemrys artemrys left a comment

Choose a reason for hiding this comment

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

This is what I got during my testing:

    def stream_events(self, inputs, event_writer):
        for input_name, input_item in inputs.inputs.items():
            normalized_input_name = input_name.split("/")[-1]
            logger = logger_for_input(normalized_input_name)
            try:
                session_key = self._input_definition.metadata["session_key"]
                log_level = conf_manager.get_log_level(
                    logger=logger,
                    session_key=session_key,
                    app_name=ADDON_NAME,
                    conf_name=f"{ADDON_NAME}_settings",
                )
                logger.setLevel(log_level)
                log.modular_input_start(logger, normalized_input_name)
                data = get_data_from_api(logger, "hello world")
                sourcetype = "dummy-data"
                for line in data:
                    event_writer.write_event(
                        smi.Event(
                            data=json.dumps(line, ensure_ascii=False, default=str),
                            index=input_item.get("index"),
                            sourcetype=sourcetype,
                        )
                    )
                raise ValueError("throwing a random exception out of nowhere")
                log.events_ingested(
                    logger, normalized_input_name, sourcetype, len(data)
                )
                log.modular_input_end(logger, normalized_input_name)
            except Exception as e:
                log.log_exception(
                    logger,
                    e,
                    msg_before="Exception raised while ingesting data for ",
                    log_level=logging.ERROR,
                )
image

That error log message should be shown as one line?

@sgoral-splunk
Copy link
Contributor Author

that's odd, because it worked for me every time and it looks like this:
image
I will try to reproduce the error

@artemrys artemrys merged commit 44e35c4 into develop Jan 30, 2024
@artemrys artemrys deleted the feat/ADDON_67614_log_exceptions branch January 30, 2024 11:21
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2024
@srv-rr-github-token
Copy link
Contributor

🎉 This PR is included in version 4.13.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@srv-rr-github-token
Copy link
Contributor

🎉 This PR is included in version 4.13.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants