|
| 1 | +--- |
| 2 | +canonical: https://grafana.com/docs/alloy/latest/reference/components/otelcol/otelcol.receiver.github/ |
| 3 | +description: Learn about otelcol.receiver.github |
| 4 | +labels: |
| 5 | + stage: experimental |
| 6 | + products: |
| 7 | + - oss |
| 8 | +title: otelcol.receiver.github |
| 9 | +--- |
| 10 | + |
| 11 | +# `otelcol.receiver.github` |
| 12 | + |
| 13 | +{{< docs/shared lookup="stability/experimental.md" source="alloy" version="<ALLOY_VERSION>" >}} |
| 14 | + |
| 15 | +`otelcol.receiver.github` collect metrics about repositories, pull requests, branches, and contributors. It can also be configured to receive webhook events from Github Actions. |
| 16 | + |
| 17 | +You can specify multiple `otelcol.receiver.github` components by giving them different labels. |
| 18 | + |
| 19 | +Ensure you have the following: |
| 20 | + |
| 21 | +- A GitHub Personal Access Token or GitHub App with appropriate permissions |
| 22 | +- For metrics: Read access to target repositories and organizations |
| 23 | +- For webhooks: A publicly accessible endpoint to receive GitHub webhook events |
| 24 | +- Network connectivity to GitHub API endpoints, for example, `api.github.com` or your GitHub Enterprise instance |
| 25 | + |
| 26 | +{{< admonition type="note" >}} |
| 27 | +`otelcol.receiver.github` is a wrapper over the upstream OpenTelemetry Collector [`github`][] receiver. |
| 28 | +Bug reports or feature requests will be redirected to the upstream repository, if necessary. |
| 29 | + |
| 30 | +[`github`]: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/{{< param "OTEL_VERSION" >}}/receiver/githubreceiver |
| 31 | +{{< /admonition >}} |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```alloy |
| 36 | +otelcol.receiver.github "<LABEL>" { |
| 37 | + scraper { |
| 38 | + github_org = "<GITHUB_ORG>" |
| 39 | + auth { |
| 40 | + authenticator = <AUTH_HANDLER> |
| 41 | + } |
| 42 | + } |
| 43 | +
|
| 44 | + output { |
| 45 | + metrics = [...] |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +## Arguments |
| 51 | + |
| 52 | +You can use the following arguments with `otelcol.receiver.github`: |
| 53 | + |
| 54 | +| Name | Type | Description | Default | Required | |
| 55 | +| --------------------- | ---------- | ---------------------------------------------------- | ------- | -------- | |
| 56 | +| `collection_interval` | `duration` | How often to scrape metrics from GitHub. | `"30s"` | no | |
| 57 | +| `initial_delay` | `duration` | Defines how long the receiver waits before starting. | `"0s"` | no | |
| 58 | + |
| 59 | +## Blocks |
| 60 | + |
| 61 | +You can use the following blocks with `otelcol.receiver.github`: |
| 62 | + |
| 63 | +| Block | Description | Required | |
| 64 | +| -------------------------------- | -------------------------------------------------------------------------- | -------- | |
| 65 | +| [`output`][output] | Configures where to send received telemetry data. | yes | |
| 66 | +| [`debug_metrics`][debug_metrics] | Configures the metrics that this component generates to monitor its state. | no | |
| 67 | +| [`scraper`][scraper] | Configures the GitHub scraper. | no | |
| 68 | +| `scraper` > [`auth`][auth] | Configures authentication for GitHub API. | yes | |
| 69 | +| `scraper` > [`metrics`][metrics] | Configures which metrics to collect. | no | |
| 70 | +| [`webhook`][webhook] | Configures webhook receiver for GitHub Actions events. | no | |
| 71 | + |
| 72 | +The > symbol indicates deeper levels of nesting. |
| 73 | +For example, `scraper` > `auth` refers to an `auth` block defined inside a `scraper` block. |
| 74 | + |
| 75 | +[scraper]: #scraper |
| 76 | +[webhook]: #webhook |
| 77 | +[output]: #output |
| 78 | +[debug_metrics]: #debug_metrics |
| 79 | +[auth]: #auth |
| 80 | +[metrics]: #metrics |
| 81 | + |
| 82 | +### `scraper` |
| 83 | + |
| 84 | +The `scraper` block configures the GitHub metrics scraper. |
| 85 | + |
| 86 | +The following arguments are supported: |
| 87 | + |
| 88 | +| Name | Type | Description | Default | Required | |
| 89 | +| -------------- | -------- | ---------------------------------------------------- | ------- | -------- | |
| 90 | +| `github_org` | `string` | GitHub organization or user to scrape metrics from. | | yes | |
| 91 | +| `endpoint` | `string` | GitHub API endpoint for GitHub Enterprise instances. | | no | |
| 92 | +| `search_query` | `string` | Custom search query to filter repositories. | | no | |
| 93 | + |
| 94 | +### `auth` |
| 95 | + |
| 96 | +The `auth` block configures authentication for the GitHub API. |
| 97 | + |
| 98 | +The following arguments are supported: |
| 99 | + |
| 100 | +| Name | Type | Description | Default | Required | |
| 101 | +| --------------- | -------------------------- | ------------------------------------------------ | ------- | -------- | |
| 102 | +| `authenticator` | `capsule(otelcol.Handler)` | Auth handler from an `otelcol.auth.*` component. | | yes | |
| 103 | + |
| 104 | +### `metrics` |
| 105 | + |
| 106 | +The `metrics` block allows you to enable or disable specific metrics. Each metric is configured with a nested block. |
| 107 | + |
| 108 | +Available metrics: |
| 109 | + |
| 110 | +| Metric Name | Description | Default | |
| 111 | +| ----------------------------- | ---------------------------------------------- | ------- | |
| 112 | +| `vcs.change.count` | Number of changes (pull requests) by state. | `true` | |
| 113 | +| `vcs.change.duration` | Time a change spent in various states. | `true` | |
| 114 | +| `vcs.change.time_to_approval` | Time it took for a change to get approved. | `true` | |
| 115 | +| `vcs.change.time_to_merge` | Time it took for a change to be merged. | `true` | |
| 116 | +| `vcs.contributor.count` | Number of unique contributors to a repository. | `false` | |
| 117 | +| `vcs.ref.count` | Number of refs (branches) in a repository. | `true` | |
| 118 | +| `vcs.ref.lines_delta` | Number of lines changed in a ref. | `true` | |
| 119 | +| `vcs.ref.revisions_delta` | Number of commits (revisions) in a ref. | `true` | |
| 120 | +| `vcs.ref.time` | Time since the ref was created. | `true` | |
| 121 | +| `vcs.repository.count` | Number of repositories in an organization. | `true` | |
| 122 | + |
| 123 | +Each metric can be configured with: |
| 124 | + |
| 125 | +```alloy |
| 126 | +metrics { |
| 127 | + vcs.change.count { |
| 128 | + enabled = true |
| 129 | + } |
| 130 | + vcs.contributor.count { |
| 131 | + enabled = false |
| 132 | + } |
| 133 | +} |
| 134 | +``` |
| 135 | + |
| 136 | +### `webhook` |
| 137 | + |
| 138 | +The `webhook` block configures webhook reception for GitHub Actions events. |
| 139 | + |
| 140 | +When enabled, this block allows the receiver to convert GitHub Actions workflow and job events into traces. |
| 141 | + |
| 142 | +{{< admonition type="note" >}} |
| 143 | +Ensure your webhook endpoint is secured with a secret and protected by appropriate network security measures. |
| 144 | +{{< /admonition >}} |
| 145 | + |
| 146 | +The following arguments are supported: |
| 147 | + |
| 148 | +| Name | Type | Description | Default | Required | |
| 149 | +|---------------------|-------------------|-----------------------------------------------------------|-------------------|----------| |
| 150 | +| `endpoint` | `string` | The `host:port` to listen for webhooks on. | `"localhost:8080"`| no | |
| 151 | +| `path` | `string` | URL path for webhook events. | `"/events"` | no | |
| 152 | +| `health_path` | `string` | URL path for health checks. | `"/health"` | no | |
| 153 | +| `secret` | `string` | Secret for validating webhook signatures. | | no | |
| 154 | +| `required_headers` | `map(string)` | Required headers that must be present on webhook requests.| | no | |
| 155 | + |
| 156 | +### `output` |
| 157 | + |
| 158 | +{{< badge text="Required" >}} |
| 159 | + |
| 160 | +{{< docs/shared lookup="reference/components/output-block.md" source="alloy" version="<ALLOY_VERSION>" >}} |
| 161 | + |
| 162 | +### `debug_metrics` |
| 163 | + |
| 164 | +{{< docs/shared lookup="reference/components/otelcol-debug-metrics-block.md" source="alloy" version="<ALLOY_VERSION>" >}} |
| 165 | + |
| 166 | +## Exported fields |
| 167 | + |
| 168 | +`otelcol.receiver.github` doesn't export any fields. |
| 169 | + |
| 170 | +## Component health |
| 171 | + |
| 172 | +`otelcol.receiver.github` is reported as unhealthy if the GitHub API can't be reached or authentication fails. |
| 173 | + |
| 174 | +## Debug information |
| 175 | + |
| 176 | +`otelcol.receiver.github` doesn't expose additional debug info. |
| 177 | + |
| 178 | +## Example |
| 179 | + |
| 180 | +### Basic configuration |
| 181 | + |
| 182 | +This example scrapes metrics from a GitHub organization: |
| 183 | + |
| 184 | +```alloy |
| 185 | +otelcol.auth.bearer "github" { |
| 186 | + token = env("GITHUB_PAT") |
| 187 | +} |
| 188 | +
|
| 189 | +otelcol.receiver.github "default" { |
| 190 | + collection_interval = "5m" |
| 191 | + |
| 192 | + scraper { |
| 193 | + github_org = "grafana" |
| 194 | + search_query = "org:grafana topic:observability" |
| 195 | + |
| 196 | + auth { |
| 197 | + authenticator = otelcol.auth.bearer.github.handler |
| 198 | + } |
| 199 | + |
| 200 | + metrics { |
| 201 | + vcs.change.count { |
| 202 | + enabled = true |
| 203 | + } |
| 204 | + vcs.change.time_to_merge { |
| 205 | + enabled = true |
| 206 | + } |
| 207 | + vcs.repository.count { |
| 208 | + enabled = true |
| 209 | + } |
| 210 | + vcs.contributor.count { |
| 211 | + enabled = true |
| 212 | + } |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + output { |
| 217 | + metrics = [otelcol.exporter.prometheus.default.input] |
| 218 | + } |
| 219 | +} |
| 220 | +
|
| 221 | +otelcol.exporter.prometheus "default" { |
| 222 | + forward_to = [prometheus.remote_write.default.receiver] |
| 223 | +} |
| 224 | +
|
| 225 | +prometheus.remote_write "default" { |
| 226 | + endpoint { |
| 227 | + url = "https://prometheus.example.com/api/v1/write" |
| 228 | + } |
| 229 | +} |
| 230 | +``` |
| 231 | + |
| 232 | +### With webhook for GitHub Actions traces |
| 233 | + |
| 234 | +This example adds webhook support to receive GitHub Actions workflow events as traces: |
| 235 | + |
| 236 | +```alloy |
| 237 | +otelcol.auth.bearer "github" { |
| 238 | + token = env("GITHUB_PAT") |
| 239 | +} |
| 240 | +
|
| 241 | +otelcol.receiver.github "default" { |
| 242 | + scraper { |
| 243 | + github_org = "my-org" |
| 244 | + auth { |
| 245 | + authenticator = otelcol.auth.bearer.github.handler |
| 246 | + } |
| 247 | + } |
| 248 | + |
| 249 | + webhook { |
| 250 | + endpoint = "0.0.0.0:8080" |
| 251 | + path = "/github/webhooks" |
| 252 | + health_path = "/health" |
| 253 | + secret = env("GITHUB_WEBHOOK_SECRET") |
| 254 | + } |
| 255 | + |
| 256 | + output { |
| 257 | + metrics = [otelcol.exporter.otlphttp.default.input] |
| 258 | + traces = [otelcol.exporter.otlphttp.default.input] |
| 259 | + } |
| 260 | +} |
| 261 | +
|
| 262 | +otelcol.exporter.otlphttp "default" { |
| 263 | + client { |
| 264 | + endpoint = "https://otlp.example.com" |
| 265 | + } |
| 266 | +} |
| 267 | +``` |
| 268 | + |
| 269 | +### GitHub Enterprise |
| 270 | + |
| 271 | +For GitHub Enterprise instances, specify the custom endpoint: |
| 272 | + |
| 273 | +```alloy |
| 274 | +otelcol.auth.bearer "github_enterprise" { |
| 275 | + token = env("GHE_PAT") |
| 276 | +} |
| 277 | +
|
| 278 | +otelcol.receiver.github "enterprise" { |
| 279 | + scraper { |
| 280 | + github_org = "my-enterprise-org" |
| 281 | + endpoint = "https://github.mycompany.com" |
| 282 | + |
| 283 | + auth { |
| 284 | + authenticator = otelcol.auth.bearer.github_enterprise.handler |
| 285 | + } |
| 286 | + } |
| 287 | + |
| 288 | + output { |
| 289 | + metrics = [otelcol.exporter.prometheus.default.input] |
| 290 | + } |
| 291 | +} |
| 292 | +``` |
| 293 | + |
| 294 | +<!-- START GENERATED COMPATIBLE COMPONENTS --> |
| 295 | +<!-- END GENERATED COMPATIBLE COMPONENTS --> |
0 commit comments