Skip to content

Commit 8c1a496

Browse files
authored
Rename clientName param to moduleName (#21893)
Per spec, the tracer name should be the name of the module. Removed some unnecessary code.
1 parent 5b641bb commit 8c1a496

File tree

8 files changed

+24
-125
lines changed

8 files changed

+24
-125
lines changed

sdk/azcore/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
### Other Changes
2424

2525
* Skip generating trace info for no-op tracers.
26+
* The `clientName` paramater in client constructors has been renamed to `moduleName`.
2627

2728
## 1.9.0-beta.1 (2023-10-05)
2829

sdk/azcore/arm/client.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,11 @@ type Client struct {
2828

2929
// NewClient creates a new Client instance with the provided values.
3030
// This client is intended to be used with Azure Resource Manager endpoints.
31-
// - clientName - the fully qualified name of the client ("module/package.Client"); this is used by the telemetry policy and tracing provider.
32-
// if module and package are the same value, the "module/" prefix can be omitted.
33-
// - moduleVersion - the version of the containing module; used by the telemetry policy
31+
// - moduleName - the fully qualified name of the module where the client is defined; used by the telemetry policy and tracing provider.
32+
// - moduleVersion - the semantic version of the module; used by the telemetry policy and tracing provider.
3433
// - cred - the TokenCredential used to authenticate the request
3534
// - options - optional client configurations; pass nil to accept the default values
36-
func NewClient(clientName, moduleVersion string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
37-
mod, client, err := shared.ExtractModuleName(clientName)
38-
if err != nil {
39-
return nil, err
40-
}
41-
35+
func NewClient(moduleName, moduleVersion string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
4236
if options == nil {
4337
options = &ClientOptions{}
4438
}
@@ -53,12 +47,12 @@ func NewClient(clientName, moduleVersion string, cred azcore.TokenCredential, op
5347
if c, ok := options.Cloud.Services[cloud.ResourceManager]; ok {
5448
ep = c.Endpoint
5549
}
56-
pl, err := armruntime.NewPipeline(mod, moduleVersion, cred, runtime.PipelineOptions{}, options)
50+
pl, err := armruntime.NewPipeline(moduleName, moduleVersion, cred, runtime.PipelineOptions{}, options)
5751
if err != nil {
5852
return nil, err
5953
}
6054

61-
tr := options.TracingProvider.NewTracer(client, moduleVersion)
55+
tr := options.TracingProvider.NewTracer(moduleName, moduleVersion)
6256
return &Client{ep: ep, pl: pl, tr: tr}, nil
6357
}
6458

sdk/azcore/arm/client_test.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ func (mc fakeCredential) GetToken(ctx context.Context, options policy.TokenReque
2424
}
2525

2626
func TestNewClient(t *testing.T) {
27-
client, err := NewClient("package.Client", "v1.0.0", fakeCredential{}, nil)
27+
client, err := NewClient("module", "v1.0.0", fakeCredential{}, nil)
2828
require.NoError(t, err)
2929
require.NotNil(t, client)
3030
require.Equal(t, cloud.AzurePublic.Services[cloud.ResourceManager].Endpoint, client.Endpoint())
3131
require.NotZero(t, client.Pipeline())
3232
require.Zero(t, client.Tracer())
3333

34-
client, err = NewClient("package.Client", "", fakeCredential{}, &ClientOptions{
34+
client, err = NewClient("module", "", fakeCredential{}, &ClientOptions{
3535
ClientOptions: azcore.ClientOptions{
3636
Cloud: cloud.AzureChina,
3737
Telemetry: policy.TelemetryOptions{
@@ -45,11 +45,7 @@ func TestNewClient(t *testing.T) {
4545
}
4646

4747
func TestNewClientError(t *testing.T) {
48-
client, err := NewClient("malformed", "v1.0.0", fakeCredential{}, nil)
49-
require.Error(t, err)
50-
require.Nil(t, client)
51-
52-
client, err = NewClient("package.Client", "malformed", fakeCredential{}, nil)
48+
client, err := NewClient("module", "malformed", fakeCredential{}, nil)
5349
require.Error(t, err)
5450
require.Nil(t, client)
5551

@@ -60,7 +56,7 @@ func TestNewClientError(t *testing.T) {
6056
},
6157
},
6258
}
63-
client, err = NewClient("package.Client", "v1.0.0", fakeCredential{}, &ClientOptions{
59+
client, err = NewClient("module", "v1.0.0", fakeCredential{}, &ClientOptions{
6460
ClientOptions: azcore.ClientOptions{
6561
Cloud: badCloud,
6662
},

sdk/azcore/core.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,11 @@ type Client struct {
101101
}
102102

103103
// NewClient creates a new Client instance with the provided values.
104-
// - clientName - the fully qualified name of the client ("module/package.Client"); this is used by the telemetry policy and tracing provider.
105-
// if module and package are the same value, the "module/" prefix can be omitted.
106-
// - moduleVersion - the semantic version of the containing module; used by the telemetry policy
104+
// - moduleName - the fully qualified name of the module where the client is defined; used by the telemetry policy and tracing provider.
105+
// - moduleVersion - the semantic version of the module; used by the telemetry policy and tracing provider.
107106
// - plOpts - pipeline configuration options; can be the zero-value
108107
// - options - optional client configurations; pass nil to accept the default values
109-
func NewClient(clientName, moduleVersion string, plOpts runtime.PipelineOptions, options *ClientOptions) (*Client, error) {
110-
mod, client, err := shared.ExtractModuleName(clientName)
111-
if err != nil {
112-
return nil, err
113-
}
114-
108+
func NewClient(moduleName, moduleVersion string, plOpts runtime.PipelineOptions, options *ClientOptions) (*Client, error) {
115109
if options == nil {
116110
options = &ClientOptions{}
117111
}
@@ -122,9 +116,9 @@ func NewClient(clientName, moduleVersion string, plOpts runtime.PipelineOptions,
122116
}
123117
}
124118

125-
pl := runtime.NewPipeline(mod, moduleVersion, plOpts, options)
119+
pl := runtime.NewPipeline(moduleName, moduleVersion, plOpts, options)
126120

127-
tr := options.TracingProvider.NewTracer(client, moduleVersion)
121+
tr := options.TracingProvider.NewTracer(moduleName, moduleVersion)
128122
if tr.Enabled() && plOpts.Tracing.Namespace != "" {
129123
tr.SetAttributes(tracing.Attribute{Key: shared.TracingNamespaceAttrName, Value: plOpts.Tracing.Namespace})
130124
}

sdk/azcore/core_test.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,6 @@ func TestNewClient(t *testing.T) {
128128
require.NotNil(t, client)
129129
}
130130

131-
func TestNewClientError(t *testing.T) {
132-
client, err := NewClient("malformed", "v1.0.0", runtime.PipelineOptions{}, nil)
133-
require.Error(t, err)
134-
require.Nil(t, client)
135-
136-
client, err = NewClient("package.Client", "malformed", runtime.PipelineOptions{}, nil)
137-
require.Error(t, err)
138-
require.Nil(t, client)
139-
}
140-
141131
func TestNewClientTracingEnabled(t *testing.T) {
142132
srv, close := mock.NewServer()
143133
defer close()
@@ -184,7 +174,7 @@ func TestClientWithClientName(t *testing.T) {
184174
var clientName string
185175
var modVersion string
186176
var attrString string
187-
client, err := NewClient("module/package.Client", "v1.0.0", runtime.PipelineOptions{
177+
client, err := NewClient("module", "v1.0.0", runtime.PipelineOptions{
188178
Tracing: runtime.TracingOptions{
189179
Namespace: "Widget.Factory",
190180
},
@@ -210,7 +200,7 @@ func TestClientWithClientName(t *testing.T) {
210200
require.NotNil(t, client)
211201
require.NotZero(t, client.Pipeline())
212202
require.NotZero(t, client.Tracer())
213-
require.EqualValues(t, "package.Client", clientName)
203+
require.EqualValues(t, "module", clientName)
214204
require.EqualValues(t, "v1.0.0", modVersion)
215205

216206
const requestEndpoint = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/fakeResourceGroupo/providers/Microsoft.Storage/storageAccounts/fakeAccountName"
@@ -221,8 +211,8 @@ func TestClientWithClientName(t *testing.T) {
221211
require.NoError(t, err)
222212
require.EqualValues(t, "az.namespace:Widget.Factory", attrString)
223213

224-
newClient := client.WithClientName("other.Client")
225-
require.EqualValues(t, "other.Client", clientName)
214+
newClient := client.WithClientName("other")
215+
require.EqualValues(t, "other", clientName)
226216
require.EqualValues(t, "v1.0.0", modVersion)
227217
require.EqualValues(t, client.Pipeline(), newClient.Pipeline())
228218
_, err = newClient.Pipeline().Do(req)

sdk/azcore/internal/shared/shared.go

-24
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,6 @@ func ValidateModVer(moduleVersion string) error {
8787
return nil
8888
}
8989

90-
// ExtractModuleName returns "module", "package.Client" from "module/package.Client" or
91-
// "package", "package.Client" from "package.Client" when there's no "module/" prefix.
92-
// If clientName is malformed, an error is returned.
93-
func ExtractModuleName(clientName string) (string, string, error) {
94-
// uses unnamed capturing for "module", "package.Client", and "package"
95-
regex, err := regexp.Compile(`^(?:([a-z0-9]+)/)?(([a-z0-9]+)\.(?:[A-Za-z0-9]+))$`)
96-
if err != nil {
97-
return "", "", err
98-
}
99-
100-
matches := regex.FindStringSubmatch(clientName)
101-
if len(matches) < 4 {
102-
return "", "", fmt.Errorf("malformed clientName %s", clientName)
103-
}
104-
105-
// the first match is the entire string, the second is "module", the third is
106-
// "package.Client" and the fourth is "package".
107-
// if there was no "module/" prefix, the second match will be the empty string
108-
if matches[1] != "" {
109-
return matches[1], matches[2], nil
110-
}
111-
return matches[3], matches[2], nil
112-
}
113-
11490
// ContextWithDeniedValues wraps an existing [context.Context], denying access to certain context values.
11591
// Pipeline policies that create new requests to be sent down their own pipeline MUST wrap the caller's
11692
// context with an instance of this type. This is to prevent context values from flowing across disjoint

sdk/azcore/internal/shared/shared_test.go

-52
Original file line numberDiff line numberDiff line change
@@ -85,58 +85,6 @@ func TestValidateModVer(t *testing.T) {
8585
require.Error(t, ValidateModVer("v1.2"))
8686
}
8787

88-
func TestExtractModuleName(t *testing.T) {
89-
mod, client, err := ExtractModuleName("module/package.Client")
90-
require.NoError(t, err)
91-
require.Equal(t, "module", mod)
92-
require.Equal(t, "package.Client", client)
93-
94-
mod, client, err = ExtractModuleName("malformed/")
95-
require.Error(t, err)
96-
require.Empty(t, mod)
97-
require.Empty(t, client)
98-
99-
mod, client, err = ExtractModuleName("malformed/malformed")
100-
require.Error(t, err)
101-
require.Empty(t, mod)
102-
require.Empty(t, client)
103-
104-
mod, client, err = ExtractModuleName("malformed/malformed.")
105-
require.Error(t, err)
106-
require.Empty(t, mod)
107-
require.Empty(t, client)
108-
109-
mod, client, err = ExtractModuleName("malformed/.malformed")
110-
require.Error(t, err)
111-
require.Empty(t, mod)
112-
require.Empty(t, client)
113-
114-
mod, client, err = ExtractModuleName("package.Client")
115-
require.NoError(t, err)
116-
require.Equal(t, "package", mod)
117-
require.Equal(t, "package.Client", client)
118-
119-
mod, client, err = ExtractModuleName("malformed")
120-
require.Error(t, err)
121-
require.Empty(t, mod)
122-
require.Empty(t, client)
123-
124-
mod, client, err = ExtractModuleName(".malformed")
125-
require.Error(t, err)
126-
require.Empty(t, mod)
127-
require.Empty(t, client)
128-
129-
mod, client, err = ExtractModuleName("malformed.")
130-
require.Error(t, err)
131-
require.Empty(t, mod)
132-
require.Empty(t, client)
133-
134-
mod, client, err = ExtractModuleName("")
135-
require.Error(t, err)
136-
require.Empty(t, mod)
137-
require.Empty(t, client)
138-
}
139-
14088
func TestContextWithDeniedValues(t *testing.T) {
14189
type testKey struct{}
14290
const value = "value"

sdk/azcore/tracing/tracing.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ type Provider struct {
3131
newTracerFn func(name, version string) Tracer
3232
}
3333

34-
// NewTracer creates a new Tracer for the specified name and version.
35-
// - name - the name of the tracer object, typically the fully qualified name of the service client
36-
// - version - the version of the module in which the service client resides
37-
func (p Provider) NewTracer(name, version string) (tracer Tracer) {
34+
// NewTracer creates a new Tracer for the specified module name and version.
35+
// - module - the fully qualified name of the module
36+
// - version - the version of the module
37+
func (p Provider) NewTracer(module, version string) (tracer Tracer) {
3838
if p.newTracerFn != nil {
39-
tracer = p.newTracerFn(name, version)
39+
tracer = p.newTracerFn(module, version)
4040
}
4141
return
4242
}

0 commit comments

Comments
 (0)