Skip to content

Commit f07c246

Browse files
niwoernerdragonlord93
authored andcommitted
[receiver/gitlab] add tracing functionality (open-telemetry#39123)
#### Description This PR adds tracing functonality for the gitlabreceiver. It's only possible to create deterministic Trace/SpanIDs once a pipeline is finished. Correlation with manual instrumented jobs during pipeline runtime is not possible because of limitations in Gitlab. More details can be found [here](open-telemetry/semantic-conventions#1749 (comment)) (I would like to become an OpenTelemetry member to be a codeowner of the gitlabreceiver - would someone be willing to sponsor the membership for me? - Thank you! :) ) #### Link to tracking issue open-telemetry#35207 #### Testing Added unit tests and performed manual testing #### Documentation Updated README how to use the receiver
1 parent 8da60d7 commit f07c246

12 files changed

+1759
-28
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: gitlabreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: add GitLab pipeline tracing functionality
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35207]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

receiver/gitlabreceiver/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ success, and failure rates.
2525

2626
### Configuration
2727

28-
**IMPORTANT: At this time the tracing portion of this receiver only serves a health check endpoint.**
28+
**IMPORTANT**: Ensure your WebHook endpoint is secured with a secret and a Web
29+
Application Firewall (WAF) or other security measure.
2930

3031
The WebHook configuration exposes the following settings:
3132

@@ -54,3 +55,19 @@ receivers:
5455
5556
For tracing, all configuration is set under the `webhook` key. The full set
5657
of exposed configuration values can be found in [`config.go`](config.go).
58+
59+
## Tracing Limitations
60+
61+
### Deterministic Trace/Span IDs and Manual Instrumentation
62+
63+
The GitLab receiver creates deterministic trace/span IDs for pipelines by using an unique pipeline/job ID and the pipeline's `finished_at` timestamp. This approach ensures that the same pipeline execution always generates the same ID.
64+
65+
**Limitation**: Manual instrumentation within GitLab pipeline jobs is currently not possible. Since the trace ID generation requires the `finished_at` timestamp, which is only available once the pipeline has completed, it's not possible to generate the same traceID within running jobs to correlate manually instrumented spans with the automatically created pipeline spans. More details can be found [here](https://github.com/open-telemetry/semantic-conventions/issues/1749#issuecomment-2772544215).
66+
67+
This means:
68+
- The receiver can automatically create traces/spans for GitLab pipelines
69+
- You cannot manually instrument code within your pipeline jobs and have those spans appear in the same trace as the pipeline spans
70+
71+
### Child and Multi-Project Pipelines
72+
73+
**Limitation**: Child and multi-project pipelines are not supported yet. The hierarchy between parent/trigger pipelines wouldn't be reflected correctly, and instead two independent traces would be created for each pipeline. This means that the parent-child relationship between pipelines is not preserved in the generated traces.

receiver/gitlabreceiver/config.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ const (
2525

2626
// GitLab default headers: https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#delivery-headers
2727
defaultUserAgentHeader = "User-Agent"
28-
defaultGitlabInstanceHeader = "X-Gitlab-Instance"
29-
defaultGitlabWebhookUUIDHeader = "X-Gitlab-Webhook-UUID"
30-
defaultGitlabEventHeader = "X-Gitlab-Event"
31-
defaultGitlabEventUUIDHeader = "X-Gitlab-Event-UUID"
28+
defaultGitLabInstanceHeader = "X-Gitlab-Instance"
29+
defaultGitLabWebhookUUIDHeader = "X-Gitlab-Webhook-UUID"
30+
defaultGitLabEventHeader = "X-Gitlab-Event"
31+
defaultGitLabEventUUIDHeader = "X-Gitlab-Event-UUID"
3232
defaultIdempotencyKeyHeader = "Idempotency-Key"
33+
// #nosec G101 - Not an actual secret, just the name of a header: https://docs.gitlab.com/user/project/integrations/webhooks/#create-a-webhook
34+
defaultGitLabSecretTokenHeader = "X-Gitlab-Token"
3335
)
3436

