Skip to content

Commit 87369d0

Browse files
committed
feat(otelcol.receiver) - Github
This PR adds the opentelemetry github receiver.
1 parent 1f2b7b8 commit 87369d0

File tree

8 files changed

+628
-73
lines changed

8 files changed

+628
-73
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Main (unreleased)
1818

1919
- Add htpasswd file based authentication for `otelcol.auth.basic` (@pkarakal)
2020

21+
- A new `otelcol.receiver.github` component which collects data from Github. (@matt-gp)
22+
2123
### Enhancements
2224

2325
- update promtail converter to use `file_match` block for `loki.source.file` instead of going through `local.file_match`. (@kalleep)
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
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 -->

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@ require (
975975
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
976976
)
977977

978+
require github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver v0.138.0
979+
978980
require (
979981
cyphar.com/go-pathrs v0.2.1 // indirect
980982
github.com/DataDog/datadog-agent/comp/api/api/def v0.73.0-devel.0.20251030121902-cd89eab046d6 // indirect
@@ -1004,12 +1006,14 @@ require (
10041006
github.com/go-openapi/swag/stringutils v0.25.1 // indirect
10051007
github.com/go-openapi/swag/typeutils v0.25.1 // indirect
10061008
github.com/go-openapi/swag/yamlutils v0.25.1 // indirect
1009+
github.com/google/go-github/v76 v76.0.0 // indirect
10071010
github.com/linode/go-metadata v0.2.2 // indirect
10081011
github.com/mitchellh/hashstructure v1.1.0 // indirect
10091012
github.com/open-telemetry/opamp-go v0.22.0 // indirect
10101013
github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages v0.139.0 // indirect
10111014
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awss3receiver v0.139.0 // indirect
10121015
github.com/twmb/franz-go/pkg/kadm v1.17.1 // indirect
1016+
github.com/vektah/gqlparser/v2 v2.5.22 // indirect
10131017
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 // indirect
10141018
)
10151019

go.sum

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob
407407
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
408408
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
409409
github.com/IBM/sarama v1.46.3/go.mod h1:GTUYiF9DMOZVe3FwyGT+dtSPceGFIgA+sPc5u6CBwko=
410+
github.com/Khan/genqlient v0.8.1 h1:wtOCc8N9rNynRLXN3k3CnfzheCUNKBcvXmVv5zt6WCs=
411+
github.com/Khan/genqlient v0.8.1/go.mod h1:R2G6DzjBvCbhjsEajfRjbWdVglSH/73kSivC9TLWVjU=
410412
github.com/KimMachineGun/automemlimit v0.7.4 h1:UY7QYOIfrr3wjjOAqahFmC3IaQCLWvur9nmfIn6LnWk=
411413
github.com/KimMachineGun/automemlimit v0.7.4/go.mod h1:QZxpHaGOQoYvFhv/r4u3U0JTC2ZcOwbSr11UZF46UBM=
412414
github.com/Lusitaniae/apache_exporter v0.11.1-0.20220518131644-f9522724dab4 h1:UEm6tMvLH2t2honcWG0q+h0qr/60++9cuh/fy7hLyMc=
@@ -460,6 +462,8 @@ github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b h1:mimo19zliBX/vS
460462
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs=
461463
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=
462464
github.com/alicebob/miniredis/v2 v2.35.0/go.mod h1:TcL7YfarKPGDAthEtl5NBeHZfeUQj6OXMm/+iu5cLMM=
465+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
466+
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
463467
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
464468
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
465469
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
@@ -1077,8 +1081,8 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
10771081
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
10781082
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
10791083
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1080-
github.com/google/go-github/v75 v75.0.0 h1:k7q8Bvg+W5KxRl9Tjq16a9XEgVY1pwuiG5sIL7435Ic=
1081-
github.com/google/go-github/v75 v75.0.0/go.mod h1:H3LUJEA1TCrzuUqtdAQniBNwuKiQIqdGKgBo1/M/uqI=
1084+
github.com/google/go-github/v76 v76.0.0 h1:MCa9VQn+VG5GG7Y7BAkBvSRUN3o+QpaEOuZwFPJmdFA=
1085+
github.com/google/go-github/v76 v76.0.0/go.mod h1:38+d/8pYDO4fBLYfBhXF5EKO0wA3UkXBjfmQapFsNCQ=
10821086
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
10831087
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
10841088
github.com/google/go-tpm v0.9.6 h1:Ku42PT4LmjDu1H5C5ISWLlpI1mj+Zq7sPGKoRw2XROA=
@@ -1913,6 +1917,8 @@ github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filestatsrece
19131917
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filestatsreceiver v0.139.0/go.mod h1:ygX4LsRLrfNtuFV0lZy5J8rAskHLmuWy5hbIiobHq6c=
19141918
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/fluentforwardreceiver v0.139.0 h1:LkBhII1P9mSIsAxLEZYDIZwEPXGoQduWEqqrVxEMsiw=
19151919
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/fluentforwardreceiver v0.139.0/go.mod h1:3n0cpchEKo89de+yLfh+3ov0VdgOL+aoWUExwty/pWE=
1920+
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver v0.138.0 h1:1bF/uTOGBDU0G7ex7Fe+Vw1fH8u1q6smlowhhlveuNg=
1921+
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver v0.138.0/go.mod h1:b4kXFJsUYqTs+BBBuDfP9RvjWWooAHGAexAALF1GZLA=
19161922
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudpubsubreceiver v0.139.0 h1:V2yADZerJO6xG/0RNWH8Ut8zewDy5YaRZvvfE4xkt44=
19171923
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudpubsubreceiver v0.139.0/go.mod h1:fPdFJPsKJvPtBHQDgnf+ooO1OnDTUuPjM6+w9uxI2CM=
19181924
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/influxdbreceiver v0.139.0 h1:ovBv/QmMfmwDASLNKqQ6kFTK781WEgYfc501uFWT2os=

internal/component/all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ import (
111111
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/file_stats" // Import otelcol.receiver.file_stats
112112
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/filelog" // Import otelcol.receiver.filelog
113113
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/fluentforward" // Import otelcol.receiver.fluentforward
114+
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/github" // Import otelcol.receiver.github
114115
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/googlecloudpubsub" // Import otelcol.receiver.googlecloudpubsub
115116
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/influxdb" // Import otelcol.receiver.influxdb
116117
_ "github.com/grafana/alloy/internal/component/otelcol/receiver/jaeger" // Import otelcol.receiver.jaeger

0 commit comments

Comments
 (0)