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

Proposal: add possibility to get reconcileID from context #2055

Closed
zbindenren opened this issue Nov 22, 2022 · 5 comments
Closed

Proposal: add possibility to get reconcileID from context #2055

zbindenren opened this issue Nov 22, 2022 · 5 comments

Comments

@zbindenren
Copy link
Contributor

Currently the context is added to the log message as follows:

log := c.LogConstructor(&req)

log = log.WithValues("reconcileID", uuid.NewUUID())
ctx = logf.IntoContext(ctx, log)

There is no easy way to get the reconcileID.

Sometimes it would be great when you have access to the reconcile ID. For example: when communicating with third party services, it would be nice if we could send the corresponding reconsileID in order to add the possibility to match a request with a specific reconcileID.

I propose to introduce method like:

func ReconcileID(ctx context.Context) string {
...
}

to get the reconcileID from the current context. In order that this works, we had to change the above code to something like:

log := c.LogConstructor(&req)

reconcileID := uuid.NewUUID()
log = log.WithValues("reconcileID", reconcileID)

reconcileIDToContext(ctx, reconcileID)

ctx = logf.IntoContext(ctx, log)
@alvaroaleman
Copy link
Member

Sounds reasonable to me

@zbindenren
Copy link
Contributor Author

Great, I will make a PR.

@grzesuav
Copy link

@zbindenren why do not use NamespacedName as logger values ?

@alvaroaleman
Copy link
Member

Done in #2056

@zbindenren
Copy link
Contributor Author

Thx

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

3 participants