Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions azure/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package azure

import (
"context"
"fmt"
"net/http"
"regexp"
Expand All @@ -28,8 +27,8 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/azure-sdk-for-go/sdk/tracing/azotel"
"go.opentelemetry.io/otel"

"sigs.k8s.io/cluster-api-provider-azure/pkg/ot"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
"sigs.k8s.io/cluster-api-provider-azure/version"
)
Expand Down Expand Up @@ -380,11 +379,7 @@ func ARMClientOptions(azureEnvironment string, extraPolicies ...policy.Policy) (
opts.PerCallPolicies = append(opts.PerCallPolicies, extraPolicies...)
opts.Retry.MaxRetries = -1 // Less than zero means one try and no retries.

otelTP, err := ot.OTLPTracerProvider(context.TODO())
if err != nil {
return nil, err
}
opts.TracingProvider = azotel.NewTracingProvider(otelTP, nil)
opts.TracingProvider = azotel.NewTracingProvider(otel.GetTracerProvider(), nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these reflect changing things that were first introduced in 1.18? As far as I can tell these changes were introduced in the v1.17.0 release:

cc @nojnhuh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That PR only exists for 1.18 not backported AFAICT: abd8819

I don't really know if this is all totally "correct" or "the right way to do things"

Turns out it is neither. This looks much better! I can still see the traces.

/lgtm


return opts, nil
}
Expand Down
9 changes: 3 additions & 6 deletions azure/scope/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/tracing/azotel"
"github.com/pkg/errors"
"go.opentelemetry.io/otel"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/pkg/ot"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)

Expand Down Expand Up @@ -90,11 +90,7 @@ func (p *AzureCredentialsProvider) GetTokenCredential(ctx context.Context, resou
var authErr error
var cred azcore.TokenCredential

otelTP, err := ot.OTLPTracerProvider(ctx)
if err != nil {
return nil, err
}
tracingProvider := azotel.NewTracingProvider(otelTP, nil)
tracingProvider := azotel.NewTracingProvider(otel.GetTracerProvider(), nil)

switch p.Identity.Spec.Type {
case infrav1.WorkloadIdentity:
Expand Down Expand Up @@ -134,6 +130,7 @@ func (p *AzureCredentialsProvider) GetTokenCredential(ctx context.Context, resou
case infrav1.ServicePrincipalCertificate:
var certsContent []byte
if p.Identity.Spec.CertPath != "" {
var err error
certsContent, err = os.ReadFile(p.Identity.Spec.CertPath)
if err != nil {
return nil, errors.Wrap(err, "failed to read certificate file")
Expand Down
9 changes: 2 additions & 7 deletions controllers/aso_credential_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/tracing/azotel"
asoannotations "github.com/Azure/azure-service-operator/v2/pkg/common/annotations"
"github.com/Azure/azure-service-operator/v2/pkg/common/config"
"go.opentelemetry.io/otel"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/scope"
"sigs.k8s.io/cluster-api-provider-azure/pkg/ot"
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)

Expand Down Expand Up @@ -98,13 +98,8 @@ func (c *asoCredentialCache) clientOptsForASOResource(ctx context.Context, obj c
return azcore.ClientOptions{}, err
}

otelTP, err := ot.OTLPTracerProvider(ctx)
if err != nil {
return azcore.ClientOptions{}, err
}

opts := azcore.ClientOptions{
TracingProvider: azotel.NewTracingProvider(otelTP, nil),
TracingProvider: azotel.NewTracingProvider(otel.GetTracerProvider(), nil),
Cloud: cloud.Configuration{
ActiveDirectoryAuthorityHost: string(secret.Data[config.AzureAuthorityHost]),
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/ot/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

// RegisterTracing enables code tracing via OpenTelemetry.
func RegisterTracing(ctx context.Context, log logr.Logger) error {
tp, err := OTLPTracerProvider(ctx)
tp, err := otlpTracerProvider(ctx)

Check warning on line 38 in pkg/ot/traces.go

View check run for this annotation

Codecov / codecov/patch

pkg/ot/traces.go#L38

Added line #L38 was not covered by tests
if err != nil {
return err
}
Expand All @@ -54,8 +54,8 @@
return nil
}

// OTLPTracerProvider initializes an OTLP exporter and configures the corresponding tracer provider.
func OTLPTracerProvider(ctx context.Context) (*sdktrace.TracerProvider, error) {
// otlpTracerProvider initializes an OTLP exporter and configures the corresponding tracer provider.
func otlpTracerProvider(ctx context.Context) (*sdktrace.TracerProvider, error) {

Check warning on line 58 in pkg/ot/traces.go

View check run for this annotation

Codecov / codecov/patch

pkg/ot/traces.go#L58

Added line #L58 was not covered by tests
res, err := resource.New(ctx,
resource.WithAttributes(
semconv.ServiceNameKey.String("capz"),
Expand Down