Skip to content

Commit 5ab7190

Browse files
committed
Add OpenTelemetry tracing for AWS calls
- add tracing helper package - instrument reconciliation flows - update tests for traced contexts
1 parent 2a73e72 commit 5ab7190

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

controllers/awsmachine_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func TestAWSMachineReconcilerIntegrationTests(t *testing.T) {
258258
expect := func(m *mocks.MockEC2APIMockRecorder, s *mock_services.MockSecretInterfaceMockRecorder, e *mocks.MockELBAPIMockRecorder) {
259259
mockedCreateInstanceCalls(m)
260260
mockedCreateSecretCall(s)
261-
e.DescribeLoadBalancers(ctx, gomock.Eq(&elb.DescribeLoadBalancersInput{
261+
e.DescribeLoadBalancers(gomock.Any(), gomock.Eq(&elb.DescribeLoadBalancersInput{
262262
LoadBalancerNames: []string{"test-cluster-apiserver"},
263263
})).
264264
Return(&elb.DescribeLoadBalancersOutput{}, nil)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ func initFlags(fs *pflag.FlagSet) {
655655

656656
fs.StringVar(
657657
&tracingEndPoint,
658-
"otel-endpoint",
658+
"trace-endpoint",
659659
"",
660660
"OpenTelemetry trace collection endpoint",
661661
)

pkg/otel/tracing/traces.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
Copyright 2026 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package otel provides OpenTelemetry tracing initialization and helper.
118
package otel
219

320
import (
@@ -10,12 +27,12 @@ import (
1027
sdktrace "go.opentelemetry.io/otel/sdk/trace"
1128
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
1229
"go.opentelemetry.io/otel/trace"
30+
1331
"sigs.k8s.io/cluster-api-provider-aws/v2/version"
1432
)
1533

16-
// function to initialize tracer
34+
// InitTracer initializes the OpenTelemetry tracer provider.
1735
func InitTracer(ctx context.Context, traceSamplingRatio float64, tracingEndPoint string) (*sdktrace.TracerProvider, error) {
18-
1936
if tracingEndPoint == "" {
2037
return nil, nil
2138
}
@@ -46,12 +63,13 @@ func InitTracer(ctx context.Context, traceSamplingRatio float64, tracingEndPoint
4663
)
4764

4865
otel.SetTracerProvider(tp)
66+
4967
return tp, nil
5068
}
5169

52-
// function to start span for given context
70+
// StartSpan starts a new OpenTelemetry span for the given context.
5371
func StartSpan(ctx context.Context, tracerName string, spanName string) (context.Context, trace.Span) {
54-
5572
tr := otel.Tracer(tracerName)
73+
5674
return tr.Start(ctx, spanName)
5775
}

0 commit comments

Comments
 (0)