diff --git a/README.md b/README.md index 7238d12..6e4fefe 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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 }} @@ -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 opensource@newrelic.com. @@ -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. - - - - - - - - - - - - - - diff --git a/docker-compose.yaml b/docker-compose.yaml index 05e89d5..6da29be 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,4 +6,4 @@ services: - VERSION=$VERSION build: context: ./ - image: docker.io/dpacheconr/gha-exporter:$VERSION + image: docker.io/newrelic-experimental/gha-exporter:$VERSION diff --git a/screenshots/logs.png b/screenshots/logs.png new file mode 100644 index 0000000..879ab83 Binary files /dev/null and b/screenshots/logs.png differ diff --git a/screenshots/single_trace.png b/screenshots/single_trace.png new file mode 100644 index 0000000..ffbfed0 Binary files /dev/null and b/screenshots/single_trace.png differ diff --git a/screenshots/tracing.png b/screenshots/tracing.png new file mode 100644 index 0000000..da5168a Binary files /dev/null and b/screenshots/tracing.png differ diff --git a/src/custom_parser/__init__.py b/src/custom_parser/__init__.py index b963f2a..20f6012 100644 --- a/src/custom_parser/__init__.py +++ b/src/custom_parser/__init__.py @@ -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: @@ -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) @@ -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) diff --git a/src/exporter.py b/src/exporter.py index 766f263..56f70d4 100644 --- a/src/exporter.py +++ b/src/exporter.py @@ -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)) @@ -54,7 +54,7 @@ #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) @@ -62,7 +62,7 @@ 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) @@ -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 @@ -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") \ No newline at end of file +print("All data exported to New Relic")