Skip to content

Commit

Permalink
Add instrumentation attributes to each data point.
Browse files Browse the repository at this point in the history
  • Loading branch information
asllop committed Feb 2, 2024
1 parent a25b0cf commit 43d9985
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CHANGELOG
All notable changes to this project will be documented in this file.

## [1.0.0] - 2024/02/01
## [1.0.0] - 2024/02/02
### Add
- Accept arbitrary event log queries.
- Accept queries of any type of event, not only event logs.
Expand All @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- Configure the SF API version to use.
- Configure the NR eventType to report.
- Dynamic SOQL query generation.
- Instrumentation attributes.
### Update
- Improve NR API interaction.
- Improve cache (redis) usage.
Expand Down
2 changes: 1 addition & 1 deletion src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from yaml import Loader, load
from newrelic_logging.env import get_var, var_exists
from newrelic_logging.integration import Integration
from newrelic_logging.telemetry import print_info, print_warn, print_err
from newrelic_logging.telemetry import print_info, print_warn

config_dir = None
argv = sys.argv[1:]
Expand Down
6 changes: 6 additions & 0 deletions src/newrelic_logging/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Integration definitions

VERSION = "1.0.0"
NAME = "salesforce-eventlogfile"
PROVIDER = "newrelic-labs"
COLLECTOR_NAME = "newrelic-logs-salesforce-eventlogfile"
4 changes: 2 additions & 2 deletions src/newrelic_logging/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .salesforce import SalesForce, SalesforceApiException, DataCache
from .env import AuthEnv
from enum import Enum
from .telemetry import Telemetry, print_info, print_err, print_warn
from .telemetry import Telemetry, print_info, print_err

class DataFormat(Enum):
LOGS = 1
Expand Down Expand Up @@ -61,9 +61,9 @@ def __init__(self, config, event_type_fields_mapping, initial_delay):
account_id = newrelic_config['account_id']
else:
account_id = auth_env.get_account_id()
NewRelic.set_api_endpoint(newrelic_config['api_endpoint'], account_id)

NewRelic.set_logs_endpoint(newrelic_config['api_endpoint'])
NewRelic.set_api_endpoint(newrelic_config['api_endpoint'], account_id)

def run(self):
sfdc_session = new_retry_session()
Expand Down
19 changes: 18 additions & 1 deletion src/newrelic_logging/newrelic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import gzip
import json
from .telemetry import Telemetry, print_info, print_err, print_warn
from .telemetry import print_info, print_err
from requests import RequestException
from newrelic_logging import VERSION, NAME, PROVIDER, COLLECTOR_NAME

class NewRelicApiException(Exception):
pass
Expand All @@ -25,6 +26,15 @@ class NewRelic:

@classmethod
def post_logs(cls, session, data):
# Append integration attributes
for log in data[0]['logs']:
if not 'attributes' in log:
log['attributes'] = {}
log['attributes']['instrumentation.name'] = NAME
log['attributes']['instrumentation.provider'] = PROVIDER
log['attributes']['instrumentation.version'] = VERSION
log['attributes']['collector.name'] = COLLECTOR_NAME

json_payload = json.dumps(data).encode()

# print("----- POST DATA (LOGS) -----")
Expand Down Expand Up @@ -52,6 +62,13 @@ def post_logs(cls, session, data):

@classmethod
def post_events(cls, session, data):
# Append integration attributes
for event in data:
event['instrumentation.name'] = NAME
event['instrumentation.provider'] = PROVIDER
event['instrumentation.version'] = VERSION
event['collector.name'] = COLLECTOR_NAME

json_payload = json.dumps(data).encode()

# print("----- POST DATA (EVENTS) -----")
Expand Down
2 changes: 1 addition & 1 deletion src/newrelic_logging/salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import hashlib
from .env import Auth, AuthEnv
from .query import Query, substitute
from .telemetry import Telemetry, print_info, print_err, print_warn
from .telemetry import print_info, print_err

class LoginException(Exception):
pass
Expand Down

0 comments on commit 43d9985

Please sign in to comment.