Skip to content

Commit

Permalink
update API_KEY variable, README
Browse files Browse the repository at this point in the history
  • Loading branch information
khpeet committed Apr 19, 2023
1 parent bde51fe commit ec5d5be
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 34 deletions.
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ Now, you can monitor your Github Actions with New Relic using Github Actions New
You will be able to:

- Visualise key metrics on your Github Actions, such as how long your workflow/jobs/steps are taking, how often they are failing.
- Visualise workflows/jobs and steps as distributed traces with logs in context
- Visualise workflows/jobs and steps as distributed traces with logs in context, reported to an OTEL service entity with New Relic
- Pinpoint where issues are coming from in your workflows
- Create alerts on your workflows.

## How to

## How to

Configuring the exporter

Before setting up the integration, you will need a New Relic ingest API key.
Before setting up the integration, you will need a [New Relic license/ingest API key](https://docs.newrelic.com/docs/apis/intro-apis/new-relic-api-keys/#license-key).


1. Configure your New Relic API key as secret in your repository, called it `NEW_RELIC_API_KEY`
1. Configure your New Relic license key as a secret in your repository, and call it `NEW_RELIC_LICENSE_KEY`
2. The exporter uses automatic token authentication by default, for this you need to ensure that `GITHUB_TOKEN` has at least read access to the action scope. Alternatively, you can use a Personal Access Token, in this case, configure your PAT token as secret in your repository, called it `GHA_TOKEN`


Expand All @@ -37,10 +38,10 @@ on:
workflow_run:
workflows: ['*']
types: [completed] # defaults to run on every completed workflow run event
env:
GHA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_RELIC_API_KEY: ${{ secrets.NEW_RELIC_API_KEY }}
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
GHA_RUN_ID: ${{ github.event.workflow_run.id }}
GHA_RUN_NAME: ${{ github.event.workflow_run.name }}
Expand All @@ -53,9 +54,23 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: new-relic-exporter
uses: dpacheconr/gha-new-relic-exporter@latest
uses: newrelic-experimental/gha-new-relic-exporter@latest
```

## Example

See example repo here, using this action: https://github.com/khpeet/fy24sko-change-tracking

Traces/Logs are viewable under an OTEL service entity in New Relic, named as your repo:
![Overview](screenshots/tracing.png)

Each workflow's run/execution steps can be viewed as spans, and logs are also captured, in context:
![SingleTrace](screenshots/single_trace.png)
![Logs](screenshots/logs.png)




## Contributing

We encourage your contributions to improve [Github Actions New Relic Exporter](../../)! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].
Expand All @@ -71,17 +86,3 @@ If you believe you have found a security vulnerability in this project or any of
Github Actions New Relic Exporter is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.

>Github Actions New Relic Exporter also use source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document.













2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
- VERSION=$VERSION
build:
context: ./
image: docker.io/dpacheconr/gha-exporter:$VERSION
image: docker.io/newrelic-experimental/gha-exporter:$VERSION
Binary file added screenshots/logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/single_trace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/tracing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/custom_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def do_parse(string):
return string != "" and string is not None and string != "None"

def check_env_vars():
keys = ("NEW_RELIC_API_KEY","GHA_TOKEN")
keys = ("NEW_RELIC_LICENSE_KEY","GHA_TOKEN")
keys_not_set = []

for key in keys:
Expand All @@ -28,7 +28,7 @@ def check_env_vars():
else:
pass

if len(keys_not_set) > 0:
if len(keys_not_set) > 0:
for key in keys_not_set:
print(key + " not set")
exit(1)
Expand All @@ -39,7 +39,7 @@ def parse_attributes(obj,att_to_drop):
# todo
# if "GHA_ATTRIBUTES_DROP" in os.environ:
# try:
# if os.getenv("GHA_ATTRIBUTES_DROP") != "":
# if os.getenv("GHA_ATTRIBUTES_DROP") != "":
# user_attributes_to_drop =str(os.getenv("GHA_ATTRIBUTES_DROP")).lower().split(",")
# for attribute in user_attributes_to_drop:
# attributes_to_drop.append(attribute)
Expand Down
18 changes: 9 additions & 9 deletions src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@

# Configure env variables
GHA_TOKEN = os.getenv('GHA_TOKEN')
NEW_RELIC_API_KEY = os.getenv('NEW_RELIC_API_KEY')
NEW_RELIC_LICENSE_KEY = os.getenv('NEW_RELIC_LICENSE_KEY')
GHA_RUN_ID = os.getenv('GHA_RUN_ID')
GHA_SERVICE_NAME=os.getenv('GITHUB_REPOSITORY')
GITHUB_REPOSITORY_OWNER=os.getenv('GITHUB_REPOSITORY_OWNER')
GHA_RUN_NAME=os.getenv('GHA_RUN_NAME')

if NEW_RELIC_API_KEY.startswith("eu"):
if NEW_RELIC_LICENSE_KEY.startswith("eu"):
OTEL_EXPORTER_OTEL_ENDPOINT = "https://otlp.eu01.nr-data.net:4318"
else:
OTEL_EXPORTER_OTEL_ENDPOINT = "https://otlp.nr-data.net:4318"

endpoint="{}".format(OTEL_EXPORTER_OTEL_ENDPOINT)
headers="api-key={}".format(NEW_RELIC_API_KEY)
headers="api-key={}".format(NEW_RELIC_LICENSE_KEY)

# Github API client
api = GhApi(owner=GITHUB_REPOSITORY_OWNER, repo=GHA_SERVICE_NAME.split('/')[1], token=str(GHA_TOKEN))
Expand All @@ -54,15 +54,15 @@
#Set workflow level tracer and logger
global_resource = Resource(attributes=global_attributes)
tracer = get_tracer(endpoint, headers, global_resource, "tracer")


#Ensure we don't export data for new relic exporters
workflow_run = json.loads(get_workflow_run_jobs_by_run_id)
job_lst=[]
for job in workflow_run['jobs']:
if str(job['name']).lower() not in ["new-relic-exporter"]:
job_lst.append(job)

if len(job_lst) == 0:
print("No data to export, assuming this github action workflow job is a new relic exporter")
exit(0)
Expand Down Expand Up @@ -96,7 +96,7 @@
child_0 = tracer.start_span(name=str(job['name']),context=pcontext,start_time=do_time(job['started_at']), kind=trace.SpanKind.CONSUMER)
child_0.set_attributes(create_resource_attributes(parse_attributes(job,"steps"),GHA_SERVICE_NAME))
p_sub_context = trace.set_span_in_context(child_0)

# Steps trace span
for step in job['steps']:
# Set steps tracer and logger
Expand Down Expand Up @@ -128,10 +128,10 @@
# Send the log events
job_logger = get_logger(endpoint,headers,resource_log, "job_logger")
job_logger.info("")

child_1.end(end_time=do_time(step['completed_at']))
child_0.end(end_time=do_time(job['completed_at']))
workflow_run_finish_time=do_time(job['completed_at'])
p_parent.end(end_time=workflow_run_finish_time)

print("All data exported to New Relic")
print("All data exported to New Relic")

0 comments on commit ec5d5be

Please sign in to comment.