Skip to content

Commit 25d6e5b

Browse files
committed
Revert "Add supporting features to enable distributed tracing (Azure#20301)"
This reverts commit 8d1e8af.
1 parent 8d1e8af commit 25d6e5b

19 files changed

+32
-677
lines changed

sdk/azcore/CHANGELOG.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
## 1.5.0-beta.2 (Unreleased)
44

55
### Features Added
6-
* Added supporting features to enable distributed tracing.
7-
* Added func `runtime.StartSpan()` for use by SDKs to start spans.
8-
* Added method `WithContext()` to `runtime.Request` to support shallow cloning with a new context.
9-
* Added field `TracingNamespace` to `runtime.PipelineOptions`.
10-
* Added field `Tracer` to `runtime.NewPollerOptions` and `runtime.NewPollerFromResumeTokenOptions` types.
11-
* Added field `SpanFromContext` to `tracing.TracerOptions`.
12-
* Added methods `Enabled()`, `SetAttributes()`, and `SpanFromContext()` to `tracing.Tracer`.
13-
* Added supporting pipeline policies to include HTTP spans when creating clients.
146

157
### Breaking Changes
168

sdk/azcore/arm/runtime/pipeline.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
1414
armpolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy"
1515
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
16-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported"
1716
azpolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
1817
azruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
1918
)
@@ -35,7 +34,7 @@ func NewPipeline(module, version string, cred azcore.TokenCredential, plOpts azr
3534
})
3635
perRetry := make([]azpolicy.Policy, len(plOpts.PerRetry), len(plOpts.PerRetry)+1)
3736
copy(perRetry, plOpts.PerRetry)
38-
plOpts.PerRetry = append(perRetry, authPolicy, exported.PolicyFunc(httpTraceNamespacePolicy))
37+
plOpts.PerRetry = append(perRetry, authPolicy)
3938
if !options.DisableRPRegistration {
4039
regRPOpts := armpolicy.RegistrationOptions{ClientOptions: options.ClientOptions}
4140
regPolicy, err := NewRPRegistrationPolicy(cred, &regRPOpts)

sdk/azcore/arm/runtime/policy_trace_namespace.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

sdk/azcore/arm/runtime/policy_trace_namespace_test.go

Lines changed: 0 additions & 97 deletions
This file was deleted.

sdk/azcore/core.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ func NewClient(clientName, moduleVersion string, plOpts runtime.PipelineOptions,
9999
pl := runtime.NewPipeline(pkg, moduleVersion, plOpts, options)
100100

101101
tr := options.TracingProvider.NewTracer(clientName, moduleVersion)
102-
if tr.Enabled() && plOpts.TracingNamespace != "" {
103-
tr.SetAttributes(tracing.Attribute{Key: "az.namespace", Value: plOpts.TracingNamespace})
104-
}
105102
return &Client{pl: pl, tr: tr}, nil
106103
}
107104

sdk/azcore/core_test.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@
77
package azcore
88

99
import (
10-
"context"
11-
"net/http"
1210
"reflect"
1311
"testing"
1412

15-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported"
16-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/shared"
1713
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
1814
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
19-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/tracing"
20-
"github.com/Azure/azure-sdk-for-go/sdk/internal/mock"
2115
"github.com/stretchr/testify/require"
2216
)
2317

@@ -137,38 +131,3 @@ func TestNewClientError(t *testing.T) {
137131
require.Error(t, err)
138132
require.Nil(t, client)
139133
}
140-
141-
func TestNewClientTracingEnabled(t *testing.T) {
142-
srv, close := mock.NewServer()
143-
defer close()
144-
145-
var attrString string
146-
client, err := NewClient("package.Client", "v1.0.0", runtime.PipelineOptions{TracingNamespace: "Widget.Factory"}, &policy.ClientOptions{
147-
TracingProvider: tracing.NewProvider(func(name, version string) tracing.Tracer {
148-
return tracing.NewTracer(func(ctx context.Context, spanName string, options *tracing.SpanOptions) (context.Context, tracing.Span) {
149-
require.NotNil(t, options)
150-
for _, attr := range options.Attributes {
151-
if attr.Key == "az.namespace" {
152-
v, ok := attr.Value.(string)
153-
require.True(t, ok)
154-
attrString = attr.Key + ":" + v
155-
}
156-
}
157-
return ctx, tracing.Span{}
158-
}, nil)
159-
}, nil),
160-
Transport: srv,
161-
})
162-
require.NoError(t, err)
163-
require.NotNil(t, client)
164-
require.NotZero(t, client.Pipeline())
165-
require.NotZero(t, client.Tracer())
166-
167-
const requestEndpoint = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/fakeResourceGroupo/providers/Microsoft.Storage/storageAccounts/fakeAccountName"
168-
req, err := exported.NewRequest(context.WithValue(context.Background(), shared.CtxWithTracingTracer{}, client.Tracer()), http.MethodGet, srv.URL()+requestEndpoint)
169-
require.NoError(t, err)
170-
srv.AppendResponse()
171-
_, err = client.Pipeline().Do(req)
172-
require.NoError(t, err)
173-
require.EqualValues(t, "az.namespace:Widget.Factory", attrString)
174-
}

sdk/azcore/internal/exported/request.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,6 @@ func (req *Request) Clone(ctx context.Context) *Request {
170170
return &r2
171171
}
172172

173-
// WithContext returns a shallow copy of the request with its context changed to ctx.
174-
func (req *Request) WithContext(ctx context.Context) *Request {
175-
r2 := new(Request)
176-
*r2 = *req
177-
r2.req = r2.req.WithContext(ctx)
178-
return r2
179-
}
180-
181173
// not exported but dependent on Request
182174

183175
// PolicyFunc is a type that implements the Policy interface.

sdk/azcore/internal/exported/request_test.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,3 @@ func TestNewRequestFail(t *testing.T) {
194194
t.Fatal("unexpected request")
195195
}
196196
}
197-
198-
func TestRequestWithContext(t *testing.T) {
199-
type ctxKey1 struct{}
200-
type ctxKey2 struct{}
201-
202-
req1, err := NewRequest(context.WithValue(context.Background(), ctxKey1{}, 1), http.MethodPost, testURL)
203-
require.NoError(t, err)
204-
require.NotNil(t, req1.Raw().Context().Value(ctxKey1{}))
205-
206-
req2 := req1.WithContext(context.WithValue(context.Background(), ctxKey2{}, 1))
207-
require.Nil(t, req2.Raw().Context().Value(ctxKey1{}))
208-
require.NotNil(t, req2.Raw().Context().Value(ctxKey2{}))
209-
210-
// shallow copy, so changing req2 affects req1
211-
req2.Raw().Header.Add("added-req2", "value")
212-
require.EqualValues(t, "value", req1.Raw().Header.Get("added-req2"))
213-
}

