Skip to content

Commit

Permalink
Use datetime to parse CreatedDate instead of external dependency date…
Browse files Browse the repository at this point in the history
…util.
  • Loading branch information
asllop committed Dec 14, 2023
1 parent 0586cc1 commit 5263e37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Binary file modified requirements.txt
Binary file not shown.
12 changes: 7 additions & 5 deletions src/newrelic_logging/salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import sys
from datetime import datetime, timedelta
from dateutil.parser import parse
import jwt
from cryptography.hazmat.primitives import serialization

Expand Down Expand Up @@ -309,18 +308,21 @@ def is_logfile_response(self, records):
else:
return True

# TODO: Use alternative timestamp attribute to avoid API limits (48 hours old)
# TODO: Ensure NR API limits:
# - Use alternative timestamp attribute to avoid time limits (48h for Log API, 24h for Event API).
# - Check attribute key and value size limits (255 and 4094 bytes respectively).
# - Check max number of attributes per event (255).

def build_log_from_event(self, records):
log_entries = []
for record in records:
if 'CreatedDate' in record:
timestamp = int(parse(record['CreatedDate']).timestamp() * 1000)
timestamp = int(datetime.strptime(record['CreatedDate'], '%Y-%m-%dT%H:%M:%S.%f%z').timestamp() * 1000)
else:
timestamp = int(datetime.datetime.now().timestamp() * 1000)

log_entries.append({
#TODO: generate a meaningful message
#TODO: generate a meaningful message, maybe event type?
'message': "SF Event",
'attributes': record,
'timestamp': timestamp
Expand Down Expand Up @@ -402,7 +404,7 @@ def pack_csv_into_log(self, record, row_offset, csv_rows):
'log_entries': log_entries
}

# Slice CSV into smaller groups
# Slice CSV into smaller chunks
def extract_csv_slice(self, csv_rows):
part_rows = []
i = 0
Expand Down

0 comments on commit 5263e37

Please sign in to comment.