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.
118package otel
219
320import (
@@ -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.
1735func 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.
5371func 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