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

[receiver/awsfirehosereceiver] Fix timestamp in cwlogs #36122

Merged
merged 3 commits into from
Nov 20, 2024

Conversation

kaiyan-sheng
Copy link
Contributor

Description

When testing ingesting json format logs from CloudWatch log groups using Firehose, I see the timestamp field has been populated wrong. For example the timestamp for the log message I ingested should be 2024-10-23T21:28:49.707 but I'm getting a timestamp from 1970-01-01T00:28:49.707Z.

{
  "cloud": {
      "account": {
        "id": "123456789012"
      }
    },
    "agent": {
      "name": "otlp",
      "version": "unknown"
    },
    "@timestamp": "1970-01-01T00:28:49.707Z",
    "log": {},
    "data_stream": {
      "namespace": "default",
      "type": "logs",
      "dataset": "apm.app.unknown"
    },
    "service": {
      "environment": "unset",
      "name": "unknown",
      "language": {
        "name": "unknown"
      }
    },
    "event": {},
    "message": "test-1",
    "labels": {
      "aws_cloudwatch_log_stream_name": "test-log-stream",
      "aws_cloudwatch_log_group_name": "test-cloudwatch-logs-ks"
    }
  }
}

This issue is caused by pcommon.Timestamp is a time specified as UNIX Epoch time in nanoseconds but timestamp in cloudwatch logs are in milliseconds. So converting the timestamp from milliseconds to nanoseconds is needed.

Testing

Added unit test.

@kaiyan-sheng kaiyan-sheng changed the title [receiver/awsfirehosereceiver] Fix timestamp in cwlog [receiver/awsfirehosereceiver] Fix timestamp in cwlogs Oct 31, 2024
@gavincabbage
Copy link
Contributor

Thanks for catching and fixing my mistake! Looks like the original metrics code handles this as well.

@dashpole
Copy link
Contributor

@Aneurysm9 would be good to get your review as the codeowner

@ChrsMark ChrsMark added ready to merge Code review completed; ready to merge by maintainers and removed waiting-for-code-owners labels Nov 20, 2024
@bogdandrutu bogdandrutu added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Nov 20, 2024
@bogdandrutu bogdandrutu merged commit 15ddc29 into open-telemetry:main Nov 20, 2024
189 checks passed
@github-actions github-actions bot added this to the next release milestone Nov 20, 2024
sbylica-splunk pushed a commit to sbylica-splunk/opentelemetry-collector-contrib that referenced this pull request Dec 17, 2024
…y#36122)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

When testing ingesting json format logs from CloudWatch log groups using
Firehose, I see the timestamp field has been populated wrong. For
example the timestamp for the log message I ingested should be
`2024-10-23T21:28:49.707` but I'm getting a timestamp from
`1970-01-01T00:28:49.707Z`.

```
{
  "cloud": {
      "account": {
        "id": "123456789012"
      }
    },
    "agent": {
      "name": "otlp",
      "version": "unknown"
    },
    "@timestamp": "1970-01-01T00:28:49.707Z",
    "log": {},
    "data_stream": {
      "namespace": "default",
      "type": "logs",
      "dataset": "apm.app.unknown"
    },
    "service": {
      "environment": "unset",
      "name": "unknown",
      "language": {
        "name": "unknown"
      }
    },
    "event": {},
    "message": "test-1",
    "labels": {
      "aws_cloudwatch_log_stream_name": "test-log-stream",
      "aws_cloudwatch_log_group_name": "test-cloudwatch-logs-ks"
    }
  }
}
```

This issue is caused by `pcommon.Timestamp` is a time specified as UNIX
Epoch time in nanoseconds but timestamp in cloudwatch logs are in
milliseconds. So converting the timestamp from milliseconds to
nanoseconds is needed.

#### Testing

Added unit test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Code review completed; ready to merge by maintainers receiver/awsfirehose Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants