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

Precision of timestampNanos in logs is miliseconds instead of nanoseconds #1996

Closed
rafal-dudek opened this issue Jul 5, 2023 · 1 comment · Fixed by #2012 or #2005
Closed

Precision of timestampNanos in logs is miliseconds instead of nanoseconds #1996

rafal-dudek opened this issue Jul 5, 2023 · 1 comment · Fixed by #2012 or #2005

Comments

@rafal-dudek
Copy link

Describe the bug
StackdriverJsonLayout sets value of 'timestampNanos' log field as
TimeUnit.MILLISECONDS.toNanos(event.getTimeStamp() % 1_000) which has precision of miliseconds.
https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-logging/src/main/java/com/google/cloud/spring/logging/StackdriverJsonLayout.java#L276
Proper value should be event.getNanoseconds()

This is causing out-of-order logs in GCP Logs Explorer in some cases.

Sample

    Logger log = LoggerFactory.getLogger(GenericSpringBootApplication.class);
    log.info("1");
    log.info("2");
    log.info("3");
    log.info("4");
    log.info("5");

Result in kubectl logs:

{"timestampSeconds":1688547662,"timestampNanos":662000000,"severity":"INFO","thread":"scheduling-1","message":"1"}
{"timestampSeconds":1688547662,"timestampNanos":663000000,"severity":"INFO","thread":"scheduling-1","message":"2"}
{"timestampSeconds":1688547662,"timestampNanos":663000000,"severity":"INFO","thread":"scheduling-1","message":"3"}
{"timestampSeconds":1688547662,"timestampNanos":663000000,"severity":"INFO","thread":"scheduling-1","message":"4"}
{"timestampSeconds":1688547662,"timestampNanos":663000000,"severity":"INFO","thread":"scheduling-1","message":"5"}

Result in GCP Logs Explorer:
image

@meltsufin
Copy link
Member

Would you mind submitted a fix?

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