3537
var (
@@ -73,12 +75,12 @@ func createDefaultConfig() component.Config {
7375
GitlabHeaders: GitlabHeaders{
7476
Customizable: map[string]string{
7577
defaultUserAgentHeader: "",
76-
defaultGitlabInstanceHeader: "https://gitlab.com",
78+
defaultGitLabInstanceHeader: "https://gitlab.com",
7779
},
7880
Fixed: map[string]string{
79-
defaultGitlabWebhookUUIDHeader: "",
80-
defaultGitlabEventHeader: "Pipeline Hook",
81-
defaultGitlabEventUUIDHeader: "",
81+
defaultGitLabWebhookUUIDHeader: "",
82+
defaultGitLabEventHeader: "Pipeline Hook",
83+
defaultGitLabEventUUIDHeader: "",
8284
defaultIdempotencyKeyHeader: "",
8385
},
8486
},

receiver/gitlabreceiver/config_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ func TestCreateDefaultConfig(t *testing.T) {
3535
GitlabHeaders: GitlabHeaders{
3636
Customizable: map[string]string{
3737
defaultUserAgentHeader: "",
38-
defaultGitlabInstanceHeader: "https://gitlab.com",
38+
defaultGitLabInstanceHeader: "https://gitlab.com",
3939
},
4040
Fixed: map[string]string{
41-
defaultGitlabWebhookUUIDHeader: "",
42-
defaultGitlabEventHeader: "Pipeline Hook",
43-
defaultGitlabEventUUIDHeader: "",
41+
defaultGitLabWebhookUUIDHeader: "",
42+
defaultGitLabEventHeader: "Pipeline Hook",
43+
defaultGitLabEventUUIDHeader: "",
4444
defaultIdempotencyKeyHeader: "",
4545
},
4646
},
@@ -80,12 +80,12 @@ func TestLoadConfig(t *testing.T) {
8080
GitlabHeaders: GitlabHeaders{
8181
Customizable: map[string]string{
8282
defaultUserAgentHeader: "",
83-
defaultGitlabInstanceHeader: "https://gitlab.com",
83+
defaultGitLabInstanceHeader: "https://gitlab.com",
8484
},
8585
Fixed: map[string]string{
86-
defaultGitlabWebhookUUIDHeader: "",
87-
defaultGitlabEventHeader: "Pipeline Hook",
88-
defaultGitlabEventUUIDHeader: "",
86+
defaultGitLabWebhookUUIDHeader: "",
87+
defaultGitLabEventHeader: "Pipeline Hook",
88+
defaultGitLabEventUUIDHeader: "",
8989
defaultIdempotencyKeyHeader: "",
9090
},
9191
},
@@ -107,12 +107,12 @@ func TestLoadConfig(t *testing.T) {
107107
expectedConfig.WebHook.GitlabHeaders = GitlabHeaders{
108108
Customizable: map[string]string{
109109
defaultUserAgentHeader: "GitLab/1.2.3-custom-version",
110-
defaultGitlabInstanceHeader: "https://gitlab.self-hosted.xyz",
110+
defaultGitLabInstanceHeader: "https://gitlab.self-hosted.xyz",
111111
},
112112
Fixed: map[string]string{
113-
defaultGitlabWebhookUUIDHeader: "",
114-
defaultGitlabEventHeader: "Pipeline Hook",
115-
defaultGitlabEventUUIDHeader: "",
113+
defaultGitLabWebhookUUIDHeader: "",
114+
defaultGitLabEventHeader: "Pipeline Hook",
115+
defaultGitLabEventUUIDHeader: "",
116116
defaultIdempotencyKeyHeader: "",
117117
},
118118
}

receiver/gitlabreceiver/go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ require (
2424
github.com/foxboron/go-tpm-keyfiles v0.0.0-20250323135004-b31fac66206e // indirect
2525
github.com/go-ole/go-ole v1.2.6 // indirect
2626
github.com/gobwas/glob v0.2.3 // indirect
27+
github.com/google/go-querystring v1.1.0 // indirect
2728
github.com/google/go-tpm v0.9.5 // indirect
2829
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 // indirect
30+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
31+
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
2932
github.com/hashicorp/go-version v1.7.0 // indirect
3033
github.com/inconshreveable/mousetrap v1.1.0 // indirect
34+
github.com/json-iterator/go v1.1.12 // indirect
3135
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
3236
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3337
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
@@ -90,6 +94,8 @@ require (
9094
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
9195
golang.org/x/crypto v0.38.0 // indirect
9296
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
97+
golang.org/x/oauth2 v0.26.0 // indirect
98+
golang.org/x/time v0.10.0 // indirect
9399
gonum.org/v1/gonum v0.16.0 // indirect
94100
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect
95101
sigs.k8s.io/yaml v1.4.0 // indirect
@@ -106,7 +112,6 @@ require (
106112
github.com/golang/snappy v1.0.0 // indirect
107113
github.com/google/uuid v1.6.0 // indirect
108114
github.com/gorilla/mux v1.8.1
109-
github.com/json-iterator/go v1.1.12 // indirect
110115
github.com/klauspost/compress v1.18.0 // indirect
111116
github.com/knadh/koanf/maps v0.1.2 // indirect
112117
github.com/knadh/koanf/providers/confmap v1.0.0 // indirect
@@ -118,6 +123,7 @@ require (
118123
github.com/pierrec/lz4/v4 v4.1.22 // indirect
119124
github.com/pmezard/go-difflib v1.0.0 // indirect
120125
github.com/rs/cors v1.11.1 // indirect
126+
gitlab.com/gitlab-org/api/client-go v0.126.0
121127
go.opentelemetry.io/collector/client v1.32.1-0.20250515040533-97a6accbc082 // indirect
122128
go.opentelemetry.io/collector/component/componentstatus v0.126.1-0.20250515040533-97a6accbc082
123129
go.opentelemetry.io/collector/config/configauth v0.126.1-0.20250515040533-97a6accbc082 // indirect
@@ -128,11 +134,11 @@ require (
128134
go.opentelemetry.io/collector/consumer/consumererror v0.126.1-0.20250515040533-97a6accbc082 // indirect
129135
go.opentelemetry.io/collector/extension v1.32.1-0.20250515040533-97a6accbc082 // indirect
130136
go.opentelemetry.io/collector/otelcol/otelcoltest v0.126.1-0.20250515040533-97a6accbc082
131-
go.opentelemetry.io/collector/pdata v1.32.1-0.20250515040533-97a6accbc082 // indirect
137+
go.opentelemetry.io/collector/pdata v1.32.1-0.20250515040533-97a6accbc082
132138
go.opentelemetry.io/collector/pdata/pprofile v0.126.1-0.20250515040533-97a6accbc082 // indirect
133139
go.opentelemetry.io/collector/pipeline v0.126.1-0.20250515040533-97a6accbc082 // indirect
134140
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
135-
go.opentelemetry.io/otel v1.35.0 // indirect
141+
go.opentelemetry.io/otel v1.35.0
136142
go.opentelemetry.io/otel/metric v1.35.0 // indirect
137143
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
138144
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect

receiver/gitlabreceiver/go.sum

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)