From 4acec8062978dbf01a7e4abe0f050d5523913404 Mon Sep 17 00:00:00 2001 From: Joel Hendrix Date: Wed, 15 Nov 2023 14:35:51 -0800 Subject: [PATCH] Add tracing spans to azquery (#21986) * Add tracing spans to azquery * fix moduleName const * remove vestigial setting --- sdk/monitor/azquery/CHANGELOG.md | 1 + sdk/monitor/azquery/autorest.md | 2 +- sdk/monitor/azquery/custom_client.go | 4 ++-- sdk/monitor/azquery/logs_client.go | 6 ++++++ sdk/monitor/azquery/metrics_client.go | 4 ++++ sdk/monitor/azquery/version.go | 2 +- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sdk/monitor/azquery/CHANGELOG.md b/sdk/monitor/azquery/CHANGELOG.md index fb6606ebc3e5..2045ac7951b7 100644 --- a/sdk/monitor/azquery/CHANGELOG.md +++ b/sdk/monitor/azquery/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bugs Fixed ### Other Changes +* Enabled spans for distributed tracing. ## 1.1.0 (2023-05-09) diff --git a/sdk/monitor/azquery/autorest.md b/sdk/monitor/azquery/autorest.md index 7986bd012f88..e337c59ace87 100644 --- a/sdk/monitor/azquery/autorest.md +++ b/sdk/monitor/azquery/autorest.md @@ -3,7 +3,6 @@ ``` yaml title: Logs Query Client clear-output-folder: false -export-clients: true go: true input-file: - https://github.com/Azure/azure-rest-api-specs/blob/72427ef3ff5875bd8409ef112ef5e6f3cf2b8795/specification/operationalinsights/data-plane/Microsoft.OperationalInsights/stable/2022-10-27/OperationalInsights.json @@ -13,6 +12,7 @@ openapi-type: "data-plane" output-folder: ../azquery security: "AADToken" use: "@autorest/go@4.0.0-preview.60" +inject-spans: true version: "^3.0.0" directive: diff --git a/sdk/monitor/azquery/custom_client.go b/sdk/monitor/azquery/custom_client.go index 90c629877429..2a6b30b078a4 100644 --- a/sdk/monitor/azquery/custom_client.go +++ b/sdk/monitor/azquery/custom_client.go @@ -46,7 +46,7 @@ func NewLogsClient(credential azcore.TokenCredential, options *LogsClientOptions } authPolicy := runtime.NewBearerTokenPolicy(credential, []string{c.Audience + "/.default"}, nil) - azcoreClient, err := azcore.NewClient("azquery.LogsClient", version, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) + azcoreClient, err := azcore.NewClient(moduleName, version, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) if err != nil { return nil, err } @@ -67,7 +67,7 @@ func NewMetricsClient(credential azcore.TokenCredential, options *MetricsClientO } authPolicy := runtime.NewBearerTokenPolicy(credential, []string{c.Audience + "/.default"}, nil) - azcoreClient, err := azcore.NewClient("azquery.MetricsClient", version, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) + azcoreClient, err := azcore.NewClient(moduleName, version, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions) if err != nil { return nil, err } diff --git a/sdk/monitor/azquery/logs_client.go b/sdk/monitor/azquery/logs_client.go index 44cafbd72820..2549dcc6bdbe 100644 --- a/sdk/monitor/azquery/logs_client.go +++ b/sdk/monitor/azquery/logs_client.go @@ -35,6 +35,8 @@ type LogsClient struct { // - options - LogsClientQueryBatchOptions contains the optional parameters for the LogsClient.QueryBatch method. func (client *LogsClient) QueryBatch(ctx context.Context, body BatchRequest, options *LogsClientQueryBatchOptions) (LogsClientQueryBatchResponse, error) { var err error + ctx, endSpan := runtime.StartSpan(ctx, "LogsClient.QueryBatch", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.queryBatchCreateRequest(ctx, body, options) if err != nil { return LogsClientQueryBatchResponse{}, err @@ -85,6 +87,8 @@ func (client *LogsClient) queryBatchHandleResponse(resp *http.Response) (LogsCli // - options - LogsClientQueryResourceOptions contains the optional parameters for the LogsClient.QueryResource method. func (client *LogsClient) QueryResource(ctx context.Context, resourceID string, body Body, options *LogsClientQueryResourceOptions) (LogsClientQueryResourceResponse, error) { var err error + ctx, endSpan := runtime.StartSpan(ctx, "LogsClient.QueryResource", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.queryResourceCreateRequest(ctx, resourceID, body, options) if err != nil { return LogsClientQueryResourceResponse{}, err @@ -138,6 +142,8 @@ func (client *LogsClient) queryResourceHandleResponse(resp *http.Response) (Logs // - options - LogsClientQueryWorkspaceOptions contains the optional parameters for the LogsClient.QueryWorkspace method. func (client *LogsClient) QueryWorkspace(ctx context.Context, workspaceID string, body Body, options *LogsClientQueryWorkspaceOptions) (LogsClientQueryWorkspaceResponse, error) { var err error + ctx, endSpan := runtime.StartSpan(ctx, "LogsClient.QueryWorkspace", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.queryWorkspaceCreateRequest(ctx, workspaceID, body, options) if err != nil { return LogsClientQueryWorkspaceResponse{}, err diff --git a/sdk/monitor/azquery/metrics_client.go b/sdk/monitor/azquery/metrics_client.go index add4860f55d4..774b738e050d 100644 --- a/sdk/monitor/azquery/metrics_client.go +++ b/sdk/monitor/azquery/metrics_client.go @@ -50,6 +50,7 @@ func (client *MetricsClient) NewListDefinitionsPager(resourceURI string, options } return client.listDefinitionsHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -105,6 +106,7 @@ func (client *MetricsClient) NewListNamespacesPager(resourceURI string, options } return client.listNamespacesHandleResponse(resp) }, + Tracer: client.internal.Tracer(), }) } @@ -143,6 +145,8 @@ func (client *MetricsClient) listNamespacesHandleResponse(resp *http.Response) ( // - options - MetricsClientQueryResourceOptions contains the optional parameters for the MetricsClient.QueryResource method. func (client *MetricsClient) QueryResource(ctx context.Context, resourceURI string, options *MetricsClientQueryResourceOptions) (MetricsClientQueryResourceResponse, error) { var err error + ctx, endSpan := runtime.StartSpan(ctx, "MetricsClient.QueryResource", client.internal.Tracer(), nil) + defer func() { endSpan(err) }() req, err := client.queryResourceCreateRequest(ctx, resourceURI, options) if err != nil { return MetricsClientQueryResourceResponse{}, err diff --git a/sdk/monitor/azquery/version.go b/sdk/monitor/azquery/version.go index 3e826b868deb..9f3daf91f432 100644 --- a/sdk/monitor/azquery/version.go +++ b/sdk/monitor/azquery/version.go @@ -7,6 +7,6 @@ package azquery const ( - moduleName = "azquery" + moduleName = "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery" version = "v1.1.1" )