sdk/azcore/internal/shared/constants.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const (
2323
HeaderUserAgent = "User-Agent"
2424
HeaderWWWAuthenticate = "WWW-Authenticate"
2525
HeaderXMSClientRequestID = "x-ms-client-request-id"
26-
HeaderXMSRequestID = "x-ms-request-id"
2726
)
2827

2928
const BearerTokenPrefix = "Bearer "

sdk/azcore/internal/shared/shared.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ type CtxWithRetryOptionsKey struct{}
2828
// CtxIncludeResponseKey is used as a context key for retrieving the raw response.
2929
type CtxIncludeResponseKey struct{}
3030

31-
// CtxWithTracingTracer is used as a context key for adding/retrieving tracing.Tracer.
32-
type CtxWithTracingTracer struct{}
33-
3431
// Delay waits for the duration to elapse or the context to be cancelled.
3532
func Delay(ctx context.Context, delay time.Duration) error {
3633
select {

sdk/azcore/policy/policy.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ type Request = exported.Request
2929
// ClientOptions contains optional settings for a client's pipeline.
3030
// All zero-value fields will be initialized with default values.
3131
type ClientOptions struct {
32-
// APIVersion overrides the default version requested of the service.
33-
// Set with caution as this package version has not been tested with arbitrary service versions.
32+
// APIVersion overrides the default version requested of the service. Set with caution as this package version has not been tested with arbitrary service versions.
3433
APIVersion string
3534

3635
// Cloud specifies a cloud for the client. The default is Azure Public Cloud.

sdk/azcore/runtime/pager.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import (
1010
"context"
1111
"encoding/json"
1212
"errors"
13-
"fmt"
14-
"reflect"
15-
16-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/tracing"
1713
)
1814

1915
// PagingHandler contains the required data for constructing a Pager.
@@ -24,16 +20,12 @@ type PagingHandler[T any] struct {
2420

2521
// Fetcher fetches the first and subsequent pages.
2622
Fetcher func(context.Context, *T) (T, error)
27-
28-
// Tracer contains the Tracer from the client that's creating the Pager.
29-
Tracer tracing.Tracer
3023
}
3124

3225
// Pager provides operations for iterating over paged responses.
3326
type Pager[T any] struct {
3427
current *T
3528
handler PagingHandler[T]
36-
tracer tracing.Tracer
3729
firstPage bool
3830
}
3931

@@ -42,7 +34,6 @@ type Pager[T any] struct {
4234
func NewPager[T any](handler PagingHandler[T]) *Pager[T] {
4335
return &Pager[T]{
4436
handler: handler,
45-
tracer: handler.Tracer,
4637
firstPage: true,
4738
}
4839
}
@@ -67,14 +58,10 @@ func (p *Pager[T]) NextPage(ctx context.Context) (T, error) {
6758
} else if !p.handler.More(*p.current) {
6859
return *new(T), errors.New("no more pages")
6960
}
70-
ctx, endSpan := StartSpan(ctx, fmt.Sprintf("%s.NextPage", shortenTypeName(reflect.TypeOf(*p).Name())), p.tracer, nil)
71-
defer endSpan(err)
7261
resp, err = p.handler.Fetcher(ctx, p.current)
7362
} else {
7463
// non-LRO case, first page
7564
p.firstPage = false
76-
ctx, endSpan := StartSpan(ctx, fmt.Sprintf("%s.NextPage", shortenTypeName(reflect.TypeOf(*p).Name())), p.tracer, nil)
77-
defer endSpan(err)
7865
resp, err = p.handler.Fetcher(ctx, nil)
7966
}
8067
if err != nil {

sdk/azcore/runtime/pipeline.go

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,9 @@ import (
1313

1414
// PipelineOptions contains Pipeline options for SDK developers
1515
type PipelineOptions struct {
16-
// AllowedHeaders is the slice of headers to log with their values intact.
17-
// All headers not in the slice will have their values REDACTED.
18-
// Applies to request and response headers.
19-
AllowedHeaders []string
20-
21-
// AllowedQueryParameters is the slice of query parameters to log with their values intact.
22-
// All query parameters not in the slice will have their values REDACTED.
23-
AllowedQueryParameters []string
24-
25-
// APIVersion overrides the default version requested of the service.
26-
// Set with caution as this package version has not been tested with arbitrary service versions.
27-
APIVersion APIVersionOptions
28-
29-
// PerCall contains custom policies to inject into the pipeline.
30-
// Each policy is executed once per request.
31-
PerCall []policy.Policy
32-
33-
// PerRetry contains custom policies to inject into the pipeline.
34-
// Each policy is executed once per request, and for each retry of that request.
35-
PerRetry []policy.Policy
36-
37-
// TracingNamespace contains the value to use for the az.namespace span attribute.
38-
TracingNamespace string
16+
AllowedHeaders, AllowedQueryParameters []string
17+
APIVersion APIVersionOptions
18+
PerCall, PerRetry []policy.Policy
3919
}
4020

4121
// Pipeline represents a primitive for sending HTTP requests and receiving responses.
@@ -76,10 +56,8 @@ func NewPipeline(module, version string, plOpts PipelineOptions, options *policy
7656
policies = append(policies, NewRetryPolicy(&cp.Retry))
7757
policies = append(policies, plOpts.PerRetry...)
7858
policies = append(policies, cp.PerRetryPolicies...)
79-
policies = append(policies, exported.PolicyFunc(httpHeaderPolicy))
80-
policies = append(policies, newHTTPTracePolicy(cp.Logging.AllowedQueryParams))
8159
policies = append(policies, NewLogPolicy(&cp.Logging))
82-
policies = append(policies, exported.PolicyFunc(bodyDownloadPolicy))
60+
policies = append(policies, exported.PolicyFunc(httpHeaderPolicy), exported.PolicyFunc(bodyDownloadPolicy))
8361
transport := cp.Transport
8462
if transport == nil {
8563
transport = defaultHTTPClient

0 commit comments

Comments
 (0)