Skip to content

Commit 31fd70e

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

File tree

8 files changed

+632
-115
lines changed

8 files changed

+632
-115
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 and convert these into traces.
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: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ require (
456456
github.com/ProtonMail/go-crypto v1.1.6 // indirect
457457
github.com/Shopify/sarama v1.38.1 // indirect
458458
github.com/Showmax/go-fqdn v1.0.0 // indirect
459-
github.com/Workiva/go-datastructures v1.1.6 // indirect
460459
github.com/alecthomas/participle/v2 v2.1.4 // indirect
461460
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
462461
github.com/andybalholm/brotli v1.2.0 // indirect
@@ -499,14 +498,11 @@ require (
499498
github.com/aws/aws-sdk-go-v2/service/storagegateway v1.34.8 // indirect
500499
github.com/aws/aws-sdk-go-v2/service/sts v1.38.9 // indirect
501500
github.com/aws/smithy-go v1.23.1 // indirect
502-
github.com/axiomhq/hyperloglog v0.2.5 // indirect
503501
github.com/bahlo/generic-list-go v0.2.0 // indirect
504502
github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 // indirect
505503
github.com/beevik/ntp v1.3.0 // indirect
506504
github.com/benbjohnson/clock v1.3.5 // indirect
507505
github.com/beorn7/perks v1.0.1 // indirect
508-
github.com/bits-and-blooms/bitset v1.22.0 // indirect
509-
github.com/bits-and-blooms/bloom/v3 v3.7.0 // indirect
510506
github.com/bmatcuk/doublestar/v4 v4.9.1 // indirect
511507
github.com/caarlos0/env/v9 v9.0.0
512508
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
@@ -539,7 +535,6 @@ require (
539535
github.com/dennwc/ioctl v1.0.0 // indirect
540536
github.com/dennwc/varint v1.0.0 // indirect
541537
github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba // indirect
542-
github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc // indirect
543538
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
544539
github.com/digitalocean/godo v1.165.1 // indirect
545540
github.com/distribution/reference v0.6.0 // indirect
@@ -627,7 +622,6 @@ require (
627622
github.com/grafana/jvmtools v0.0.3 // indirect
628623
github.com/grafana/otel-profiling-go v0.5.1 // indirect
629624
github.com/grobie/gomemcache v0.0.0-20230213081705-239240bbc445 // indirect
630-
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 // indirect
631625
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
632626
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
633627
github.com/hashicorp/cronexpr v1.1.3 // indirect
@@ -667,7 +661,6 @@ require (
667661
github.com/influxdata/influxdb-observability/influx2otel v0.5.12 // indirect
668662
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
669663
github.com/influxdata/line-protocol/v2 v2.2.1 // indirect
670-
github.com/influxdata/tdigest v0.0.2-0.20210216194612-fc98d27c9e8b // indirect
671664
github.com/ionos-cloud/sdk-go/v6 v6.3.4 // indirect
672665
github.com/itchyny/timefmt-go v0.1.7 // indirect
673666
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
@@ -691,8 +684,6 @@ require (
691684
github.com/joyent/triton-go v1.8.5 // indirect
692685
github.com/jpillora/backoff v1.0.0 // indirect
693686
github.com/jsimonetti/rtnetlink v1.4.2 // indirect
694-
github.com/julienschmidt/httprouter v1.3.0 // indirect
695-
github.com/kamstrup/intmap v0.5.1 // indirect
696687
github.com/karrick/godirwalk v1.17.0 // indirect
697688
github.com/kevinburke/ssh_config v1.2.0 // indirect
698689
github.com/klauspost/asmfmt v1.3.2 // indirect
@@ -975,6 +966,11 @@ require (
975966
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
976967
)
977968

969+
require (
970+
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awss3receiver v0.139.0
971+
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver v0.138.0
972+
)
973+
978974
require (
979975
cyphar.com/go-pathrs v0.2.1 // indirect
980976
github.com/DataDog/datadog-agent/comp/api/api/def v0.73.0-devel.0.20251030121902-cd89eab046d6 // indirect
@@ -991,6 +987,7 @@ require (
991987
github.com/DataDog/datadog-agent/pkg/opentelemetry-mapping-go/otlp/rum v0.73.0-devel.0.20251030121902-cd89eab046d6 // indirect
992988
github.com/DataDog/datadog-agent/pkg/util/defaultpaths v0.69.3 // indirect
993989
github.com/DataDog/datadog-agent/pkg/util/quantile v0.73.0-devel.0.20251030121902-cd89eab046d6 // indirect
990+
github.com/Khan/genqlient v0.8.1 // indirect
994991
github.com/aws/aws-sdk-go-v2/service/sqs v1.42.11 // indirect
995992
github.com/digitalocean/go-metadata v0.0.0-20250129100319-e3650a3df44b // indirect
996993
github.com/go-openapi/swag/cmdutils v0.25.1 // indirect
@@ -1004,12 +1001,13 @@ require (
10041001
github.com/go-openapi/swag/stringutils v0.25.1 // indirect
10051002
github.com/go-openapi/swag/typeutils v0.25.1 // indirect
10061003
github.com/go-openapi/swag/yamlutils v0.25.1 // indirect
1004+
github.com/google/go-github/v76 v76.0.0 // indirect
10071005
github.com/linode/go-metadata v0.2.2 // indirect
10081006
github.com/mitchellh/hashstructure v1.1.0 // indirect
10091007
github.com/open-telemetry/opamp-go v0.22.0 // indirect
10101008
github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampcustommessages v0.139.0 // indirect
1011-
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awss3receiver v0.139.0 // indirect
10121009
github.com/twmb/franz-go/pkg/kadm v1.17.1 // indirect
1010+
github.com/vektah/gqlparser/v2 v2.5.22 // indirect
10131011
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 // indirect
10141012
)
10151013

0 commit comments

Comments
 (0)