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

Add a way to log errors within the function #143

Closed
chaitanyakolluru opened this issue Jun 3, 2024 · 3 comments
Closed

Add a way to log errors within the function #143

chaitanyakolluru opened this issue Jun 3, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@chaitanyakolluru
Copy link

chaitanyakolluru commented Jun 3, 2024

What problem are you facing?

Logger for functions defined here is setup to proxy logger defined in crossplane-runtime here, which only allows logging Info and Debug level logs as function logs. As RunFunction is only expected to append errors as Results to RunFunctionResponse and that it never returns an error even when we add a fatal result to the RunFunctionResponse,
outside of looking at XRs status we don't have a means to log those errors on the function.

How could Crossplane help solve your problem?

The solution suggested would involve setting up a FnLogger interface with Error() added and an implementation to invoke logger's Error() method to log errors.
Please find the proposed changes here.

@negz
Copy link
Member

negz commented Jun 3, 2024

What's the benefit of a dedicated Error method on the logger? Why not log errors at Info or Debug as appropriate, e.g.:

log.Info("Something went wrong", "error", err)

@chaitanyakolluru
Copy link
Author

chaitanyakolluru commented Jun 3, 2024

i) Better and clearer syntax when logging an error. As an example:

Assuming xrMetadata is keys and values holding xr metadata information,
with Info:

        ...
  	log.Info(msg, xrMetadata...)
	response.Fatal(rsp, errors.New(msg))

	return rsp, nil

where xrMetadata needs to now include ["error", error]

vs with Error:

        ...
	log.Error(incomingErr, msg, xrMetadata...)
	response.Fatal(rsp, errors.New(msg))

	return rsp, nil

where xrMetadata can simply be xr metadata.

ii) Error spits out stacktrace by default without any other changes to the way logger is setup:

{"level":"error","ts":"2024-06-03T21:12:26Z","logger":"fn-name","msg":"failed message", KeysAndValues..., "stacktrace":"stacktrace\n"}
{"level":"info","ts":"2024-06-03T21:12:26Z","logger":"fn-name","msg":"failed message", KeysAndValues...}

iii) Also, seeing that, per function development convention, functions will never return an error, (rsp, nil) with error details added as a Result within rsp, I think it makes sense for us to have a dedicated Error method on fn's logger (not Crossplane-runtime's) to indicate that developers can log error states outside of setting Result on RunFunctionResponse.

It is workable with Info(), but think it would be cleaner with a dedicated Error method on the Logger interface.

@chaitanyakolluru
Copy link
Author

Emitting logs using Info method does seem favorable seeing that we don't need the stacktrace and that we can include error metadata within keysAndValues. Closing this issue.

@chaitanyakolluru chaitanyakolluru closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants