diff --git a/.DS_Store b/.DS_Store index 8674f7e..5172429 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index b6b2718..2549226 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ env: 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 }} + #GHA_CUSTOM_ATTS: '{"mycustomattributea":"test", "mycustomattributeb":10, "mycustomattributec":"My custom attribute"}' jobs: diff --git a/new-relic-exporter.yaml.example b/new-relic-exporter.yaml.example index 4692de4..7118b96 100644 --- a/new-relic-exporter.yaml.example +++ b/new-relic-exporter.yaml.example @@ -10,6 +10,7 @@ env: NEW_RELIC_API_KEY: ${{ secrets.NEW_RELIC_API_KEY }} GHA_RUN_ID: ${{ github.event.workflow_run.id }} GHA_RUN_NAME: ${{ github.event.workflow_run.name }} + #GHA_CUSTOM_ATTS: '{"mycustomattributea":"test", "mycustomattributeb":10, "mycustomattributec":"My custom attribute"}' jobs: new-relic-exporter: diff --git a/src/exporter.py b/src/exporter.py index 3ee4dfb..48d8c1e 100644 --- a/src/exporter.py +++ b/src/exporter.py @@ -67,7 +67,21 @@ "github.resource.type": "span" } +# Example: GHA_CUSTOM_ATTS: '{"mycustomattributea":"test", "mycustomattributeb":10, "mycustomattributec":"My custom attribute"}' +# Check for custom attributes +if "GHA_CUSTOM_ATTS" in os.environ: + GHA_CUSTOM_ATTS = os.environ["GHA_CUSTOM_ATTS"] +else: + GHA_CUSTOM_ATTS = "" + +if GHA_CUSTOM_ATTS != "": + try: + global_attributes.update(json.loads(GHA_CUSTOM_ATTS)) + except: + print("Error parsing GHA_CUSTOM_ATTS check your configuration, continuing without custom attributes") + pass + #Set workflow level tracer and logger global_resource = Resource(attributes=global_attributes) tracer = get_tracer(endpoint, headers, global_resource, "tracer") @@ -123,7 +137,15 @@ print("Processing step ->",step['name'],"from job",job['name']) # Set steps tracer and logger resource_attributes ={SERVICE_NAME: GHA_SERVICE_NAME,"github.source": "github-exporter","github.resource.type": "span","workflow_run_id": GHA_RUN_ID} + # Add custom attributes if they exist + if GHA_CUSTOM_ATTS != "": + try: + resource_attributes.update(json.loads(GHA_CUSTOM_ATTS)) + except: + print("Error parsing GHA_CUSTOM_ATTS check your configuration, continuing without custom attributes") + pass resource_log = Resource(attributes=resource_attributes) + step_tracer = get_tracer(endpoint, headers, resource_log, "step_tracer") resource_attributes.update(create_resource_attributes(parse_attributes(step,"","step"),GHA_SERVICE_NAME))