Code Monkey home page Code Monkey logo

dynatrace-github-action's Introduction

Dynatrace GitHub Action

Build Status

This GitHub Action enables CI/CD workflows to report events and metrics to a Dynatrace monitoring environment.

Usage

The action configuration must specify the Dynatrace url as well as an API token to be able to send information into a Dynatrace environment. We strongly advise to use GitHub repository placeholders for both information here to prevent the exposure of secrets in your repository!

The url must contain a Dynatrace domain, e.g.: https://{your-environment-id}.live.dynatrace.com.

The token must contain a Dynatrace API v2 token with 'Ingest metrics' and/or 'Ingest events' scope enabled, as shown below:

token

Please note how metrics and events is configured as a string containing YAML code - this allows to send more than one metric or event at once. To send a metric, configure a job step like the following:

- name: Build count
  uses: dynatrace-oss/dynatrace-github-action@v8
  with:
    url: '${{ secrets.DT_URL }}'
    token: '${{ secrets.DT_TOKEN }}'
    metrics: |
      - metric: "github.metric1"
      value: "1.0"
      dimensions:
        project: "${{ github.repository }}"
        branch: "${{ github.ref }}"
        event: "${{ github.event_name }}"
        owner: wolfgang

Analyze the resulting CI/CD pipeline metric within Dynatrace, as shown below: chart

You can also send Dynatrace events from workflows, same as metric. See below how an event is configured within the events section. The standard entity selector query is used to push the event on a selected entity or onto a cohort of entities e.g.: a tagged set of services. See the Dynatrace help page on entity selectors. See some example entity selectors below:

  • type(host),tag(prod) Selects all hosts with a tag 'prod'.
  • type(service),entityName(login) Selects services with the name 'login'

For example, to send an event whenever a job has failed:

steps:
  - name: checkout
    uses: actions/checkout@v2
  - name: build
    run: this-will-fail
  - name: Notify Dynatrace on Build Failed
    if: failure()
    uses: dynatrace-oss/dynatrace-github-action@v8
    with:
      url: '${{ secrets.DT_URL }}'
      token: '${{ secrets.DT_TOKEN }}'
      events: |
        - title: "Build failed"
          type: CUSTOM_INFO
          entitySelector: type(host),entityName(myHost)
          properties:
            description: "Branch ${{ github.ref }} failed to build"
            source: GitHub
            project: "${{ github.repository }}"
            branch: "${{ github.ref }}"
            event: "${{ github.event_name }}"
            owner: ${{ github.repository_owner }}

Find the resulting CI/CD pipeline events within Dynatrace, as shown below: events

In another example, a deployment event can be sent onto a specific entity. In this example the event is sent to a mobile app whenever the Android GitHub Action build workflow succeeded:

steps:
  - name: checkout
    uses: actions/checkout@v2
  - name: build
    run: this-will-fail
  - name: Notify Dynatrace on Build Failed
    if: failure()
    uses: dynatrace-oss/dynatrace-github-action@v8
    with:
      url: '${{ secrets.DT_URL }}'
      token: '${{ secrets.DT_TOKEN }}'
      events: |
        - type: CUSTOM_DEPLOYMENT
          title: Mobile app version deployment failed
          entitySelector: type(MOBILE_APPLICATION),entityId(MOBILE_APPLICATION-C061BED4799B41C5)
          properties:
            source: GitHub
            deploymentName: "GitHub Action"
            deploymentVersion: "${{ github.ref }}"
            deploymentProject: "${{ github.repository }}"
            remediationAction: "None"
            ciBackLink: "https://github.com/${{ github.repository }}"
            project: "${{ github.repository }}"
            branch: "${{ github.ref }}"
            event: "${{ github.event_name }}"
            owner: wolfgang

Development

Install the dependencies

$ npm install

up to date, audited 1004 packages in 3s

Lint, test and build the typescript and package it for distribution

$ npm run all

> [email protected] all
> npm run build && npm run format && npm run lint && npm run package && npm test
...

Run the tests ✔️

$ npm test

> [email protected] test
> jest

ts-jest[versions] (WARN) Version 4.0.2 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=2.7.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
 PASS  __tests__/main.test.ts (8.316s)
  ✓ throws invalid number (15ms)
  ✓ wait 500 ms (500ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        9.336s
Ran all test suites.

dynatrace-github-action's People

Contributors

wolfgangb33r avatar dependabot[bot] avatar joshuaw-kr avatar arminru avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.