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

Multiple issues while changing the timestamp of a log #542

Closed
simranchanna opened this issue May 2, 2022 · 5 comments
Closed

Multiple issues while changing the timestamp of a log #542

simranchanna opened this issue May 2, 2022 · 5 comments
Assignees
Labels
2023-triage api: logging Issues related to the googleapis/python-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@simranchanna
Copy link

I've tried several methods to change the timestamp of a log being sent to cloud logging, but there are a few problems:

  1. I'm able to send data only in the past and not in the future while using API directly - (whereas according to the documentation https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write the timestamp value can be maximum 24 hours in the future)

  2. I'm passing the timestamp value while calling the struct_log method and that timestamp is passed internally in the library functions to where API is called, but that doesn't work at all and as a result, no log is created.

@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/python-logging API. label May 2, 2022
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels May 2, 2022
@arbrown arbrown added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels May 17, 2022
@yoshi-automation yoshi-automation removed the 🚨 This issue needs some love. label May 17, 2022
@arbrown arbrown assigned daniel-sanche and unassigned arbrown Jun 30, 2022
@daniel-sanche
Copy link
Contributor

daniel-sanche commented Oct 17, 2022

Hey @simranchanna , could you give a code snippet so I can see how you're calling the library, how you're formatting the timestamp, and how you're viewing the logs? I just tried to reproduce this, but it seems to be working for me:

import datetime

client = google.cloud.logging.Client()
logger = client.logger(log_name)
timestamp = datetime.datetime.now() + datetime.timedelta(minutes=1)
logger.log_struct({"hello":"world", timestamp=timestamp)

I noticed the log doesn't appear in the Log Explorer until the time denoted in the timestamp, so that may be why it appears that no log is created. But let me know if you're seeing something different

@daniel-sanche daniel-sanche added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. logging-resilience labels Oct 18, 2022
@lmesz
Copy link

lmesz commented Dec 10, 2022

Hey @daniel-sanche,

I tried a little modified version of your code:

from google.cloud import logging
log_name="onetwo"

client = logging.Client()
logger = client.logger(log_name)
timestamp = datetime.datetime.now() - datetime.timedelta(minutes=1)
print(timestamp)
logger.log_struct({"hello":"world", "message": "appletree"}, timestamp=timestamp)

I tried to see the sent logs in Logs Explorer and in the given log but didn't see any. I am in CET timezone and the Logs Explorer is set to this timezone as well.
Can you give me some hint either how to debug further or what I am doing wrong?
Thank you

@daniel-sanche
Copy link
Contributor

Nothing you're doing stands out as wrong to me. To help debug: can you show me what filters you're using in log explorer and what GCP environment you're running the code on? Do you see any logs if you omit the timestamp changes?

@lmesz
Copy link

lmesz commented Dec 15, 2022

Yeah I saw logs when I omitted the timestamp field.
Figured out the problem was how the datetime was set to timestamp field.
I needed to change
from timestamp = datetime.datetime.now() - datetime.timedelta(minutes=1)
to timestamp = (datetime.datetime.now() - datetime.timedelta(minutes=1)).astimezone()

@daniel-sanche
Copy link
Contributor

Ok great, glad you got it working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2023-triage api: logging Issues related to the googleapis/python-logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants