diff --git a/sdk/anomalydetector/ai-anomaly-detector/package.json b/sdk/anomalydetector/ai-anomaly-detector/package.json index 91aecad1c45c..c8ad2bd27fd8 100644 --- a/sdk/anomalydetector/ai-anomaly-detector/package.json +++ b/sdk/anomalydetector/ai-anomaly-detector/package.json @@ -67,7 +67,7 @@ "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0", - "@azure/core-tracing": "1.0.0-preview.9" + "@azure/core-tracing": "1.0.0-beta.1" }, "devDependencies": { "@azure/dev-tool": "^1.0.0", diff --git a/sdk/anomalydetector/ai-anomaly-detector/src/tracing.ts b/sdk/anomalydetector/ai-anomaly-detector/src/tracing.ts index b088d784b5c5..2c88a5a12c9b 100644 --- a/sdk/anomalydetector/ai-anomaly-detector/src/tracing.ts +++ b/sdk/anomalydetector/ai-anomaly-detector/src/tracing.ts @@ -1,58 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer, OperationTracingOptions } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan( - `Azure.CognitiveServices.AnomalyDetector.${operationName}`, - spanOptions - ); - - span.setAttribute("az.namespace", "Microsoft.CognitiveServices"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.CognitiveServices" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.CognitiveServices.AnomalyDetector", + namespace: "Microsoft.CognitiveServices" +}); diff --git a/sdk/appconfiguration/app-configuration/package.json b/sdk/appconfiguration/app-configuration/package.json index eae92739a4a3..901080f61a30 100644 --- a/sdk/appconfiguration/app-configuration/package.json +++ b/sdk/appconfiguration/app-configuration/package.json @@ -89,7 +89,7 @@ "@azure/core-asynciterator-polyfill": "^1.0.0", "@azure/core-http": "^1.2.0", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" }, diff --git a/sdk/communication/communication-administration/package.json b/sdk/communication/communication-administration/package.json index 2f6124547e2d..33f6f26c5f36 100644 --- a/sdk/communication/communication-administration/package.json +++ b/sdk/communication/communication-administration/package.json @@ -73,7 +73,7 @@ "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", "@azure/logger": "^1.0.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "events": "^3.0.0", "tslib": "^2.0.0" diff --git a/sdk/communication/communication-administration/src/common/tracing.ts b/sdk/communication/communication-administration/src/common/tracing.ts index 4407ba845a27..88aa261c1114 100644 --- a/sdk/communication/communication-administration/src/common/tracing.ts +++ b/sdk/communication/communication-administration/src/common/tracing.ts @@ -1,57 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { OperationOptions } from "@azure/core-http"; -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", "Microsoft.Communication"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Communication" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Communication", + namespace: "Microsoft.Communication" +}); diff --git a/sdk/communication/communication-chat/package.json b/sdk/communication/communication-chat/package.json index fa3c5044e920..f45d16161bb2 100644 --- a/sdk/communication/communication-chat/package.json +++ b/sdk/communication/communication-chat/package.json @@ -69,7 +69,7 @@ "@azure/communication-signaling": "1.0.0-beta.2", "@azure/core-auth": "^1.2.0", "@azure/core-http": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "events": "^3.0.0", diff --git a/sdk/communication/communication-chat/src/tracing.ts b/sdk/communication/communication-chat/src/tracing.ts index 89f66369a3c2..88aa261c1114 100644 --- a/sdk/communication/communication-chat/src/tracing.ts +++ b/sdk/communication/communication-chat/src/tracing.ts @@ -1,57 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-http"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", "Microsoft.Communication"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Communication" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Communication", + namespace: "Microsoft.Communication" +}); diff --git a/sdk/communication/communication-identity/package.json b/sdk/communication/communication-identity/package.json index ad770abeb8c1..ed9e9e076a15 100644 --- a/sdk/communication/communication-identity/package.json +++ b/sdk/communication/communication-identity/package.json @@ -72,7 +72,7 @@ "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", "@azure/logger": "^1.0.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "events": "^3.0.0", "tslib": "^2.0.0" diff --git a/sdk/communication/communication-identity/src/common/tracing.ts b/sdk/communication/communication-identity/src/common/tracing.ts index 4407ba845a27..88aa261c1114 100644 --- a/sdk/communication/communication-identity/src/common/tracing.ts +++ b/sdk/communication/communication-identity/src/common/tracing.ts @@ -1,57 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { OperationOptions } from "@azure/core-http"; -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", "Microsoft.Communication"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Communication" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Communication", + namespace: "Microsoft.Communication" +}); diff --git a/sdk/communication/communication-sms/package.json b/sdk/communication/communication-sms/package.json index 67e30fd42036..6c7513ba7561 100644 --- a/sdk/communication/communication-sms/package.json +++ b/sdk/communication/communication-sms/package.json @@ -71,7 +71,7 @@ "@azure/communication-common": "1.0.0-beta.6", "@azure/core-auth": "^1.2.0", "@azure/core-http": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "events": "^3.0.0", diff --git a/sdk/communication/communication-sms/src/tracing.ts b/sdk/communication/communication-sms/src/tracing.ts index 4407ba845a27..88aa261c1114 100644 --- a/sdk/communication/communication-sms/src/tracing.ts +++ b/sdk/communication/communication-sms/src/tracing.ts @@ -1,57 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { OperationOptions } from "@azure/core-http"; -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Communication.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", "Microsoft.Communication"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Communication" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Communication", + namespace: "Microsoft.Communication" +}); diff --git a/sdk/core/core-client/CHANGELOG.md b/sdk/core/core-client/CHANGELOG.md index 4b351adba731..a47a4d1cf2fc 100644 --- a/sdk/core/core-client/CHANGELOG.md +++ b/sdk/core/core-client/CHANGELOG.md @@ -2,6 +2,9 @@ ## 1.0.0-beta.2 (Unreleased) +- [Breaking] Removed `createSpanFunction` and `SpanConfig`. These have been moved into + `@azure/core-tracing`. + ## 1.0.0-beta.1 (2021-02-04) - First release of package, see README.md for details. diff --git a/sdk/core/core-client/package.json b/sdk/core/core-client/package.json index 16a76a0fc6e4..12b4a2581212 100644 --- a/sdk/core/core-client/package.json +++ b/sdk/core/core-client/package.json @@ -80,7 +80,7 @@ "@azure/core-asynciterator-polyfill": "^1.0.0", "@azure/core-auth": "^1.2.0", "@azure/core-https": "1.0.0-beta.2", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" }, diff --git a/sdk/core/core-client/review/core-client.api.md b/sdk/core/core-client/review/core-client.api.md index 1fe1ee02f061..d4968686fd4c 100644 --- a/sdk/core/core-client/review/core-client.api.md +++ b/sdk/core/core-client/review/core-client.api.md @@ -13,7 +13,6 @@ import { Pipeline } from '@azure/core-https'; import { PipelinePolicy } from '@azure/core-https'; import { PipelineRequest } from '@azure/core-https'; import { PipelineResponse } from '@azure/core-https'; -import { Span } from '@opentelemetry/api'; import { TokenCredential } from '@azure/core-auth'; import { TransferProgressEvent } from '@azure/core-https'; @@ -77,12 +76,6 @@ export function createSerializer(modelMappers?: { [key: string]: any; }, isXML?: boolean): Serializer; -// @public -export function createSpanFunction({ packagePrefix, namespace }: SpanConfig): (operationName: string, operationOptions: T) => { - span: Span; - updatedOptions: T; -}; - // @public export interface DeserializationContentTypes { json?: string[]; diff --git a/sdk/core/core-client/src/createSpan.ts b/sdk/core/core-client/src/createSpan.ts deleted file mode 100644 index faaa05f77dd1..000000000000 --- a/sdk/core/core-client/src/createSpan.ts +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { getTracer } from "@azure/core-tracing"; -import { OperationOptions, SpanConfig } from "./interfaces"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; - -/** - * Creates a function called createSpan to create spans using the global tracer. - * @hidden - * @param spanConfig - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. - */ -export function createSpanFunction({ packagePrefix, namespace }: SpanConfig) { - return function( - operationName: string, - operationOptions: T - ): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`${packagePrefix}.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", namespace); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": namespace - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; - }; -} diff --git a/sdk/core/core-client/src/index.ts b/sdk/core/core-client/src/index.ts index 572b4fc5698f..ee0fe5a452a5 100644 --- a/sdk/core/core-client/src/index.ts +++ b/sdk/core/core-client/src/index.ts @@ -2,7 +2,6 @@ // Licensed under the MIT license. export { createSerializer, MapperTypeNames } from "./serializer"; -export { createSpanFunction } from "./createSpan"; export { ServiceClient, ServiceClientOptions } from "./serviceClient"; export { createClientPipeline, ClientPipelineOptions } from "./pipeline"; export { diff --git a/sdk/core/core-client/test/createSpan.spec.ts b/sdk/core/core-client/test/createSpan.spec.ts deleted file mode 100644 index 8d94c7792c2a..000000000000 --- a/sdk/core/core-client/test/createSpan.spec.ts +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import { assert } from "chai"; -import { SpanKind, TraceFlags } from "@opentelemetry/api"; -import { setTracer, TestSpan, TestTracer } from "@azure/core-tracing"; -import sinon from "sinon"; -import { createSpanFunction } from "../src/createSpan"; -import { OperationOptions } from "../src/interfaces"; - -const createSpan = createSpanFunction({ namespace: "Microsoft.Test", packagePrefix: "Azure.Test" }); - -describe("createSpan", () => { - it("returns a created span with the right metadata", () => { - const tracer = new TestTracer(); - const testSpan = new TestSpan( - tracer, - "testing", - { traceId: "", spanId: "", traceFlags: TraceFlags.NONE }, - SpanKind.INTERNAL - ); - const setAttributeSpy = sinon.spy(testSpan, "setAttribute"); - const startSpanStub = sinon.stub(tracer, "startSpan"); - startSpanStub.returns(testSpan); - setTracer(tracer); - const { span } = createSpan("testMethod", {}); - assert.strictEqual(span, testSpan, "Should return mocked span"); - assert.isTrue(startSpanStub.calledOnce); - const [name, options] = startSpanStub.firstCall.args; - assert.strictEqual(name, "Azure.Test.testMethod"); - assert.deepEqual(options, { kind: SpanKind.INTERNAL }); - assert.isTrue(setAttributeSpy.calledOnceWithExactly("az.namespace", "Microsoft.Test")); - }); - - it("returns updated SpanOptions", () => { - const options: OperationOptions = {}; - const { span, updatedOptions } = createSpan("testMethod", options); - assert.isEmpty(options, "original options should not be modified"); - assert.notStrictEqual(updatedOptions, options, "should return new object"); - const expected: OperationOptions = { - tracingOptions: { - spanOptions: { - parent: span.context(), - attributes: { - "az.namespace": "Microsoft.Test" - } - } - } - }; - assert.deepEqual(updatedOptions, expected); - }); - - it("preserves existing attributes", () => { - const options: OperationOptions = { - tracingOptions: { - spanOptions: { - attributes: { - foo: "bar" - } - } - } - }; - const { span, updatedOptions } = createSpan("testMethod", options); - assert.notStrictEqual(updatedOptions, options, "should return new object"); - const expected: OperationOptions = { - tracingOptions: { - spanOptions: { - parent: span.context(), - attributes: { - "az.namespace": "Microsoft.Test", - foo: "bar" - } - } - } - }; - assert.deepEqual(updatedOptions, expected); - }); - - afterEach(() => { - sinon.restore(); - }); -}); diff --git a/sdk/core/core-http/package.json b/sdk/core/core-http/package.json index 069c825c1331..043bc5f4bc64 100644 --- a/sdk/core/core-http/package.json +++ b/sdk/core/core-http/package.json @@ -133,7 +133,7 @@ "@azure/abort-controller": "^1.0.0", "@azure/core-asynciterator-polyfill": "^1.0.0", "@azure/core-auth": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "@types/node-fetch": "^2.5.0", diff --git a/sdk/core/core-http/review/core-http.api.md b/sdk/core/core-http/review/core-http.api.md index 680dac23462e..32b43607d81d 100644 --- a/sdk/core/core-http/review/core-http.api.md +++ b/sdk/core/core-http/review/core-http.api.md @@ -157,8 +157,8 @@ export const Constants: { // @public (undocumented) export function createPipelineFromOptions(pipelineOptions: InternalPipelineOptions, authPolicyFactory?: RequestPolicyFactory): ServiceClientOptions; -// @public -export function createSpanFunction({ packagePrefix, namespace }: SpanConfig): (operationName: string, operationOptions: T) => { +// @public @deprecated +export function createSpanFunction(args: SpanConfig): (operationName: string, operationOptions: T) => { span: Span; updatedOptions: T; }; @@ -798,7 +798,7 @@ export interface SimpleMapperType { name: "Base64Url" | "Boolean" | "ByteArray" | "Date" | "DateTime" | "DateTimeRfc1123" | "Object" | "Stream" | "String" | "TimeSpan" | "UnixTime" | "Uuid" | "Number" | "any"; } -// @public +// @public @deprecated export interface SpanConfig { namespace: string; packagePrefix: string; diff --git a/sdk/core/core-http/src/coreHttp.ts b/sdk/core/core-http/src/coreHttp.ts index 4123f8a818ac..dd3b91076fe9 100644 --- a/sdk/core/core-http/src/coreHttp.ts +++ b/sdk/core/core-http/src/coreHttp.ts @@ -43,7 +43,6 @@ export { ProxySettings, ProxyOptions } from "./serviceClient"; -export { createSpanFunction, SpanConfig } from "./createSpan"; export { PipelineOptions, InternalPipelineOptions } from "./pipelineOptions"; export { QueryCollectionFormat } from "./queryCollectionFormat"; export { Constants } from "./util/constants"; @@ -115,6 +114,9 @@ export { export { URLBuilder, URLQuery } from "./url"; export { AbortSignalLike } from "@azure/abort-controller"; +// legacy exports. Use core-tracing instead (and remove on next major version update of core-http). +export { createSpanFunction, SpanConfig } from "./createSpanLegacy"; + // Credentials export { TokenCredential, GetTokenOptions, AccessToken, isTokenCredential } from "@azure/core-auth"; export { AccessTokenCache, ExpiringAccessTokenCache } from "./credentials/accessTokenCache"; diff --git a/sdk/core/core-http/src/createSpan.ts b/sdk/core/core-http/src/createSpan.ts deleted file mode 100644 index d7029a039e9f..000000000000 --- a/sdk/core/core-http/src/createSpan.ts +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { getTracer } from "@azure/core-tracing"; -import { OperationOptions } from "./coreHttp"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; - -/** - * Configuration for creating a new Tracing Span - */ -export interface SpanConfig { - /** - * Package name prefix - */ - packagePrefix: string; - /** - * Service namespace - */ - namespace: string; -} - -/** - * Creates a function called createSpan to create spans using the global tracer. - * @hidden - * @param spanConfig - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. - */ -export function createSpanFunction({ packagePrefix, namespace }: SpanConfig) { - return function( - operationName: string, - operationOptions: T - ): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`${packagePrefix}.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", namespace); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": namespace - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; - }; -} diff --git a/sdk/core/core-http/src/createSpanLegacy.ts b/sdk/core/core-http/src/createSpanLegacy.ts new file mode 100644 index 000000000000..8291a678ac10 --- /dev/null +++ b/sdk/core/core-http/src/createSpanLegacy.ts @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +// NOTE: we've moved this code into core-tracing but these functions +// were a part of the GA'd library and can't be removed until the next major +// release. They currently get called always, even if tracing is not enabled. + +import { createSpanFunction as coreTracingCreateSpanFunction } from "@azure/core-tracing"; +import { Span } from "@opentelemetry/api"; +import { OperationOptions } from "./operationOptions"; + +/** + * This function is only here for compatibility. Use createSpanFunction in core-tracing. + * + * @deprecated This function is only here for compatibility. Use core-tracing instead. + * @hidden + */ +export interface SpanConfig { + /** + * Package name prefix + */ + packagePrefix: string; + /** + * Service namespace + */ + namespace: string; +} + +/** + * This function is only here for compatibility. Use createSpanFunction in core-tracing. + * + * @deprecated This function is only here for compatibility. Use createSpanFunction in core-tracing. + * @hidden + + * @param spanConfig - The name of the operation being performed. + * @param tracingOptions - The options for the underlying http request. + */ +export function createSpanFunction( + args: SpanConfig +): ( + operationName: string, + operationOptions: T +) => { span: Span; updatedOptions: T } { + return coreTracingCreateSpanFunction(args); +} diff --git a/sdk/core/core-https/package.json b/sdk/core/core-https/package.json index bcf5ab633ee1..4b0153e097b2 100644 --- a/sdk/core/core-https/package.json +++ b/sdk/core/core-https/package.json @@ -90,7 +90,7 @@ "dependencies": { "@azure/abort-controller": "^1.0.0", "@azure/core-auth": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "form-data": "^3.0.0", diff --git a/sdk/core/core-tracing/package.json b/sdk/core/core-tracing/package.json index 8ffaca6f48e2..61e8ac551bf3 100644 --- a/sdk/core/core-tracing/package.json +++ b/sdk/core/core-tracing/package.json @@ -88,6 +88,8 @@ "rollup-plugin-visualizer": "^4.0.4", "typescript": "4.1.2", "util": "^0.12.1", - "typedoc": "0.15.2" + "typedoc": "0.15.2", + "sinon": "^9.0.2", + "@types/sinon": "^9.0.4" } } diff --git a/sdk/core/core-tracing/review/core-tracing.api.md b/sdk/core/core-tracing/review/core-tracing.api.md index e5cd6fcea46e..aa2fd0dc7e56 100644 --- a/sdk/core/core-tracing/review/core-tracing.api.md +++ b/sdk/core/core-tracing/review/core-tracing.api.md @@ -16,6 +16,20 @@ import { TimeInput } from '@opentelemetry/api'; import { Tracer } from '@opentelemetry/api'; import { TracerBase } from '@opencensus/web-types'; +// @public +export function createSpanFunction(args: CreateSpanFunctionArgs): (operationName: string, operationOptions: T | undefined) => { + span: Span; + updatedOptions: T; +}; + +// @public +export interface CreateSpanFunctionArgs { + namespace: string; + packagePrefix: string; +} + // @public export function extractSpanContextFromTraceParentHeader(traceParentHeader: string): SpanContext | undefined; diff --git a/sdk/core/core-tracing/src/createSpan.ts b/sdk/core/core-tracing/src/createSpan.ts new file mode 100644 index 000000000000..2ab431f68a4e --- /dev/null +++ b/sdk/core/core-tracing/src/createSpan.ts @@ -0,0 +1,87 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; +import { getTracer } from "../src/tracerProxy"; +import { OperationTracingOptions } from "./interfaces"; + +/** + * Arguments for `createSpanFunction` that allow you to specify the + * prefix for each created span as well as the `az.namespace` attribute. + * + * @hidden + */ +export interface CreateSpanFunctionArgs { + /** + * Package name prefix + */ + packagePrefix: string; + /** + * Service namespace + */ + namespace: string; +} + +/** + * Creates a function that can be used to create spans using the global tracer. + * + * Usage: + * + * ```typescript + * // once + * const createSpan = createSpanFunction({ packagePrefix: "Azure.Data.AppConfiguration", namespace: "Microsoft.AppConfiguration" }); + * + * // in each operation + * const span = createSpan("deleteConfigurationSetting", operationOptions); + * // code... + * span.end(); + * ``` + * + * @hidden + * @param args - allows configuration of the prefix for each span as well as the az.namespace field. + */ +export function createSpanFunction(args: CreateSpanFunctionArgs) { + return function( + operationName: string, + operationOptions: T | undefined + ): { span: Span; updatedOptions: T } { + const tracer = getTracer(); + const tracingOptions = operationOptions?.tracingOptions || {}; + const spanOptions: SpanOptions = { + ...tracingOptions.spanOptions, + kind: SpanKind.INTERNAL + }; + + const span = tracer.startSpan(`${args.packagePrefix}.${operationName}`, spanOptions); + + span.setAttribute("az.namespace", args.namespace); + + let newSpanOptions = tracingOptions.spanOptions || {}; + if (span.isRecording()) { + newSpanOptions = { + ...tracingOptions.spanOptions, + parent: span.context(), + attributes: { + ...spanOptions.attributes, + "az.namespace": args.namespace + } + }; + } + + const newTracingOptions: OperationTracingOptions = { + ...tracingOptions, + spanOptions: newSpanOptions + // TODO: .context soon. + }; + + const newOperationOptions = { + ...operationOptions, + tracingOptions: newTracingOptions + }; + + return { + span, + updatedOptions: newOperationOptions as T + }; + }; +} diff --git a/sdk/core/core-tracing/src/index.ts b/sdk/core/core-tracing/src/index.ts index e97ce0e3a238..a18b1f01e095 100644 --- a/sdk/core/core-tracing/src/index.ts +++ b/sdk/core/core-tracing/src/index.ts @@ -10,6 +10,7 @@ export { OpenCensusSpanWrapper } from "./tracers/opencensus/openCensusSpanWrappe export { OpenCensusTracerWrapper } from "./tracers/opencensus/openCensusTracerWrapper"; export { TestTracer, SpanGraph, SpanGraphNode } from "./tracers/test/testTracer"; export { TestSpan } from "./tracers/test/testSpan"; +export { createSpanFunction, CreateSpanFunctionArgs } from "./createSpan"; // Shared interfaces export { SpanContext, SpanOptions, TraceFlags } from "./interfaces"; diff --git a/sdk/core/core-http/test/createSpan.spec.ts b/sdk/core/core-tracing/test/createSpan.spec.ts similarity index 57% rename from sdk/core/core-http/test/createSpan.spec.ts rename to sdk/core/core-tracing/test/createSpan.spec.ts index 90ef3d8e26fb..c48b070eda1e 100644 --- a/sdk/core/core-http/test/createSpan.spec.ts +++ b/sdk/core/core-tracing/test/createSpan.spec.ts @@ -1,14 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { assert } from "chai"; -import { SpanKind, TraceFlags } from "@opentelemetry/api"; -import { setTracer, TestSpan, TestTracer } from "@azure/core-tracing"; +import * as assert from "assert"; import sinon from "sinon"; +import { SpanKind, TraceFlags } from "@opentelemetry/api"; -import { OperationOptions } from "../src/coreHttp"; - +import { setTracer } from "../src/tracerProxy"; +import { TestTracer } from "../src/tracers/test/testTracer"; +import { TestSpan } from "../src/tracers/test/testSpan"; import { createSpanFunction } from "../src/createSpan"; +import { OperationTracingOptions } from "../src/interfaces"; + const createSpan = createSpanFunction({ namespace: "Microsoft.Test", packagePrefix: "Azure.Test" }); describe("createSpan", () => { @@ -24,21 +26,44 @@ describe("createSpan", () => { const startSpanStub = sinon.stub(tracer, "startSpan"); startSpanStub.returns(testSpan); setTracer(tracer); - const { span } = createSpan("testMethod", {}); + const { span, updatedOptions } = createSpan("testMethod", { + tracingOptions: ({ + // validate that we dumbly just copy any fields (this makes future upgrades easier) + someOtherField: "someOtherFieldValue", + context: { someContext: "some Context" } + } as OperationTracingOptions) as any + }); assert.strictEqual(span, testSpan, "Should return mocked span"); - assert.isTrue(startSpanStub.calledOnce); + assert.ok(startSpanStub.calledOnce); const [name, options] = startSpanStub.firstCall.args; assert.strictEqual(name, "Azure.Test.testMethod"); assert.deepEqual(options, { kind: SpanKind.INTERNAL }); - assert.isTrue(setAttributeSpy.calledOnceWithExactly("az.namespace", "Microsoft.Test")); + assert.ok(setAttributeSpy.calledOnceWithExactly("az.namespace", "Microsoft.Test")); + + assert.deepEqual(updatedOptions.tracingOptions, { + someOtherField: "someOtherFieldValue", + // TODO: note, this will be incorrect (and break) when we get to the next opentelemetry + // upgrade (and that'll be a good reminder to fix it) + context: { someContext: "some Context" }, + spanOptions: { + attributes: { + "az.namespace": "Microsoft.Test" + }, + parent: { + spanId: "", + traceFlags: 0, + traceId: "" + } + } + }); }); it("returns updated SpanOptions", () => { - const options: OperationOptions = {}; + const options: { tracingOptions?: OperationTracingOptions } = {}; const { span, updatedOptions } = createSpan("testMethod", options); - assert.isEmpty(options, "original options should not be modified"); + assert.deepStrictEqual(options, {}, "original options should not be modified"); assert.notStrictEqual(updatedOptions, options, "should return new object"); - const expected: OperationOptions = { + const expected: { tracingOptions?: OperationTracingOptions } = { tracingOptions: { spanOptions: { parent: span.context(), @@ -52,7 +77,7 @@ describe("createSpan", () => { }); it("preserves existing attributes", () => { - const options: OperationOptions = { + const options: { tracingOptions?: OperationTracingOptions } = { tracingOptions: { spanOptions: { attributes: { @@ -63,7 +88,7 @@ describe("createSpan", () => { }; const { span, updatedOptions } = createSpan("testMethod", options); assert.notStrictEqual(updatedOptions, options, "should return new object"); - const expected: OperationOptions = { + const expected: { tracingOptions?: OperationTracingOptions } = { tracingOptions: { spanOptions: { parent: span.context(), diff --git a/sdk/digitaltwins/digital-twins-core/package.json b/sdk/digitaltwins/digital-twins-core/package.json index d92d221561f8..e10d9d628930 100644 --- a/sdk/digitaltwins/digital-twins-core/package.json +++ b/sdk/digitaltwins/digital-twins-core/package.json @@ -68,7 +68,7 @@ "dependencies": { "@azure/core-http": "^1.2.0", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/digitaltwins/digital-twins-core/src/tracing.ts b/sdk/digitaltwins/digital-twins-core/src/tracing.ts index 24fd5f430249..1d5bf67208d8 100644 --- a/sdk/digitaltwins/digital-twins-core/src/tracing.ts +++ b/sdk/digitaltwins/digital-twins-core/src/tracing.ts @@ -1,57 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-http"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`DigitalTwinsClient.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", "Microsoft.DigitalTwins"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.DigitalTwins" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "DigitalTwinsClient", + namespace: "Microsoft.DigitalTwins" +}); diff --git a/sdk/eventgrid/eventgrid/package.json b/sdk/eventgrid/eventgrid/package.json index 5a8bebdab042..3ddd006a6b69 100644 --- a/sdk/eventgrid/eventgrid/package.json +++ b/sdk/eventgrid/eventgrid/package.json @@ -82,7 +82,7 @@ "@azure/core-auth": "^1.2.0", "@azure/core-client": "1.0.0-beta.2", "@azure/core-https": "1.0.0-beta.2", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0", diff --git a/sdk/eventgrid/eventgrid/src/tracing.ts b/sdk/eventgrid/eventgrid/src/tracing.ts index b7750fa0d3d5..8b6c476e60ed 100644 --- a/sdk/eventgrid/eventgrid/src/tracing.ts +++ b/sdk/eventgrid/eventgrid/src/tracing.ts @@ -1,57 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-client"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Data.EventGrid.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", "Microsoft.Messaging.EventGrid"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Data.EventGrid" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Data.EventGrid", + namespace: "Microsoft.Messaging.EventGrid" +}); diff --git a/sdk/eventhub/event-hubs/package.json b/sdk/eventhub/event-hubs/package.json index 15f6e47e0e24..9eca9652cbc0 100644 --- a/sdk/eventhub/event-hubs/package.json +++ b/sdk/eventhub/event-hubs/package.json @@ -92,7 +92,7 @@ "@azure/abort-controller": "^1.0.0", "@azure/core-amqp": "^2.1.0", "@azure/core-asynciterator-polyfill": "^1.0.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/core-auth": "^1.2.0", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", diff --git a/sdk/formrecognizer/ai-form-recognizer/package.json b/sdk/formrecognizer/ai-form-recognizer/package.json index cf9a0f6d3988..a2634efa5c1f 100644 --- a/sdk/formrecognizer/ai-form-recognizer/package.json +++ b/sdk/formrecognizer/ai-form-recognizer/package.json @@ -82,7 +82,7 @@ "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", "@azure/core-http": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/formrecognizer/ai-form-recognizer/src/tracing.ts b/sdk/formrecognizer/ai-form-recognizer/src/tracing.ts index ab8a61d1f832..ca9e15799641 100644 --- a/sdk/formrecognizer/ai-form-recognizer/src/tracing.ts +++ b/sdk/formrecognizer/ai-form-recognizer/src/tracing.ts @@ -1,58 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer, OperationTracingOptions } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan( - `Azure.CognitiveServices.FormRecognizer.${operationName}`, - spanOptions - ); - - span.setAttribute("az.namespace", "Microsoft.CognitiveServices"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.CognitiveServices" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.CognitiveServices.FormRecognizer", + namespace: "Microsoft.CognitiveServices" +}); diff --git a/sdk/identity/identity/package.json b/sdk/identity/identity/package.json index baedc591e207..4afb4d34d4c7 100644 --- a/sdk/identity/identity/package.json +++ b/sdk/identity/identity/package.json @@ -81,7 +81,7 @@ "sideEffects": false, "dependencies": { "@azure/core-http": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@azure/msal-node": "1.0.0-beta.6", "@azure/msal-browser": "2.9.0", diff --git a/sdk/identity/identity/src/client/identityClient.ts b/sdk/identity/identity/src/client/identityClient.ts index 7fd8a0a21ab8..8e7075359224 100644 --- a/sdk/identity/identity/src/client/identityClient.ts +++ b/sdk/identity/identity/src/client/identityClient.ts @@ -126,7 +126,7 @@ export class IdentityClient extends ServiceClient implements INetworkModule { `IdentityClient: refreshing access token with client ID: ${clientId}, scopes: ${scopes} started` ); - const { span, options: newOptions } = createSpan("IdentityClient-refreshAccessToken", options); + const { span, updatedOptions } = createSpan("IdentityClient-refreshAccessToken", options); const refreshParams = { grant_type: "refresh_token", @@ -151,7 +151,7 @@ export class IdentityClient extends ServiceClient implements INetworkModule { Accept: "application/json", "Content-Type": "application/x-www-form-urlencoded" }, - spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions, + spanOptions: updatedOptions?.tracingOptions?.spanOptions, abortSignal: options && options.abortSignal }); diff --git a/sdk/identity/identity/src/credentials/authorizationCodeCredential.ts b/sdk/identity/identity/src/credentials/authorizationCodeCredential.ts index 2aa38086e470..880bd25a9335 100644 --- a/sdk/identity/identity/src/credentials/authorizationCodeCredential.ts +++ b/sdk/identity/identity/src/credentials/authorizationCodeCredential.ts @@ -135,10 +135,7 @@ export class AuthorizationCodeCredential implements TokenCredential { scopes: string | string[], options?: GetTokenOptions ): Promise { - const { span, options: newOptions } = createSpan( - "AuthorizationCodeCredential-getToken", - options - ); + const { span, updatedOptions } = createSpan("AuthorizationCodeCredential-getToken", options); try { let tokenResponse: TokenResponse | null = null; let scopeString = typeof scopes === "string" ? scopes : scopes.join(" "); @@ -155,7 +152,7 @@ export class AuthorizationCodeCredential implements TokenCredential { this.lastTokenResponse.refreshToken, this.clientSecret, undefined, - newOptions + updatedOptions ); } @@ -179,7 +176,7 @@ export class AuthorizationCodeCredential implements TokenCredential { "Content-Type": "application/x-www-form-urlencoded" }, abortSignal: options && options.abortSignal, - spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions + spanOptions: updatedOptions?.tracingOptions?.spanOptions }); tokenResponse = await this.identityClient.sendTokenRequest(webResource); diff --git a/sdk/identity/identity/src/credentials/chainedTokenCredential.ts b/sdk/identity/identity/src/credentials/chainedTokenCredential.ts index 092946f2ab55..1f7330248678 100644 --- a/sdk/identity/identity/src/credentials/chainedTokenCredential.ts +++ b/sdk/identity/identity/src/credentials/chainedTokenCredential.ts @@ -58,11 +58,11 @@ export class ChainedTokenCredential implements TokenCredential { let token = null; const errors = []; - const { span, options: newOptions } = createSpan("ChainedTokenCredential-getToken", options); + const { span, updatedOptions } = createSpan("ChainedTokenCredential-getToken", options); for (let i = 0; i < this._sources.length && token === null; i++) { try { - token = await this._sources[i].getToken(scopes, newOptions); + token = await this._sources[i].getToken(scopes, updatedOptions); } catch (err) { if (err instanceof CredentialUnavailable) { errors.push(err); diff --git a/sdk/identity/identity/src/credentials/clientCertificateCredential.ts b/sdk/identity/identity/src/credentials/clientCertificateCredential.ts index 38c1b1f43ffa..03efcfe5e5de 100644 --- a/sdk/identity/identity/src/credentials/clientCertificateCredential.ts +++ b/sdk/identity/identity/src/credentials/clientCertificateCredential.ts @@ -114,10 +114,7 @@ export class ClientCertificateCredential implements TokenCredential { scopes: string | string[], options?: GetTokenOptions ): Promise { - const { span, options: newOptions } = createSpan( - "ClientCertificateCredential-getToken", - options - ); + const { span, updatedOptions } = createSpan("ClientCertificateCredential-getToken", options); try { const tokenId = uuidV4(); const urlSuffix = getIdentityTokenEndpointSuffix(this.tenantId); @@ -172,7 +169,7 @@ export class ClientCertificateCredential implements TokenCredential { "Content-Type": "application/x-www-form-urlencoded" }, abortSignal: options && options.abortSignal, - spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions + spanOptions: updatedOptions?.tracingOptions?.spanOptions }); const tokenResponse = await this.identityClient.sendTokenRequest(webResource); diff --git a/sdk/identity/identity/src/credentials/clientSecretCredential.ts b/sdk/identity/identity/src/credentials/clientSecretCredential.ts index a7d1382d9b7f..4024515025e8 100644 --- a/sdk/identity/identity/src/credentials/clientSecretCredential.ts +++ b/sdk/identity/identity/src/credentials/clientSecretCredential.ts @@ -62,7 +62,7 @@ export class ClientSecretCredential implements TokenCredential { scopes: string | string[], options?: GetTokenOptions ): Promise { - const { span, options: newOptions } = createSpan("ClientSecretCredential-getToken", options); + const { span, updatedOptions } = createSpan("ClientSecretCredential-getToken", options); try { const urlSuffix = getIdentityTokenEndpointSuffix(this.tenantId); const webResource = this.identityClient.createWebResource({ @@ -82,7 +82,7 @@ export class ClientSecretCredential implements TokenCredential { "Content-Type": "application/x-www-form-urlencoded" }, abortSignal: options && options.abortSignal, - spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions + spanOptions: updatedOptions?.tracingOptions?.spanOptions }); const tokenResponse = await this.identityClient.sendTokenRequest(webResource); diff --git a/sdk/identity/identity/src/credentials/environmentCredential.ts b/sdk/identity/identity/src/credentials/environmentCredential.ts index 7ce0b6230ef8..537e852b1214 100644 --- a/sdk/identity/identity/src/credentials/environmentCredential.ts +++ b/sdk/identity/identity/src/credentials/environmentCredential.ts @@ -122,10 +122,10 @@ export class EnvironmentCredential implements TokenCredential { scopes: string | string[], options?: GetTokenOptions ): Promise { - const { span, options: newOptions } = createSpan("EnvironmentCredential-getToken", options); + const { span, updatedOptions } = createSpan("EnvironmentCredential-getToken", options); if (this._credential) { try { - const result = await this._credential.getToken(scopes, newOptions); + const result = await this._credential.getToken(scopes, updatedOptions); logger.getToken.info(formatSuccess(scopes)); return result; } catch (err) { diff --git a/sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts b/sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts index 45bfe8261209..ac781276960c 100644 --- a/sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts +++ b/sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts @@ -54,7 +54,7 @@ export const imdsMsi: MSI = { clientId?: string, getTokenOptions?: GetTokenOptions ): Promise { - const { span, options } = createSpan( + const { span, updatedOptions } = createSpan( "ManagedIdentityCredential-pingImdsEndpoint", getTokenOptions ); @@ -68,14 +68,14 @@ export const imdsMsi: MSI = { delete request.headers.Metadata; } - request.spanOptions = options.tracingOptions && options.tracingOptions.spanOptions; + request.spanOptions = updatedOptions?.tracingOptions?.spanOptions; try { // Create a request with a timeout since we expect that // not having a "Metadata" header should cause an error to be // returned quickly from the endpoint, proving its availability. const webResource = identityClient.createWebResource(request); - webResource.timeout = (options.requestOptions && options.requestOptions.timeout) || 500; + webResource.timeout = updatedOptions?.requestOptions?.timeout || 500; try { logger.info(`Pinging IMDS endpoint`); diff --git a/sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts b/sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts index 1337b188b51b..5744ba992c7d 100644 --- a/sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts +++ b/sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts @@ -97,16 +97,16 @@ export class ManagedIdentityCredential implements TokenCredential { getTokenOptions?: GetTokenOptions ): Promise { const resource = mapScopesToResource(scopes); - const { span, options } = createSpan( + const { span, updatedOptions } = createSpan( "ManagedIdentityCredential-authenticateManagedIdentity", getTokenOptions ); try { // Determining the available MSI, and avoiding checking for other MSIs while the program is running. - const availableMSI = await this.cachedAvailableMSI(resource, clientId, options); + const availableMSI = await this.cachedAvailableMSI(resource, clientId, updatedOptions); - return availableMSI.getToken(this.identityClient, resource, clientId, options); + return availableMSI.getToken(this.identityClient, resource, clientId, updatedOptions); } catch (err) { const code = err.name === AuthenticationErrorName @@ -138,14 +138,14 @@ export class ManagedIdentityCredential implements TokenCredential { ): Promise { let result: AccessToken | null = null; - const { span, options: newOptions } = createSpan("ManagedIdentityCredential-getToken", options); + const { span, updatedOptions } = createSpan("ManagedIdentityCredential-getToken", options); try { // isEndpointAvailable can be true, false, or null, // If it's null, it means we don't yet know whether // the endpoint is available and need to check for it. if (this.isEndpointUnavailable !== true) { - result = await this.authenticateManagedIdentity(scopes, this.clientId, newOptions); + result = await this.authenticateManagedIdentity(scopes, this.clientId, updatedOptions); if (result === null) { // If authenticateManagedIdentity returns null, diff --git a/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts b/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts index 7bf1ac2bdacd..3040b3493683 100644 --- a/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts +++ b/sdk/identity/identity/src/credentials/usernamePasswordCredential.ts @@ -67,10 +67,7 @@ export class UsernamePasswordCredential implements TokenCredential { scopes: string | string[], options?: GetTokenOptions ): Promise { - const { span, options: newOptions } = createSpan( - "UsernamePasswordCredential-getToken", - options - ); + const { span, updatedOptions } = createSpan("UsernamePasswordCredential-getToken", options); try { const urlSuffix = getIdentityTokenEndpointSuffix(this.tenantId); const webResource = this.identityClient.createWebResource({ @@ -91,7 +88,7 @@ export class UsernamePasswordCredential implements TokenCredential { "Content-Type": "application/x-www-form-urlencoded" }, abortSignal: options && options.abortSignal, - spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions + spanOptions: updatedOptions?.tracingOptions?.spanOptions }); const tokenResponse = await this.identityClient.sendTokenRequest(webResource); diff --git a/sdk/identity/identity/src/util/tracing.ts b/sdk/identity/identity/src/util/tracing.ts index 173f43f04870..2e2f0a0ce4c4 100644 --- a/sdk/identity/identity/src/util/tracing.ts +++ b/sdk/identity/identity/src/util/tracing.ts @@ -1,54 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { GetTokenOptions } from "@azure/core-http"; -import { getTracer, OperationTracingOptions } from "@azure/core-tracing"; -import { Span, SpanKind, SpanOptions as OTSpanOptions } from "@opentelemetry/api"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. - * @param name - The name of the operation being performed. - * @param options - The options for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - options: GetTokenOptions = {} -): { span: Span; options: GetTokenOptions } { - const tracer = getTracer(); - - const tracingOptions: OperationTracingOptions = { - spanOptions: {}, - ...options.tracingOptions - }; - - const spanOptions: OTSpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Identity.${operationName}`, spanOptions); - span.setAttribute("az.namespace", "Microsoft.AAD"); - - let newOptions = options; - if (span.isRecording()) { - newOptions = { - ...options, - tracingOptions: { - ...tracingOptions, - spanOptions: { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.AAD" - } - } - } - }; - } - - return { - span, - options: newOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Identity", + namespace: "Microsoft.AAD" +}); diff --git a/sdk/keyvault/keyvault-admin/package.json b/sdk/keyvault/keyvault-admin/package.json index 29ebe4e21ab4..48d4abf25331 100644 --- a/sdk/keyvault/keyvault-admin/package.json +++ b/sdk/keyvault/keyvault-admin/package.json @@ -81,7 +81,7 @@ "@azure/core-http": "^1.2.0", "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/keyvault/keyvault-certificates/package.json b/sdk/keyvault/keyvault-certificates/package.json index 3a57d2cb798e..81b18086f10a 100644 --- a/sdk/keyvault/keyvault-certificates/package.json +++ b/sdk/keyvault/keyvault-certificates/package.json @@ -95,7 +95,7 @@ "@azure/core-http": "^1.2.0", "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/keyvault/keyvault-common/package.json b/sdk/keyvault/keyvault-common/package.json index 916e17a77fb6..517aa3a12a58 100644 --- a/sdk/keyvault/keyvault-common/package.json +++ b/sdk/keyvault/keyvault-common/package.json @@ -59,7 +59,7 @@ "dependencies": { "@azure/core-http": "^1.2.0", "tslib": "^2.0.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2" }, "devDependencies": { diff --git a/sdk/keyvault/keyvault-keys/package.json b/sdk/keyvault/keyvault-keys/package.json index a9f403c27c24..c9421dc8dc28 100644 --- a/sdk/keyvault/keyvault-keys/package.json +++ b/sdk/keyvault/keyvault-keys/package.json @@ -88,7 +88,7 @@ "@azure/core-http": "^1.2.0", "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/keyvault/keyvault-secrets/package.json b/sdk/keyvault/keyvault-secrets/package.json index 51a74860ba06..84e158678e04 100644 --- a/sdk/keyvault/keyvault-secrets/package.json +++ b/sdk/keyvault/keyvault-secrets/package.json @@ -94,7 +94,7 @@ "@azure/core-http": "^1.2.0", "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/metricsadvisor/ai-metrics-advisor/package.json b/sdk/metricsadvisor/ai-metrics-advisor/package.json index a94bb2a6cf24..8f0f1f8699e7 100644 --- a/sdk/metricsadvisor/ai-metrics-advisor/package.json +++ b/sdk/metricsadvisor/ai-metrics-advisor/package.json @@ -81,7 +81,7 @@ "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", "@azure/core-http": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/metricsadvisor/ai-metrics-advisor/src/tracing.ts b/sdk/metricsadvisor/ai-metrics-advisor/src/tracing.ts index fe6f44d0aa60..3c434d6dbe84 100644 --- a/sdk/metricsadvisor/ai-metrics-advisor/src/tracing.ts +++ b/sdk/metricsadvisor/ai-metrics-advisor/src/tracing.ts @@ -1,58 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer, OperationTracingOptions } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan( - `Azure.CognitiveServices.MetricsAdvisor.${operationName}`, - spanOptions - ); - - span.setAttribute("az.namespace", "Microsoft.CognitiveServices"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.CognitiveServices" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.CognitiveServices.MetricsAdvisor", + namespace: "Microsoft.CognitiveServices" +}); diff --git a/sdk/mixedreality/mixedreality-authentication/package.json b/sdk/mixedreality/mixedreality-authentication/package.json index ee0815b3faf2..c16938b1e573 100644 --- a/sdk/mixedreality/mixedreality-authentication/package.json +++ b/sdk/mixedreality/mixedreality-authentication/package.json @@ -69,7 +69,7 @@ "dependencies": { "@azure/core-auth": "^1.2.0", "@azure/core-http": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/mixedreality/mixedreality-authentication/src/tracing.ts b/sdk/mixedreality/mixedreality-authentication/src/tracing.ts index d5bd668486f5..6aa773938456 100644 --- a/sdk/mixedreality/mixedreality-authentication/src/tracing.ts +++ b/sdk/mixedreality/mixedreality-authentication/src/tracing.ts @@ -1,59 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-http"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name The name of the operation being performed. - * @param tracingOptions The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.MixedReality.${operationName}`, spanOptions); - - // Resource providers are documented here: - // https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/azure-services-resource-providers - span.setAttribute("Microsoft.MixedReality", "Microsoft.MixedReality"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "Microsoft.MixedReality": "Microsoft.MixedReality" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.MixedReality", + // TODO: oddly enough the createSpan here was actually the attribute named + // 'Microsoft.MixedReality', not 'az.namespace'. Might have been a bug. + namespace: "Microsoft.MixedReality" +}); diff --git a/sdk/search/search-documents/package.json b/sdk/search/search-documents/package.json index 854c658cea68..8cbe5327e4c0 100644 --- a/sdk/search/search-documents/package.json +++ b/sdk/search/search-documents/package.json @@ -78,7 +78,7 @@ "@azure/core-auth": "^1.2.0", "@azure/core-http": "^1.2.0", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0", diff --git a/sdk/search/search-documents/src/tracing.ts b/sdk/search/search-documents/src/tracing.ts index 36dde5e51d18..0392b0a03cbe 100644 --- a/sdk/search/search-documents/src/tracing.ts +++ b/sdk/search/search-documents/src/tracing.ts @@ -1,57 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-http"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. - * @hidden - * @param operationName - The name of the operation being performed. - * @param operationOptions - The options for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Search.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", "Microsoft.Search"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Search" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Search", + namespace: "Microsoft.Search" +}); diff --git a/sdk/servicebus/service-bus/package.json b/sdk/servicebus/service-bus/package.json index 71ae9fcdc0db..7b2102ace707 100644 --- a/sdk/servicebus/service-bus/package.json +++ b/sdk/servicebus/service-bus/package.json @@ -99,7 +99,7 @@ "@azure/core-amqp": "^2.1.0", "@azure/core-asynciterator-polyfill": "^1.0.0", "@azure/core-http": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/core-paging": "^1.1.1", "@azure/core-auth": "^1.2.0", "@azure/logger": "^1.0.0", diff --git a/sdk/servicebus/service-bus/src/serviceBusAtomManagementClient.ts b/sdk/servicebus/service-bus/src/serviceBusAtomManagementClient.ts index 045345546d93..8f74c1b5064a 100644 --- a/sdk/servicebus/service-bus/src/serviceBusAtomManagementClient.ts +++ b/sdk/servicebus/service-bus/src/serviceBusAtomManagementClient.ts @@ -224,7 +224,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { operationOptions?: OperationOptions ): Promise> { logger.verbose(`Performing management operation - getNamespaceProperties()`); - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getNamespaceProperties", operationOptions ); @@ -232,7 +232,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.getResource( "$namespaceinfo", this.namespaceResourceSerializer, - updatedOperationOptions + updatedOptions ); return this.buildNamespacePropertiesResponse(response); @@ -266,7 +266,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { queueName: string, options?: CreateQueueOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-createQueue", options ); @@ -280,7 +280,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { buildQueueOptions(options || {}), this.queueResourceSerializer, false, - updatedOperationOptions + updatedOptions ); return this.buildQueueResponse(response); @@ -313,7 +313,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { queueName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getQueue", operationOptions ); @@ -322,7 +322,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.getResource( queueName, this.queueResourceSerializer, - updatedOperationOptions + updatedOptions ); return this.buildQueueResponse(response); @@ -354,7 +354,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { queueName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getQueueRuntimeProperties", operationOptions ); @@ -365,7 +365,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.getResource( queueName, this.queueResourceSerializer, - updatedOperationOptions + updatedOptions ); return this.buildQueueRuntimePropertiesResponse(response); @@ -396,7 +396,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { private async getQueues( options?: ListRequestOptions & OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getQueues", options ); @@ -404,7 +404,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { logger.verbose(`Performing management operation - getQueues() with options: %j`, options); const response: HttpOperationResponse = await this.listResources( "$Resources/Queues", - updatedOperationOptions, + updatedOptions, this.queueResourceSerializer ); @@ -495,7 +495,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { private async getQueuesRuntimeProperties( options?: ListRequestOptions & OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getQueuesRuntimeProperties", options ); @@ -506,7 +506,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { ); const response: HttpOperationResponse = await this.listResources( "$Resources/Queues", - updatedOperationOptions, + updatedOptions, this.queueResourceSerializer ); @@ -610,7 +610,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { queue: WithResponse, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-updateQueue", operationOptions ); @@ -635,7 +635,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { buildQueueOptions(queue), this.queueResourceSerializer, true, - updatedOperationOptions + updatedOptions ); return this.buildQueueResponse(response); @@ -667,7 +667,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { queueName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-deleteQueue", operationOptions ); @@ -676,7 +676,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.deleteResource( queueName, this.queueResourceSerializer, - updatedOperationOptions + updatedOptions ); return { _response: getHttpResponseOnly(response) }; @@ -696,14 +696,14 @@ export class ServiceBusAdministrationClient extends ServiceClient { * @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request. */ async queueExists(queueName: string, operationOptions?: OperationOptions): Promise { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-queueExists", operationOptions ); try { logger.verbose(`Performing management operation - queueExists() for "${queueName}"`); try { - await this.getQueue(queueName, updatedOperationOptions); + await this.getQueue(queueName, updatedOptions); } catch (error) { if (error.code == "MessageEntityNotFoundError") { return false; @@ -741,7 +741,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { topicName: string, options?: CreateTopicOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-createTopic", options ); @@ -755,7 +755,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { buildTopicOptions(options || {}), this.topicResourceSerializer, false, - updatedOperationOptions + updatedOptions ); return this.buildTopicResponse(response); @@ -788,7 +788,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { topicName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getTopic", operationOptions ); @@ -797,7 +797,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.getResource( topicName, this.topicResourceSerializer, - updatedOperationOptions + updatedOptions ); return this.buildTopicResponse(response); @@ -829,7 +829,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { topicName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getTopicRuntimeProperties", operationOptions ); @@ -840,7 +840,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.getResource( topicName, this.topicResourceSerializer, - updatedOperationOptions + updatedOptions ); return this.buildTopicRuntimePropertiesResponse(response); @@ -871,7 +871,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { private async getTopics( options?: ListRequestOptions & OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getTopics", options ); @@ -879,7 +879,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { logger.verbose(`Performing management operation - getTopics() with options: %j`, options); const response: HttpOperationResponse = await this.listResources( "$Resources/Topics", - updatedOperationOptions, + updatedOptions, this.topicResourceSerializer ); @@ -971,7 +971,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { private async getTopicsRuntimeProperties( options?: ListRequestOptions & OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getTopicsRuntimeProperties", options ); @@ -982,7 +982,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { ); const response: HttpOperationResponse = await this.listResources( "$Resources/Topics", - updatedOperationOptions, + updatedOptions, this.topicResourceSerializer ); @@ -1089,7 +1089,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { topic: WithResponse, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-updateTopic", operationOptions ); @@ -1114,7 +1114,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { buildTopicOptions(topic), this.topicResourceSerializer, true, - updatedOperationOptions + updatedOptions ); return this.buildTopicResponse(response); @@ -1146,7 +1146,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { topicName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-deleteTopic", operationOptions ); @@ -1155,7 +1155,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.deleteResource( topicName, this.topicResourceSerializer, - updatedOperationOptions + updatedOptions ); return { _response: getHttpResponseOnly(response) }; @@ -1175,14 +1175,14 @@ export class ServiceBusAdministrationClient extends ServiceClient { * @param operationOptions - The options that can be used to abort, trace and control other configurations on the HTTP request. */ async topicExists(topicName: string, operationOptions?: OperationOptions): Promise { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-topicExists", operationOptions ); try { logger.verbose(`Performing management operation - topicExists() for "${topicName}"`); try { - await this.getTopic(topicName, updatedOperationOptions); + await this.getTopic(topicName, updatedOptions); } catch (error) { if (error.code == "MessageEntityNotFoundError") { return false; @@ -1221,7 +1221,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { subscriptionName: string, options?: CreateSubscriptionOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-createSubscription", options ); @@ -1236,7 +1236,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { buildSubscriptionOptions(options || {}), this.subscriptionResourceSerializer, false, - updatedOperationOptions + updatedOptions ); return this.buildSubscriptionResponse(response); @@ -1270,7 +1270,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { subscriptionName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getSubscription", operationOptions ); @@ -1282,7 +1282,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.getResource( fullPath, this.subscriptionResourceSerializer, - updatedOperationOptions + updatedOptions ); return this.buildSubscriptionResponse(response); @@ -1315,7 +1315,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { subscriptionName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getSubscriptionRuntimeProperties", operationOptions ); @@ -1327,7 +1327,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.getResource( fullPath, this.subscriptionResourceSerializer, - updatedOperationOptions + updatedOptions ); return this.buildSubscriptionRuntimePropertiesResponse(response); @@ -1359,7 +1359,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { topicName: string, options?: ListRequestOptions & OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getSubscriptions", options ); @@ -1370,7 +1370,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { ); const response: HttpOperationResponse = await this.listResources( topicName + "/Subscriptions/", - updatedOperationOptions, + updatedOptions, this.subscriptionResourceSerializer ); @@ -1470,7 +1470,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { topicName: string, options?: ListRequestOptions & OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getSubscriptionsRuntimeProperties", options ); @@ -1481,7 +1481,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { ); const response: HttpOperationResponse = await this.listResources( topicName + "/Subscriptions/", - updatedOperationOptions, + updatedOptions, this.subscriptionResourceSerializer ); @@ -1593,7 +1593,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { subscription: WithResponse, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-updateSubscription", operationOptions ); @@ -1625,7 +1625,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { buildSubscriptionOptions(subscription), this.subscriptionResourceSerializer, true, - updatedOperationOptions + updatedOptions ); return this.buildSubscriptionResponse(response); @@ -1658,7 +1658,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { subscriptionName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-deleteSubscription", operationOptions ); @@ -1670,7 +1670,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.deleteResource( fullPath, this.subscriptionResourceSerializer, - updatedOperationOptions + updatedOptions ); return { _response: getHttpResponseOnly(response) }; @@ -1694,7 +1694,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { subscriptionName: string, operationOptions?: OperationOptions ): Promise { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-subscriptionExists", operationOptions ); @@ -1703,7 +1703,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { `Performing management operation - subscriptionExists() for "${topicName}" and "${subscriptionName}"` ); try { - await this.getSubscription(topicName, subscriptionName, updatedOperationOptions); + await this.getSubscription(topicName, subscriptionName, updatedOptions); } catch (error) { if (error.code == "MessageEntityNotFoundError") { return false; @@ -1789,7 +1789,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { operOptions = { ...ruleActionOrOperationOptions, ...operationOptions }; } } - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-createRule", operOptions ); @@ -1804,7 +1804,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { { name: ruleName, filter: ruleFilter, action: ruleAction }, this.ruleResourceSerializer, false, - updatedOperationOptions + updatedOptions ); return this.buildRuleResponse(response); } catch (e) { @@ -1837,7 +1837,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { ruleName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getRule", operationOptions ); @@ -1847,7 +1847,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.getResource( fullPath, this.ruleResourceSerializer, - updatedOperationOptions + updatedOptions ); return this.buildRuleResponse(response); @@ -1879,16 +1879,13 @@ export class ServiceBusAdministrationClient extends ServiceClient { subscriptionName: string, options?: ListRequestOptions & OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( - "ServiceBusAdministrationClient-getRules", - options - ); + const { span, updatedOptions } = createSpan("ServiceBusAdministrationClient-getRules", options); try { logger.verbose(`Performing management operation - getRules() with options: %j`, options); const fullPath = this.getSubscriptionPath(topicName, subscriptionName) + "/Rules/"; const response: HttpOperationResponse = await this.listResources( fullPath, - updatedOperationOptions, + updatedOptions, this.ruleResourceSerializer ); @@ -1995,7 +1992,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { rule: WithResponse, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-updateRule", operationOptions ); @@ -2021,7 +2018,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { rule, this.ruleResourceSerializer, true, - updatedOperationOptions + updatedOptions ); return this.buildRuleResponse(response); @@ -2055,7 +2052,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { ruleName: string, operationOptions?: OperationOptions ): Promise> { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-deleteRule", operationOptions ); @@ -2065,7 +2062,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const response: HttpOperationResponse = await this.deleteResource( fullPath, this.ruleResourceSerializer, - updatedOperationOptions + updatedOptions ); return { _response: getHttpResponseOnly(response) }; @@ -2090,14 +2087,14 @@ export class ServiceBusAdministrationClient extends ServiceClient { ruleName: string, operationOptions?: OperationOptions ): Promise { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-ruleExists", operationOptions ); try { logger.verbose(`Performing management operation - ruleExists() for "${ruleName}"`); try { - await this.getRule(topicName, subscriptionName, ruleName, updatedOperationOptions); + await this.getRule(topicName, subscriptionName, ruleName, updatedOptions); } catch (error) { if (error.code == "MessageEntityNotFoundError") { return false; @@ -2130,7 +2127,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { isUpdate: boolean = false, operationOptions: OperationOptions = {} ): Promise { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-putResource", operationOptions ); @@ -2173,7 +2170,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { webResource.headers.set("content-type", "application/atom+xml;type=entry;charset=utf-8"); - return executeAtomXmlOperation(this, webResource, serializer, updatedOperationOptions); + return executeAtomXmlOperation(this, webResource, serializer, updatedOptions); } catch (e) { span.setStatus({ code: getCanonicalCode(e), @@ -2193,19 +2190,14 @@ export class ServiceBusAdministrationClient extends ServiceClient { serializer: AtomXmlSerializer, operationOptions: OperationOptions = {} ): Promise { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-getResource", operationOptions ); try { const webResource: WebResource = new WebResource(this.getUrl(name), "GET"); - const response = await executeAtomXmlOperation( - this, - webResource, - serializer, - updatedOperationOptions - ); + const response = await executeAtomXmlOperation(this, webResource, serializer, updatedOptions); if ( response.parsedBody == undefined || (Array.isArray(response.parsedBody) && response.parsedBody.length == 0) @@ -2239,7 +2231,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { options: ListRequestOptions & OperationOptions = {}, serializer: AtomXmlSerializer ): Promise { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-listResources", options ); @@ -2256,7 +2248,7 @@ export class ServiceBusAdministrationClient extends ServiceClient { const webResource: WebResource = new WebResource(this.getUrl(name, queryParams), "GET"); - return executeAtomXmlOperation(this, webResource, serializer, updatedOperationOptions); + return executeAtomXmlOperation(this, webResource, serializer, updatedOptions); } catch (e) { span.setStatus({ code: getCanonicalCode(e), @@ -2276,14 +2268,14 @@ export class ServiceBusAdministrationClient extends ServiceClient { serializer: AtomXmlSerializer, operationOptions: OperationOptions = {} ): Promise { - const { span, updatedOperationOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ServiceBusAdministrationClient-deleteResource", operationOptions ); try { const webResource: WebResource = new WebResource(this.getUrl(name), "DELETE"); - return executeAtomXmlOperation(this, webResource, serializer, updatedOperationOptions); + return executeAtomXmlOperation(this, webResource, serializer, updatedOptions); } catch (e) { span.setStatus({ code: getCanonicalCode(e), diff --git a/sdk/servicebus/service-bus/src/util/tracing.ts b/sdk/servicebus/service-bus/src/util/tracing.ts index 277db537fdc9..240a5b9b545f 100644 --- a/sdk/servicebus/service-bus/src/util/tracing.ts +++ b/sdk/servicebus/service-bus/src/util/tracing.ts @@ -1,49 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { OperationOptions, RestError } from "@azure/core-http"; -import { getTracer } from "@azure/core-tracing"; -import { CanonicalCode, Span, SpanKind, SpanOptions as OTSpanOptions } from "@opentelemetry/api"; +import { RestError } from "@azure/core-http"; +import { CanonicalCode } from "@opentelemetry/api"; +import { createSpanFunction } from "@azure/core-tracing"; /** - * @internal * Creates a span using the global tracer. - * @param name - The name of the operation being performed. - * @param operationOptions - The options for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - operationOptions: OperationOptions = {} -): { span: Span; updatedOperationOptions: OperationOptions } { - const tracer = getTracer(); - const spanOptions: OTSpanOptions = { - ...operationOptions.tracingOptions?.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.ServiceBus.${operationName}`, spanOptions); - span.setAttribute("az.namespace", "Microsoft.ServiceBus"); - - let newSpanOptions = operationOptions.tracingOptions?.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...operationOptions.tracingOptions?.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.ServiceBus" - } - }; - } - - return { - span, - updatedOperationOptions: { - ...operationOptions, - tracingOptions: { ...operationOptions?.tracingOptions, spanOptions: newSpanOptions } - } - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.ServiceBus", + namespace: "Microsoft.ServiceBus" +}); /** * @internal diff --git a/sdk/storage/storage-blob-changefeed/package.json b/sdk/storage/storage-blob-changefeed/package.json index 41fc5177bf91..43658380a5ee 100644 --- a/sdk/storage/storage-blob-changefeed/package.json +++ b/sdk/storage/storage-blob-changefeed/package.json @@ -99,7 +99,7 @@ "@azure/core-http": "^1.2.0", "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "events": "^3.0.0", diff --git a/sdk/storage/storage-blob-changefeed/src/ChangeFeed.ts b/sdk/storage/storage-blob-changefeed/src/ChangeFeed.ts index 85cfe3fd6208..91b6dacf13d6 100644 --- a/sdk/storage/storage-blob-changefeed/src/ChangeFeed.ts +++ b/sdk/storage/storage-blob-changefeed/src/ChangeFeed.ts @@ -80,10 +80,7 @@ export class ChangeFeed { } private async advanceSegmentIfNecessary(options: ChangeFeedGetChangeOptions = {}): Promise { - const { span, spanOptions } = createSpan( - "ChangeFeed-advanceSegmentIfNecessary", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ChangeFeed-advanceSegmentIfNecessary", options); try { if (!this.currentSegment) { throw new Error("Empty Change Feed shouldn't call this function."); @@ -102,7 +99,7 @@ export class ChangeFeed { undefined, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); } @@ -116,7 +113,7 @@ export class ChangeFeed { this.end, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); @@ -127,7 +124,7 @@ export class ChangeFeed { undefined, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); } else { @@ -161,17 +158,17 @@ export class ChangeFeed { public async getChange( options: ChangeFeedGetChangeOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ChangeFeed-getChange", options.tracingOptions); + const { span, updatedOptions } = createSpan("ChangeFeed-getChange", options); try { let event: BlobChangeFeedEvent | undefined = undefined; while (event === undefined && this.hasNext()) { event = await this.currentSegment!.getChange({ abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); await this.advanceSegmentIfNecessary({ abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } return event; diff --git a/sdk/storage/storage-blob-changefeed/src/ChangeFeedFactory.ts b/sdk/storage/storage-blob-changefeed/src/ChangeFeedFactory.ts index e1ba7256c8b9..263073a09c05 100644 --- a/sdk/storage/storage-blob-changefeed/src/ChangeFeedFactory.ts +++ b/sdk/storage/storage-blob-changefeed/src/ChangeFeedFactory.ts @@ -61,7 +61,7 @@ export class ChangeFeedFactory { continuationToken?: string, options: BlobChangeFeedListChangesOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ChangeFeedFactory-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("ChangeFeedFactory-create", options); try { const containerClient = blobServiceClient.getContainerClient(CHANGE_FEED_CONTAINER_NAME); @@ -82,7 +82,7 @@ export class ChangeFeedFactory { // Check if Change Feed has been enabled for this account. const changeFeedContainerExists = await containerClient.exists({ abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); if (!changeFeedContainerExists) { throw new Error( @@ -98,7 +98,7 @@ export class ChangeFeedFactory { const blobClient = containerClient.getBlobClient(CHANGE_FEED_META_SEGMENT_PATH); const blobDownloadRes = await blobClient.download(undefined, undefined, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); const lastConsumable = new Date( (JSON.parse(await bodyToString(blobDownloadRes)) as MetaSegments).lastConsumable @@ -107,7 +107,7 @@ export class ChangeFeedFactory { // Get year paths const years: number[] = await getYearsPaths(containerClient, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // Dequeue any years that occur before start time. @@ -130,7 +130,7 @@ export class ChangeFeedFactory { minDate(lastConsumable, options.end), { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); } @@ -143,7 +143,7 @@ export class ChangeFeedFactory { cursor?.CurrentSegmentCursor, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); diff --git a/sdk/storage/storage-blob-changefeed/src/LazyLoadingBlobStream.ts b/sdk/storage/storage-blob-changefeed/src/LazyLoadingBlobStream.ts index 2d854c35f3ed..a197865bde2a 100644 --- a/sdk/storage/storage-blob-changefeed/src/LazyLoadingBlobStream.ts +++ b/sdk/storage/storage-blob-changefeed/src/LazyLoadingBlobStream.ts @@ -71,14 +71,11 @@ export class LazyLoadingBlobStream extends Readable { } private async downloadBlock(options: LazyLoadingBlobStreamDownloadBlockOptions = {}) { - const { span, spanOptions } = createSpan( - "LazyLoadingBlobStream-downloadBlock", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("LazyLoadingBlobStream-downloadBlock", options); try { const properties = await this.blobClient.getProperties({ abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); this.blobLength = properties.contentLength!; @@ -93,7 +90,7 @@ export class LazyLoadingBlobStream extends Readable { this.lastDownloadBytes, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); this.offset += this.lastDownloadBytes; @@ -114,10 +111,7 @@ export class LazyLoadingBlobStream extends Readable { * @param size - Optional. The size of data to be read */ public async _read(size?: number) { - const { span, spanOptions } = createSpan( - "LazyLoadingBlobStream-read", - this.options?.tracingOptions - ); + const { span, updatedOptions } = createSpan("LazyLoadingBlobStream-read", this.options); try { if (!size) { @@ -130,7 +124,7 @@ export class LazyLoadingBlobStream extends Readable { if (this.lastDownloadData === undefined || this.lastDownloadData?.byteLength === 0) { await this.downloadBlock({ abortSignal: this.options?.abortSignal, - tracingOptions: { ...this.options?.tracingOptions, spanOptions } + tracingOptions: updatedOptions?.tracingOptions }); } if (this.lastDownloadData?.byteLength) { diff --git a/sdk/storage/storage-blob-changefeed/src/Segment.ts b/sdk/storage/storage-blob-changefeed/src/Segment.ts index f27c8a947590..b16d60beace9 100644 --- a/sdk/storage/storage-blob-changefeed/src/Segment.ts +++ b/sdk/storage/storage-blob-changefeed/src/Segment.ts @@ -58,7 +58,7 @@ export class Segment { public async getChange( options: SegmentGetChangeOptions = {} ): Promise { - const { span, spanOptions } = createSpan("Segment-getChange", options.tracingOptions); + const { span, updatedOptions } = createSpan("Segment-getChange", options); try { if (this.shardIndex >= this.shards.length || this.shardIndex < 0) { @@ -75,7 +75,7 @@ export class Segment { const currentShard = this.shards[this.shardIndex]; event = await currentShard.getChange({ abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); if (!currentShard.hasNext()) { diff --git a/sdk/storage/storage-blob-changefeed/src/SegmentFactory.ts b/sdk/storage/storage-blob-changefeed/src/SegmentFactory.ts index 737c761fac0d..daedcc7dcc59 100644 --- a/sdk/storage/storage-blob-changefeed/src/SegmentFactory.ts +++ b/sdk/storage/storage-blob-changefeed/src/SegmentFactory.ts @@ -46,7 +46,7 @@ export class SegmentFactory { cursor?: SegmentCursor, options: CreateSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan("SegmentFactory-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("SegmentFactory-create", options); try { const shards: Shard[] = []; @@ -55,7 +55,7 @@ export class SegmentFactory { const blobClient = containerClient.getBlobClient(manifestPath); const blobDownloadRes = await blobClient.download(undefined, undefined, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); const blobContent: string = await bodyToString(blobDownloadRes); @@ -73,7 +73,7 @@ export class SegmentFactory { shardCursor, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); if (shard.hasNext()) { diff --git a/sdk/storage/storage-blob-changefeed/src/Shard.ts b/sdk/storage/storage-blob-changefeed/src/Shard.ts index 15360b672a7c..46a96d7060cd 100644 --- a/sdk/storage/storage-blob-changefeed/src/Shard.ts +++ b/sdk/storage/storage-blob-changefeed/src/Shard.ts @@ -52,7 +52,7 @@ export class Shard { public async getChange( options: ShardGetChangeOptions = {} ): Promise { - const { span, spanOptions } = createSpan("Shard-getChange", options.tracingOptions); + const { span, updatedOptions } = createSpan("Shard-getChange", options); try { let event: BlobChangeFeedEvent | undefined = undefined; while (event === undefined && this.hasNext()) { @@ -67,7 +67,7 @@ export class Shard { undefined, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); } diff --git a/sdk/storage/storage-blob-changefeed/src/ShardFactory.ts b/sdk/storage/storage-blob-changefeed/src/ShardFactory.ts index 691ed1fc19bd..72d2ea59dbde 100644 --- a/sdk/storage/storage-blob-changefeed/src/ShardFactory.ts +++ b/sdk/storage/storage-blob-changefeed/src/ShardFactory.ts @@ -34,7 +34,7 @@ export class ShardFactory { shardCursor?: ShardCursor, options: CreateShardOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShardFactory-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShardFactory-create", options); try { const chunks: string[] = []; const blockOffset: number = shardCursor?.BlockOffset || 0; @@ -43,7 +43,7 @@ export class ShardFactory { for await (const blobItem of containerClient.listBlobsFlat({ prefix: shardPath, abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions })) { chunks.push(blobItem.name); } @@ -80,7 +80,7 @@ export class ShardFactory { eventIndex, { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); } diff --git a/sdk/storage/storage-blob-changefeed/src/utils/tracing.ts b/sdk/storage/storage-blob-changefeed/src/utils/tracing.ts index 881f79f84d93..c1402b5817e4 100644 --- a/sdk/storage/storage-blob-changefeed/src/utils/tracing.ts +++ b/sdk/storage/storage-blob-changefeed/src/utils/tracing.ts @@ -1,41 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer, OperationTracingOptions, SpanOptions } from "@azure/core-tracing"; -import { Span, SpanOptions as OTSpanOptions, SpanKind } from "@opentelemetry/api"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - tracingOptions: OperationTracingOptions = {} -): { span: Span; spanOptions: SpanOptions } { - const tracer = getTracer(); - const spanOptions: OTSpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Storage.Blob.Changefeed.${operationName}`, spanOptions); - span.setAttribute("az.namespace", "Microsoft.Storage"); - - let newOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Storage" - } - }; - } - - return { - span, - spanOptions: newOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Storage.Blob.Changefeed", + namespace: "Microsoft.Storage" +}); diff --git a/sdk/storage/storage-blob-changefeed/src/utils/utils.common.ts b/sdk/storage/storage-blob-changefeed/src/utils/utils.common.ts index 576c6a4aa645..a03dd7a0543a 100644 --- a/sdk/storage/storage-blob-changefeed/src/utils/utils.common.ts +++ b/sdk/storage/storage-blob-changefeed/src/utils/utils.common.ts @@ -67,12 +67,12 @@ export async function getYearsPaths( containerClient: ContainerClient, options: GetYearsPathsOptions = {} ): Promise { - const { span, spanOptions } = createSpan("getYearsPaths", options.tracingOptions); + const { span, updatedOptions } = createSpan("getYearsPaths", options); try { const years: number[] = []; for await (const item of containerClient.listBlobsByHierarchy("/", { abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions }, + tracingOptions: updatedOptions.tracingOptions, prefix: CHANGE_FEED_SEGMENT_PREFIX })) { // TODO: add String.prototype.includes polyfill for IE11 @@ -111,7 +111,7 @@ export async function getSegmentsInYear( endTime?: Date, options: GetSegmentsInYearOptions = {} ): Promise { - const { span, spanOptions } = createSpan("getSegmentsInYear", options.tracingOptions); + const { span, updatedOptions } = createSpan("getSegmentsInYear", options); try { const segments: string[] = []; @@ -124,7 +124,7 @@ export async function getSegmentsInYear( for await (const item of containerClient.listBlobsFlat({ prefix, abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions })) { const segmentTime = parseDateFromSegmentPath(item.name); if ((startTime && segmentTime < startTime) || (endTime && segmentTime >= endTime)) { diff --git a/sdk/storage/storage-blob/package.json b/sdk/storage/storage-blob/package.json index e9d942481229..5ff54ca01baa 100644 --- a/sdk/storage/storage-blob/package.json +++ b/sdk/storage/storage-blob/package.json @@ -122,7 +122,7 @@ "@azure/core-http": "^1.2.0", "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "events": "^3.0.0", diff --git a/sdk/storage/storage-blob/src/BlobBatch.ts b/sdk/storage/storage-blob/src/BlobBatch.ts index 58bb53b0d437..38a6817cc2db 100644 --- a/sdk/storage/storage-blob/src/BlobBatch.ts +++ b/sdk/storage/storage-blob/src/BlobBatch.ts @@ -184,10 +184,7 @@ export class BlobBatch { options = {}; } - const { span, spanOptions } = createSpan( - "BatchDeleteRequest-addSubRequest", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BatchDeleteRequest-addSubRequest", options); try { this.setBatchType("delete"); @@ -197,10 +194,9 @@ export class BlobBatch { credential: credential }, async () => { - await new BlobClient(url, this.batchRequest.createPipeline(credential)).delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + await new BlobClient(url, this.batchRequest.createPipeline(credential)).delete( + updatedOptions + ); } ); } catch (e) { @@ -303,10 +299,7 @@ export class BlobBatch { options = {}; } - const { span, spanOptions } = createSpan( - "BatchSetTierRequest-addSubRequest", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BatchSetTierRequest-addSubRequest", options); try { this.setBatchType("setAccessTier"); @@ -318,10 +311,7 @@ export class BlobBatch { async () => { await new BlobClient(url, this.batchRequest.createPipeline(credential)).setAccessTier( tier, - { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - } + updatedOptions ); } ); diff --git a/sdk/storage/storage-blob/src/BlobBatchClient.ts b/sdk/storage/storage-blob/src/BlobBatchClient.ts index f07644c6e7b6..1c88fb78f8c4 100644 --- a/sdk/storage/storage-blob/src/BlobBatchClient.ts +++ b/sdk/storage/storage-blob/src/BlobBatchClient.ts @@ -13,7 +13,7 @@ import { utf8ByteLength } from "./BatchUtils"; import { BlobBatch } from "./BlobBatch"; import { AbortSignalLike } from "@azure/abort-controller"; import { CanonicalCode } from "@opentelemetry/api"; -import { createSpan } from "./utils/tracing"; +import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing"; import { HttpResponse, TokenCredential } from "@azure/core-http"; import { Service, Container } from "./generated/src/operations"; import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential"; @@ -303,7 +303,7 @@ export class BlobBatchClient { throw new RangeError("Batch request should contain one or more sub requests."); } - const { span, spanOptions } = createSpan("BlobBatchClient-submitBatch", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobBatchClient-submitBatch", options); try { const batchRequestBody = batchRequest.getHttpRequestBody(); @@ -314,7 +314,7 @@ export class BlobBatchClient { batchRequest.getMultiPartContentType(), { ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); diff --git a/sdk/storage/storage-blob/src/BlobLeaseClient.ts b/sdk/storage/storage-blob/src/BlobLeaseClient.ts index 586c4a6defd5..7202a2f96ff0 100644 --- a/sdk/storage/storage-blob/src/BlobLeaseClient.ts +++ b/sdk/storage/storage-blob/src/BlobLeaseClient.ts @@ -9,7 +9,7 @@ import { Blob as StorageBlob, Container } from "./generated/src/operations"; import { ModifiedAccessConditions } from "./models"; import { CommonOptions } from "./StorageClient"; import { ETagNone } from "./utils/constants"; -import { createSpan } from "./utils/tracing"; +import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing"; import { BlobClient } from "./Clients"; import { ContainerClient } from "./ContainerClient"; @@ -163,10 +163,7 @@ export class BlobLeaseClient { duration: number, options: LeaseOperationOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlobLeaseClient-acquireLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobLeaseClient-acquireLease", options); if ( this._isContainer && @@ -188,7 +185,7 @@ export class BlobLeaseClient { ifTags: options.conditions?.tagConditions }, proposedLeaseId: this._leaseId, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -215,7 +212,7 @@ export class BlobLeaseClient { proposedLeaseId: string, options: LeaseOperationOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobLeaseClient-changeLease", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobLeaseClient-changeLease", options); if ( this._isContainer && @@ -238,7 +235,7 @@ export class BlobLeaseClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); this._leaseId = proposedLeaseId; @@ -265,10 +262,7 @@ export class BlobLeaseClient { * @returns Response data for release lease operation. */ public async releaseLease(options: LeaseOperationOptions = {}): Promise { - const { span, spanOptions } = createSpan( - "BlobLeaseClient-releaseLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobLeaseClient-releaseLease", options); if ( this._isContainer && @@ -288,7 +282,7 @@ export class BlobLeaseClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -311,7 +305,7 @@ export class BlobLeaseClient { * @returns Response data for renew lease operation. */ public async renewLease(options: LeaseOperationOptions = {}): Promise { - const { span, spanOptions } = createSpan("BlobLeaseClient-renewLease", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobLeaseClient-renewLease", options); if ( this._isContainer && @@ -331,7 +325,7 @@ export class BlobLeaseClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -359,7 +353,7 @@ export class BlobLeaseClient { breakPeriod: number, options: LeaseOperationOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobLeaseClient-breakLease", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobLeaseClient-breakLease", options); if ( this._isContainer && @@ -380,7 +374,7 @@ export class BlobLeaseClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }; return await this._containerOrBlobOperation.breakLease(operationOptions); } catch (e) { diff --git a/sdk/storage/storage-blob/src/BlobServiceClient.ts b/sdk/storage/storage-blob/src/BlobServiceClient.ts index cfce2b6622b2..0e847e6ac2f9 100644 --- a/sdk/storage/storage-blob/src/BlobServiceClient.ts +++ b/sdk/storage/storage-blob/src/BlobServiceClient.ts @@ -46,7 +46,7 @@ import { AnonymousCredential } from "./credentials/AnonymousCredential"; import "@azure/core-paging"; import { PageSettings, PagedAsyncIterableIterator } from "@azure/core-paging"; import { truncatedISO8061Date } from "./utils/utils.common"; -import { createSpan } from "./utils/tracing"; +import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing"; import { BlobBatchClient } from "./BlobBatchClient"; import { CommonOptions, StorageClient } from "./StorageClient"; import { Tags } from "./models"; @@ -536,16 +536,10 @@ export class BlobServiceClient extends StorageClient { containerClient: ContainerClient; containerCreateResponse: ContainerCreateResponse; }> { - const { span, spanOptions } = createSpan( - "BlobServiceClient-createContainer", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-createContainer", options); try { const containerClient = this.getContainerClient(containerName); - const containerCreateResponse = await containerClient.create({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const containerCreateResponse = await containerClient.create(updatedOptions); return { containerClient, containerCreateResponse @@ -572,16 +566,10 @@ export class BlobServiceClient extends StorageClient { containerName: string, options: ContainerDeleteMethodOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlobServiceClient-deleteContainer", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-deleteContainer", options); try { const containerClient = this.getContainerClient(containerName); - return await containerClient.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await containerClient.delete(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -610,10 +598,7 @@ export class BlobServiceClient extends StorageClient { containerClient: ContainerClient; containerUndeleteResponse: ContainerUndeleteResponse; }> { - const { span, spanOptions } = createSpan( - "BlobServiceClient-undeleteContainer", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-undeleteContainer", options); try { const containerClient = this.getContainerClient( options.destinationContainerName || deletedContainerName @@ -623,8 +608,7 @@ export class BlobServiceClient extends StorageClient { const containerUndeleteResponse = await containerContext.restore({ deletedContainerName, deletedContainerVersion, - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } + ...updatedOptions }); return { containerClient, containerUndeleteResponse }; } catch (e) { @@ -654,18 +638,14 @@ export class BlobServiceClient extends StorageClient { containerClient: ContainerClient; containerRenameResponse: ContainerRenameResponse; }> { - const { span, spanOptions } = createSpan( - "BlobServiceClient-renameContainer", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-renameContainer", options); try { const containerClient = this.getContainerClient(destinationContainerName); // Hack to access a protected member. const containerContext = new Container(containerClient["storageClientContext"]); const containerRenameResponse = await containerContext.rename(sourceContainerName, { - ...options, - sourceLeaseId: options.sourceCondition?.leaseId, - tracingOptions: { ...options.tracingOptions, spanOptions } + ...updatedOptions, + sourceLeaseId: options.sourceCondition?.leaseId }); return { containerClient, containerRenameResponse }; } catch (e) { @@ -690,14 +670,11 @@ export class BlobServiceClient extends StorageClient { public async getProperties( options: ServiceGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlobServiceClient-getProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-getProperties", options); try { return await this.serviceContext.getProperties({ abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -723,14 +700,11 @@ export class BlobServiceClient extends StorageClient { properties: BlobServiceProperties, options: ServiceSetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlobServiceClient-setProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-setProperties", options); try { return await this.serviceContext.setProperties(properties, { abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -755,14 +729,11 @@ export class BlobServiceClient extends StorageClient { public async getStatistics( options: ServiceGetStatisticsOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlobServiceClient-getStatistics", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-getStatistics", options); try { return await this.serviceContext.getStatistics({ abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -788,14 +759,11 @@ export class BlobServiceClient extends StorageClient { public async getAccountInfo( options: ServiceGetAccountInfoOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlobServiceClient-getAccountInfo", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-getAccountInfo", options); try { return await this.serviceContext.getAccountInfo({ abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -826,10 +794,7 @@ export class BlobServiceClient extends StorageClient { marker?: string, options: ServiceListContainersSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlobServiceClient-listContainersSegment", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-listContainersSegment", options); try { return await this.serviceContext.listContainersSegment({ @@ -837,7 +802,7 @@ export class BlobServiceClient extends StorageClient { marker, ...options, include: typeof options.include === "string" ? [options.include] : options.include, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -873,9 +838,9 @@ export class BlobServiceClient extends StorageClient { marker?: string, options: ServiceFindBlobsByTagsSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "BlobServiceClient-findBlobsByTagsSegment", - options.tracingOptions + options ); try { @@ -884,7 +849,7 @@ export class BlobServiceClient extends StorageClient { where: tagFilterSqlExpression, marker, maxPageSize: options.maxPageSize, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const wrappedResponse: ServiceFindBlobsByTagsSegmentResponse = { @@ -1258,10 +1223,7 @@ export class BlobServiceClient extends StorageClient { expiresOn: Date, options: ServiceGetUserDelegationKeyOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlobServiceClient-getUserDelegationKey", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlobServiceClient-getUserDelegationKey", options); try { const response = await this.serviceContext.getUserDelegationKey( { @@ -1270,7 +1232,7 @@ export class BlobServiceClient extends StorageClient { }, { abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); diff --git a/sdk/storage/storage-blob/src/Clients.ts b/sdk/storage/storage-blob/src/Clients.ts index 2db09f8bf579..ad3889fbc646 100644 --- a/sdk/storage/storage-blob/src/Clients.ts +++ b/sdk/storage/storage-blob/src/Clients.ts @@ -105,7 +105,7 @@ import { ETagAny, URLConstants } from "./utils/constants"; -import { createSpan } from "./utils/tracing"; +import { createSpan, convertTracingToRequestOptionsBase } from "./utils/tracing"; import { appendToURLPath, appendToURLQuery, @@ -1063,7 +1063,7 @@ export class BlobClient extends StorageClient { options.conditions = options.conditions || {}; ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); - const { span, spanOptions } = createSpan("BlobClient-download", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-download", options); try { const res = await this.blobContext.download({ @@ -1079,7 +1079,7 @@ export class BlobClient extends StorageClient { rangeGetContentCRC64: options.rangeGetContentCrc64, snapshot: options.snapshot, cpkInfo: options.customerProvidedKey, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const wrappedRes = { @@ -1175,17 +1175,14 @@ export class BlobClient extends StorageClient { * @param options - options to Exists operation. */ public async exists(options: BlobExistsOptions = {}): Promise { - const { span, spanOptions } = createSpan("BlobClient-exists", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-exists", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); await this.getProperties({ abortSignal: options.abortSignal, customerProvidedKey: options.customerProvidedKey, conditions: options.conditions, - tracingOptions: { - ...options.tracingOptions, - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); return true; } catch (e) { @@ -1221,7 +1218,7 @@ export class BlobClient extends StorageClient { public async getProperties( options: BlobGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-getProperties", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-getProperties", options); try { options.conditions = options.conditions || {}; ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); @@ -1233,7 +1230,7 @@ export class BlobClient extends StorageClient { ifTags: options.conditions?.tagConditions }, cpkInfo: options.customerProvidedKey, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); return { @@ -1263,7 +1260,7 @@ export class BlobClient extends StorageClient { * @param options - Optional options to Blob Delete operation. */ public async delete(options: BlobDeleteOptions = {}): Promise { - const { span, spanOptions } = createSpan("BlobClient-delete", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-delete", options); options.conditions = options.conditions || {}; try { return await this.blobContext.deleteMethod({ @@ -1274,7 +1271,7 @@ export class BlobClient extends StorageClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1299,12 +1296,9 @@ export class BlobClient extends StorageClient { public async deleteIfExists( options: BlobDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-deleteIfExists", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-deleteIfExists", options); try { - const res = await this.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.delete(updatedOptions); return { succeeded: true, ...res, @@ -1341,11 +1335,11 @@ export class BlobClient extends StorageClient { * @param options - Optional options to Blob Undelete operation. */ public async undelete(options: BlobUndeleteOptions = {}): Promise { - const { span, spanOptions } = createSpan("BlobClient-undelete", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-undelete", options); try { return await this.blobContext.undelete({ abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1374,7 +1368,7 @@ export class BlobClient extends StorageClient { blobHTTPHeaders?: BlobHTTPHeaders, options: BlobSetHTTPHeadersOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-setHTTPHeaders", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-setHTTPHeaders", options); options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); @@ -1387,7 +1381,7 @@ export class BlobClient extends StorageClient { ifTags: options.conditions?.tagConditions }, cpkInfo: options.customerProvidedKey, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1415,7 +1409,7 @@ export class BlobClient extends StorageClient { metadata?: Metadata, options: BlobSetMetadataOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-setMetadata", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-setMetadata", options); options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); @@ -1429,7 +1423,7 @@ export class BlobClient extends StorageClient { }, cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1452,7 +1446,7 @@ export class BlobClient extends StorageClient { * @param options - */ public async setTags(tags: Tags, options: BlobSetTagsOptions = {}): Promise { - const { span, spanOptions } = createSpan("BlobClient-setTags", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-setTags", options); try { return await this.blobContext.setTags({ abortSignal: options.abortSignal, @@ -1461,7 +1455,7 @@ export class BlobClient extends StorageClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions, + ...convertTracingToRequestOptionsBase(updatedOptions), tags: toBlobTags(tags) }); } catch (e) { @@ -1481,7 +1475,7 @@ export class BlobClient extends StorageClient { * @param options - */ public async getTags(options: BlobGetTagsOptions = {}): Promise { - const { span, spanOptions } = createSpan("BlobClient-getTags", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-getTags", options); try { const response = await this.blobContext.getTags({ abortSignal: options.abortSignal, @@ -1490,7 +1484,7 @@ export class BlobClient extends StorageClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const wrappedResponse: BlobGetTagsResponse = { ...response, @@ -1528,7 +1522,7 @@ export class BlobClient extends StorageClient { public async createSnapshot( options: BlobCreateSnapshotOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-createSnapshot", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-createSnapshot", options); options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); @@ -1542,7 +1536,7 @@ export class BlobClient extends StorageClient { }, cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1666,12 +1660,12 @@ export class BlobClient extends StorageClient { copyId: string, options: BlobAbortCopyFromURLOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-abortCopyFromURL", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-abortCopyFromURL", options); try { return await this.blobContext.abortCopyFromURL(copyId, { abortSignal: options.abortSignal, leaseAccessConditions: options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1696,7 +1690,7 @@ export class BlobClient extends StorageClient { copySource: string, options: BlobSyncCopyFromURLOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-syncCopyFromURL", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-syncCopyFromURL", options); options.conditions = options.conditions || {}; options.sourceConditions = options.sourceConditions || {}; @@ -1717,7 +1711,7 @@ export class BlobClient extends StorageClient { }, sourceContentMD5: options.sourceContentMD5, blobTagsString: toBlobTagsString(options.tags), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1745,7 +1739,7 @@ export class BlobClient extends StorageClient { tier: BlockBlobTier | PremiumPageBlobTier | string, options: BlobSetTierOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-setAccessTier", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-setAccessTier", options); try { return await this.blobContext.setTier(toAccessTier(tier)!, { abortSignal: options.abortSignal, @@ -1755,7 +1749,7 @@ export class BlobClient extends StorageClient { ifTags: options.conditions?.tagConditions }, rehydratePriority: options.rehydratePriority, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1831,7 +1825,7 @@ export class BlobClient extends StorageClient { count = typeof param2 === "number" ? param2 : 0; options = (param3 as BlobDownloadToBufferOptions) || {}; } - const { span, spanOptions } = createSpan("BlobClient-downloadToBuffer", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-downloadToBuffer", options); try { if (!options.blockSize) { @@ -1862,7 +1856,7 @@ export class BlobClient extends StorageClient { ...options, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); count = response.contentLength! - offset; @@ -1906,7 +1900,7 @@ export class BlobClient extends StorageClient { customerProvidedKey: options.customerProvidedKey, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); const stream = response.readableStreamBody!; @@ -1955,13 +1949,13 @@ export class BlobClient extends StorageClient { count?: number, options: BlobDownloadOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-downloadToFile", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-downloadToFile", options); try { const response = await this.download(offset, count, { ...options, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); if (response.readableStreamBody) { @@ -2052,7 +2046,7 @@ export class BlobClient extends StorageClient { copySource: string, options: BlobStartCopyFromURLOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlobClient-startCopyFromURL", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlobClient-startCopyFromURL", options); options.conditions = options.conditions || {}; options.sourceConditions = options.sourceConditions || {}; @@ -2076,7 +2070,7 @@ export class BlobClient extends StorageClient { tier: toAccessTier(options.tier), blobTagsString: toBlobTagsString(options.tags), sealBlob: options.sealBlob, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -2495,7 +2489,7 @@ export class AppendBlobClient extends BlobClient { * ``` */ public async create(options: AppendBlobCreateOptions = {}): Promise { - const { span, spanOptions } = createSpan("AppendBlobClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("AppendBlobClient-create", options); options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); @@ -2512,7 +2506,7 @@ export class AppendBlobClient extends BlobClient { cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, blobTagsString: toBlobTagsString(options.tags), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -2535,16 +2529,12 @@ export class AppendBlobClient extends BlobClient { public async createIfNotExists( options: AppendBlobCreateIfNotExistsOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "AppendBlobClient-createIfNotExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("AppendBlobClient-createIfNotExists", options); const conditions = { ifNoneMatch: ETagAny }; try { const res = await this.create({ - ...options, - conditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + ...updatedOptions, + conditions }); return { succeeded: true, @@ -2580,7 +2570,7 @@ export class AppendBlobClient extends BlobClient { * @param options - */ public async seal(options: AppendBlobSealOptions = {}): Promise { - const { span, spanOptions } = createSpan("AppendBlobClient-seal", options.tracingOptions); + const { span, updatedOptions } = createSpan("AppendBlobClient-seal", options); options.conditions = options.conditions || {}; try { return await this.appendBlobContext.seal({ @@ -2591,7 +2581,7 @@ export class AppendBlobClient extends BlobClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -2633,10 +2623,7 @@ export class AppendBlobClient extends BlobClient { contentLength: number, options: AppendBlobAppendBlockOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "AppendBlobClient-appendBlock", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("AppendBlobClient-appendBlock", options); options.conditions = options.conditions || {}; try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); @@ -2654,7 +2641,7 @@ export class AppendBlobClient extends BlobClient { transactionalContentCrc64: options.transactionalContentCrc64, cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -2687,10 +2674,7 @@ export class AppendBlobClient extends BlobClient { count: number, options: AppendBlobAppendBlockFromURLOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "AppendBlobClient-appendBlockFromURL", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("AppendBlobClient-appendBlockFromURL", options); options.conditions = options.conditions || {}; options.sourceConditions = options.sourceConditions || {}; try { @@ -2715,7 +2699,7 @@ export class AppendBlobClient extends BlobClient { }, cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -3460,7 +3444,7 @@ export class BlockBlobClient extends BlobClient { ): Promise { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); - const { span, spanOptions } = createSpan("BlockBlobClient-query", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlockBlobClient-query", options); try { if (!isNode) { @@ -3479,7 +3463,7 @@ export class BlockBlobClient extends BlobClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); return new BlobQueryResponse(response, { abortSignal: options.abortSignal, @@ -3530,7 +3514,7 @@ export class BlockBlobClient extends BlobClient { options: BlockBlobUploadOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("BlockBlobClient-upload", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlockBlobClient-upload", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return await this.blockBlobContext.upload(body, contentLength, { @@ -3547,7 +3531,7 @@ export class BlockBlobClient extends BlobClient { encryptionScope: options.encryptionScope, tier: toAccessTier(options.tier), blobTagsString: toBlobTagsString(options.tags), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -3584,10 +3568,7 @@ export class BlockBlobClient extends BlobClient { options: BlockBlobSyncUploadFromURLOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "BlockBlobClient-syncUploadFromURL", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlockBlobClient-syncUploadFromURL", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return await this.blockBlobContext.putBlobFromUrl(0, sourceURL, { @@ -3607,7 +3588,7 @@ export class BlockBlobClient extends BlobClient { cpkInfo: options.customerProvidedKey, tier: toAccessTier(options.tier), blobTagsString: toBlobTagsString(options.tags), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -3637,7 +3618,7 @@ export class BlockBlobClient extends BlobClient { contentLength: number, options: BlockBlobStageBlockOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlockBlobClient-stageBlock", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlockBlobClient-stageBlock", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return await this.blockBlobContext.stageBlock(blockId, contentLength, body, { @@ -3648,7 +3629,7 @@ export class BlockBlobClient extends BlobClient { transactionalContentCrc64: options.transactionalContentCrc64, cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -3689,10 +3670,7 @@ export class BlockBlobClient extends BlobClient { count?: number, options: BlockBlobStageBlockFromURLOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlockBlobClient-stageBlockFromURL", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlockBlobClient-stageBlockFromURL", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return await this.blockBlobContext.stageBlockFromURL(blockId, 0, sourceURL, { @@ -3703,7 +3681,7 @@ export class BlockBlobClient extends BlobClient { sourceRange: offset === 0 && !count ? undefined : rangeToString({ offset, count }), cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -3733,10 +3711,7 @@ export class BlockBlobClient extends BlobClient { options: BlockBlobCommitBlockListOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "BlockBlobClient-commitBlockList", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlockBlobClient-commitBlockList", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return await this.blockBlobContext.commitBlockList( @@ -3754,7 +3729,7 @@ export class BlockBlobClient extends BlobClient { encryptionScope: options.encryptionScope, tier: toAccessTier(options.tier), blobTagsString: toBlobTagsString(options.tags), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -3782,10 +3757,7 @@ export class BlockBlobClient extends BlobClient { listType: BlockListType, options: BlockBlobGetBlockListOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlockBlobClient-getBlockList", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlockBlobClient-getBlockList", options); try { const res = await this.blockBlobContext.getBlockList(listType, { abortSignal: options.abortSignal, @@ -3794,7 +3766,7 @@ export class BlockBlobClient extends BlobClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); if (!res.committedBlocks) { @@ -3834,7 +3806,7 @@ export class BlockBlobClient extends BlobClient { data: Buffer | Blob | ArrayBuffer | ArrayBufferView, options: BlockBlobParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlockBlobClient-uploadData", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlockBlobClient-uploadData", options); try { if (isNode) { let buffer: Buffer; @@ -3850,17 +3822,14 @@ export class BlockBlobClient extends BlobClient { return this.uploadSeekableInternal( (offset: number, size: number): Buffer => buffer.slice(offset, offset + size), buffer.byteLength, - { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - } + updatedOptions ); } else { const browserBlob = new Blob([data]); return this.uploadSeekableInternal( (offset: number, size: number): Blob => browserBlob.slice(offset, offset + size), browserBlob.size, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + updatedOptions ); } } catch (e) { @@ -3893,16 +3862,13 @@ export class BlockBlobClient extends BlobClient { browserData: Blob | ArrayBuffer | ArrayBufferView, options: BlockBlobParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "BlockBlobClient-uploadBrowserData", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlockBlobClient-uploadBrowserData", options); try { const browserBlob = new Blob([browserData]); return await this.uploadSeekableInternal( (offset: number, size: number): Blob => browserBlob.slice(offset, offset + size), browserBlob.size, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + updatedOptions ); } catch (e) { span.setStatus({ @@ -3974,17 +3940,11 @@ export class BlockBlobClient extends BlobClient { options.conditions = {}; } - const { span, spanOptions } = createSpan( - "BlockBlobClient-uploadSeekableInternal", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlockBlobClient-uploadSeekableInternal", options); try { if (size <= options.maxSingleShotSize) { - return await this.upload(bodyFactory(0, size), size, { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await this.upload(bodyFactory(0, size), size, updatedOptions); } const numBlocks: number = Math.floor((size - 1) / options.blockSize) + 1; @@ -4012,7 +3972,7 @@ export class BlockBlobClient extends BlobClient { abortSignal: options.abortSignal, conditions: options.conditions, encryptionScope: options.encryptionScope, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // Update progress after block is successfully uploaded to server, in case of block trying // TODO: Hook with convenience layer progress event in finer level @@ -4027,10 +3987,7 @@ export class BlockBlobClient extends BlobClient { } await batch.do(); - return this.commitBlockList(blockList, { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return this.commitBlockList(blockList, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -4059,7 +4016,7 @@ export class BlockBlobClient extends BlobClient { filePath: string, options: BlockBlobParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan("BlockBlobClient-uploadFile", options.tracingOptions); + const { span, updatedOptions } = createSpan("BlockBlobClient-uploadFile", options); try { const size = (await fsStat(filePath)).size; return await this.uploadSeekableInternal( @@ -4072,7 +4029,13 @@ export class BlockBlobClient extends BlobClient { }); }, size, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + { + ...options, + tracingOptions: { + ...options!.tracingOptions, + ...convertTracingToRequestOptionsBase(updatedOptions) + } + } ); } catch (e) { span.setStatus({ @@ -4114,10 +4077,7 @@ export class BlockBlobClient extends BlobClient { options.conditions = {}; } - const { span, spanOptions } = createSpan( - "BlockBlobClient-uploadStream", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("BlockBlobClient-uploadStream", options); try { let blockNum = 0; @@ -4137,7 +4097,7 @@ export class BlockBlobClient extends BlobClient { await this.stageBlock(blockID, body, length, { conditions: options.conditions, encryptionScope: options.encryptionScope, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // Update progress after block is successfully uploaded to server, in case of block trying @@ -4156,7 +4116,10 @@ export class BlockBlobClient extends BlobClient { return await this.commitBlockList(blockList, { ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: { + ...options!.tracingOptions, + ...convertTracingToRequestOptionsBase(updatedOptions) + } }); } catch (e) { span.setStatus({ @@ -4648,7 +4611,7 @@ export class PageBlobClient extends BlobClient { options: PageBlobCreateOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("PageBlobClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("PageBlobClient-create", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return await this.pageBlobContext.create(0, size, { @@ -4665,7 +4628,7 @@ export class PageBlobClient extends BlobClient { encryptionScope: options.encryptionScope, tier: toAccessTier(options.tier), blobTagsString: toBlobTagsString(options.tags), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -4691,16 +4654,13 @@ export class PageBlobClient extends BlobClient { size: number, options: PageBlobCreateIfNotExistsOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "PageBlobClient-createIfNotExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("PageBlobClient-createIfNotExists", options); try { const conditions = { ifNoneMatch: ETagAny }; const res = await this.create(size, { ...options, conditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); return { succeeded: true, @@ -4747,7 +4707,7 @@ export class PageBlobClient extends BlobClient { options: PageBlobUploadPagesOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("PageBlobClient-uploadPages", options.tracingOptions); + const { span, updatedOptions } = createSpan("PageBlobClient-uploadPages", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return await this.pageBlobContext.uploadPages(body, count, { @@ -4764,7 +4724,7 @@ export class PageBlobClient extends BlobClient { transactionalContentCrc64: options.transactionalContentCrc64, cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -4797,10 +4757,7 @@ export class PageBlobClient extends BlobClient { ): Promise { options.conditions = options.conditions || {}; options.sourceConditions = options.sourceConditions || {}; - const { span, spanOptions } = createSpan( - "PageBlobClient-uploadPagesFromURL", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("PageBlobClient-uploadPagesFromURL", options); try { ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps); return await this.pageBlobContext.uploadPagesFromURL( @@ -4826,7 +4783,7 @@ export class PageBlobClient extends BlobClient { }, cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -4855,7 +4812,7 @@ export class PageBlobClient extends BlobClient { options: PageBlobClearPagesOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("PageBlobClient-clearPages", options.tracingOptions); + const { span, updatedOptions } = createSpan("PageBlobClient-clearPages", options); try { return await this.pageBlobContext.clearPages(0, { abortSignal: options.abortSignal, @@ -4868,7 +4825,7 @@ export class PageBlobClient extends BlobClient { sequenceNumberAccessConditions: options.conditions, cpkInfo: options.customerProvidedKey, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -4896,10 +4853,7 @@ export class PageBlobClient extends BlobClient { options: PageBlobGetPageRangesOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "PageBlobClient-getPageRanges", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("PageBlobClient-getPageRanges", options); try { return await this.pageBlobContext .getPageRanges({ @@ -4910,7 +4864,7 @@ export class PageBlobClient extends BlobClient { ifTags: options.conditions?.tagConditions }, range: rangeToString({ offset, count }), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }) .then(rangeResponseFromModel); } catch (e) { @@ -4941,10 +4895,7 @@ export class PageBlobClient extends BlobClient { options: PageBlobGetPageRangesDiffOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "PageBlobClient-getPageRangesDiff", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("PageBlobClient-getPageRangesDiff", options); try { return await this.pageBlobContext @@ -4957,7 +4908,7 @@ export class PageBlobClient extends BlobClient { }, prevsnapshot: prevSnapshot, range: rangeToString({ offset, count }), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }) .then(rangeResponseFromModel); } catch (e) { @@ -4988,9 +4939,9 @@ export class PageBlobClient extends BlobClient { options: PageBlobGetPageRangesDiffOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "PageBlobClient-GetPageRangesDiffForManagedDisks", - options.tracingOptions + options ); try { @@ -5004,7 +4955,7 @@ export class PageBlobClient extends BlobClient { }, prevSnapshotUrl, range: rangeToString({ offset, count }), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }) .then(rangeResponseFromModel); } catch (e) { @@ -5031,7 +4982,7 @@ export class PageBlobClient extends BlobClient { options: PageBlobResizeOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("PageBlobClient-resize", options.tracingOptions); + const { span, updatedOptions } = createSpan("PageBlobClient-resize", options); try { return await this.pageBlobContext.resize(size, { abortSignal: options.abortSignal, @@ -5041,7 +4992,7 @@ export class PageBlobClient extends BlobClient { ifTags: options.conditions?.tagConditions }, encryptionScope: options.encryptionScope, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -5069,10 +5020,7 @@ export class PageBlobClient extends BlobClient { options: PageBlobUpdateSequenceNumberOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "PageBlobClient-updateSequenceNumber", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("PageBlobClient-updateSequenceNumber", options); try { return await this.pageBlobContext.updateSequenceNumber(sequenceNumberAction, { abortSignal: options.abortSignal, @@ -5082,7 +5030,7 @@ export class PageBlobClient extends BlobClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -5112,10 +5060,7 @@ export class PageBlobClient extends BlobClient { copySource: string, options: PageBlobStartCopyIncrementalOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "PageBlobClient-startCopyIncremental", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("PageBlobClient-startCopyIncremental", options); try { return await this.pageBlobContext.copyIncremental(copySource, { abortSignal: options.abortSignal, @@ -5123,7 +5068,7 @@ export class PageBlobClient extends BlobClient { ...options.conditions, ifTags: options.conditions?.tagConditions }, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ diff --git a/sdk/storage/storage-blob/src/ContainerClient.ts b/sdk/storage/storage-blob/src/ContainerClient.ts index 85ac00b3b96c..1af3ec080018 100644 --- a/sdk/storage/storage-blob/src/ContainerClient.ts +++ b/sdk/storage/storage-blob/src/ContainerClient.ts @@ -45,7 +45,7 @@ import { } from "./models"; import { newPipeline, Pipeline, StoragePipelineOptions } from "./Pipeline"; import { CommonOptions, StorageClient } from "./StorageClient"; -import { createSpan } from "./utils/tracing"; +import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing"; import { appendToURLPath, appendToURLQuery, @@ -700,13 +700,13 @@ export class ContainerClient extends StorageClient { * ``` */ public async create(options: ContainerCreateOptions = {}): Promise { - const { span, spanOptions } = createSpan("ContainerClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("ContainerClient-create", options); try { // Spread operator in destructuring assignments, // this will filter out unwanted properties from the response object into result object return await this.containerContext.create({ ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -729,15 +729,9 @@ export class ContainerClient extends StorageClient { public async createIfNotExists( options: ContainerCreateOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ContainerClient-createIfNotExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ContainerClient-createIfNotExists", options); try { - const res = await this.create({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.create(updatedOptions); return { succeeded: true, ...res, @@ -776,11 +770,11 @@ export class ContainerClient extends StorageClient { * @param options - */ public async exists(options: ContainerExistsOptions = {}): Promise { - const { span, spanOptions } = createSpan("ContainerClient-exists", options.tracingOptions); + const { span, updatedOptions } = createSpan("ContainerClient-exists", options); try { await this.getProperties({ abortSignal: options.abortSignal, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); return true; } catch (e) { @@ -876,15 +870,12 @@ export class ContainerClient extends StorageClient { options.conditions = {}; } - const { span, spanOptions } = createSpan( - "ContainerClient-getProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ContainerClient-getProperties", options); try { return await this.containerContext.getProperties({ abortSignal: options.abortSignal, ...options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -911,13 +902,13 @@ export class ContainerClient extends StorageClient { options.conditions = {}; } - const { span, spanOptions } = createSpan("ContainerClient-delete", options.tracingOptions); + const { span, updatedOptions } = createSpan("ContainerClient-delete", options); try { return await this.containerContext.deleteMethod({ abortSignal: options.abortSignal, leaseAccessConditions: options.conditions, modifiedAccessConditions: options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -940,16 +931,10 @@ export class ContainerClient extends StorageClient { public async deleteIfExists( options: ContainerDeleteMethodOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ContainerClient-deleteIfExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ContainerClient-deleteIfExists", options); try { - const res = await this.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.delete(updatedOptions); return { succeeded: true, ...res, @@ -1003,7 +988,7 @@ export class ContainerClient extends StorageClient { ); } - const { span, spanOptions } = createSpan("ContainerClient-setMetadata", options.tracingOptions); + const { span, updatedOptions } = createSpan("ContainerClient-setMetadata", options); try { return await this.containerContext.setMetadata({ @@ -1011,7 +996,7 @@ export class ContainerClient extends StorageClient { leaseAccessConditions: options.conditions, metadata, modifiedAccessConditions: options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1042,16 +1027,13 @@ export class ContainerClient extends StorageClient { options.conditions = {}; } - const { span, spanOptions } = createSpan( - "ContainerClient-getAccessPolicy", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ContainerClient-getAccessPolicy", options); try { const response = await this.containerContext.getAccessPolicy({ abortSignal: options.abortSignal, leaseAccessConditions: options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const res: ContainerGetAccessPolicyResponse = { @@ -1124,10 +1106,7 @@ export class ContainerClient extends StorageClient { options: ContainerSetAccessPolicyOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "ContainerClient-setAccessPolicy", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ContainerClient-setAccessPolicy", options); try { const acl: SignedIdentifierModel[] = []; for (const identifier of containerAcl || []) { @@ -1151,7 +1130,7 @@ export class ContainerClient extends StorageClient { containerAcl: acl, leaseAccessConditions: options.conditions, modifiedAccessConditions: options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1202,16 +1181,10 @@ export class ContainerClient extends StorageClient { contentLength: number, options: BlockBlobUploadOptions = {} ): Promise<{ blockBlobClient: BlockBlobClient; response: BlockBlobUploadResponse }> { - const { span, spanOptions } = createSpan( - "ContainerClient-uploadBlockBlob", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ContainerClient-uploadBlockBlob", options); try { const blockBlobClient = this.getBlockBlobClient(blobName); - const response = await blockBlobClient.upload(body, contentLength, { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const response = await blockBlobClient.upload(body, contentLength, updatedOptions); return { blockBlobClient, response @@ -1242,16 +1215,13 @@ export class ContainerClient extends StorageClient { blobName: string, options: ContainerDeleteBlobOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ContainerClient-deleteBlob", options.tracingOptions); + const { span, updatedOptions } = createSpan("ContainerClient-deleteBlob", options); try { let blobClient = this.getBlobClient(blobName); if (options.versionId) { blobClient = blobClient.withVersion(options.versionId); } - return await blobClient.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await blobClient.delete(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -1277,15 +1247,12 @@ export class ContainerClient extends StorageClient { marker?: string, options: ContainerListBlobsSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ContainerClient-listBlobFlatSegment", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ContainerClient-listBlobFlatSegment", options); try { const response = await this.containerContext.listBlobFlatSegment({ marker, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const wrappedResponse: ContainerListBlobFlatSegmentResponse = { ...response, @@ -1332,15 +1299,15 @@ export class ContainerClient extends StorageClient { marker?: string, options: ContainerListBlobsSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ContainerClient-listBlobHierarchySegment", - options.tracingOptions + options ); try { const response = await this.containerContext.listBlobHierarchySegment(delimiter, { marker, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const wrappedResponse: ContainerListBlobHierarchySegmentResponse = { ...response, @@ -1593,7 +1560,10 @@ export class ContainerClient extends StorageClient { const segment = listBlobsHierarchySegmentResponse.segment; if (segment.blobPrefixes) { for (const prefix of segment.blobPrefixes) { - yield { kind: "prefix", ...prefix }; + yield { + kind: "prefix", + ...prefix + }; } } for (const blob of segment.blobItems) { diff --git a/sdk/storage/storage-blob/src/utils/tracing.ts b/sdk/storage/storage-blob/src/utils/tracing.ts index b84e961499f0..ff06164466aa 100644 --- a/sdk/storage/storage-blob/src/utils/tracing.ts +++ b/sdk/storage/storage-blob/src/utils/tracing.ts @@ -1,41 +1,29 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer, OperationTracingOptions, SpanOptions } from "@azure/core-tracing"; -import { Span, SpanOptions as OTSpanOptions, SpanKind } from "@opentelemetry/api"; +import { OperationOptions, RequestOptionsBase } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - tracingOptions: OperationTracingOptions = {} -): { span: Span; spanOptions: SpanOptions } { - const tracer = getTracer(); - const spanOptions: OTSpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Storage.Blob.${operationName}`, spanOptions); - span.setAttribute("az.namespace", "Microsoft.Storage"); - - let newOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Storage" - } - }; - } +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Storage.Blob", + namespace: "Microsoft.Storage" +}); +/** + * @internal + * + * Adapt the tracing options from OperationOptions to what they need to be for + * RequestOptionsBase (when we update to later OpenTelemetry versions this is now + * two separate fields, not just one). + */ +export function convertTracingToRequestOptionsBase( + options?: OperationOptions +): Pick { return { - span, - spanOptions: newOptions + spanOptions: options?.tracingOptions?.spanOptions }; } diff --git a/sdk/storage/storage-file-datalake/package.json b/sdk/storage/storage-file-datalake/package.json index 40dfcb5906d0..4c38f64ecf52 100644 --- a/sdk/storage/storage-file-datalake/package.json +++ b/sdk/storage/storage-file-datalake/package.json @@ -101,7 +101,7 @@ "@azure/abort-controller": "^1.0.0", "@azure/core-http": "^1.2.0", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@azure/storage-blob": "^12.5.0-beta.1", "events": "^3.0.0", diff --git a/sdk/storage/storage-file-datalake/src/DataLakeFileSystemClient.ts b/sdk/storage/storage-file-datalake/src/DataLakeFileSystemClient.ts index 5220acfb6546..5b475d87ce48 100644 --- a/sdk/storage/storage-file-datalake/src/DataLakeFileSystemClient.ts +++ b/sdk/storage/storage-file-datalake/src/DataLakeFileSystemClient.ts @@ -38,7 +38,7 @@ import { import { newPipeline, Pipeline, StoragePipelineOptions } from "./Pipeline"; import { StorageClient } from "./StorageClient"; import { toContainerPublicAccessType, toPublicAccessType, toPermissions } from "./transforms"; -import { createSpan } from "./utils/tracing"; +import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing"; import { appendToURLPath, appendToURLQuery } from "./utils/utils.common"; import { DataLakeFileClient, DataLakeDirectoryClient } from "./clients"; import { generateDataLakeSASQueryParameters } from "./sas/DataLakeSASSignatureValues"; @@ -162,15 +162,12 @@ export class DataLakeFileSystemClient extends StorageClient { * @param options - Optional. Options when creating file system. */ public async create(options: FileSystemCreateOptions = {}): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileSystemClient-create", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileSystemClient-create", options); try { return await this.blobContainerClient.create({ ...options, access: toContainerPublicAccessType(options.access), - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -194,15 +191,15 @@ export class DataLakeFileSystemClient extends StorageClient { public async createIfNotExists( options: FileSystemCreateOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakeFileSystemClient-createIfNotExists", - options.tracingOptions + options ); try { return await this.blobContainerClient.createIfNotExists({ ...options, access: toContainerPublicAccessType(options.access), - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -225,15 +222,9 @@ export class DataLakeFileSystemClient extends StorageClient { * @param options - */ public async exists(options: FileSystemExistsOptions = {}): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileSystemClient-exists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileSystemClient-exists", options); try { - return await this.blobContainerClient.exists({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await this.blobContainerClient.exists(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -253,14 +244,11 @@ export class DataLakeFileSystemClient extends StorageClient { * @param options - Optional. Options when deleting file system. */ public async delete(options: FileSystemDeleteOptions = {}): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileSystemClient-delete", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileSystemClient-delete", options); try { return await this.blobContainerClient.delete({ ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -283,15 +271,9 @@ export class DataLakeFileSystemClient extends StorageClient { public async deleteIfExists( options: FileSystemDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileSystemClient-deleteIfExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileSystemClient-deleteIfExists", options); try { - return await this.blobContainerClient.deleteIfExists({ - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + return await this.blobContainerClient.deleteIfExists(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -319,14 +301,11 @@ export class DataLakeFileSystemClient extends StorageClient { public async getProperties( options: FileSystemGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileSystemClient-getProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileSystemClient-getProperties", options); try { const rawResponse = await this.blobContainerClient.getProperties({ ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // Transfer and rename blobPublicAccess to publicAccess @@ -366,14 +345,11 @@ export class DataLakeFileSystemClient extends StorageClient { metadata?: Metadata, options: FileSystemSetMetadataOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileSystemClient-setMetadata", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileSystemClient-setMetadata", options); try { return await this.blobContainerClient.setMetadata(metadata, { ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -400,14 +376,14 @@ export class DataLakeFileSystemClient extends StorageClient { public async getAccessPolicy( options: FileSystemGetAccessPolicyOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakeFileSystemClient-getAccessPolicy", - options.tracingOptions + options ); try { const rawResponse = await this.blobContainerClient.getAccessPolicy({ ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // Transfer and rename blobPublicAccess to publicAccess @@ -450,9 +426,9 @@ export class DataLakeFileSystemClient extends StorageClient { fileSystemAcl?: SignedIdentifier[], options: FileSystemSetAccessPolicyOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakeFileSystemClient-setAccessPolicy", - options.tracingOptions + options ); try { return await this.blobContainerClient.setAccessPolicy( @@ -460,7 +436,7 @@ export class DataLakeFileSystemClient extends StorageClient { fileSystemAcl, { ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); } catch (e) { @@ -591,16 +567,16 @@ export class DataLakeFileSystemClient extends StorageClient { continuation?: string, options: ListPathsSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakeFileSystemClient-listPathsSegment", - options.tracingOptions + options ); try { const rawResponse = await this.fileSystemContext.listPaths(options.recursive || false, { continuation, ...options, upn: options.userPrincipalName, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const response = rawResponse as FileSystemListPathsResponse; diff --git a/sdk/storage/storage-file-datalake/src/DataLakeLeaseClient.ts b/sdk/storage/storage-file-datalake/src/DataLakeLeaseClient.ts index 2d025e078c94..1df0646b1cb1 100644 --- a/sdk/storage/storage-file-datalake/src/DataLakeLeaseClient.ts +++ b/sdk/storage/storage-file-datalake/src/DataLakeLeaseClient.ts @@ -22,18 +22,9 @@ export class DataLakeLeaseClient { options: LeaseOperationOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakeLeaseClient-acquireLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeLeaseClient-acquireLease", options); try { - return await this.client.acquireLease(duration, { - ...options, - tracingOptions: { - ...options.tracingOptions, - spanOptions - } - }); + return await this.client.acquireLease(duration, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -50,18 +41,9 @@ export class DataLakeLeaseClient { options: LeaseOperationOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakeLeaseClient-changeLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeLeaseClient-changeLease", options); try { - return await this.client.changeLease(proposedLeaseId, { - ...options, - tracingOptions: { - ...options.tracingOptions, - spanOptions - } - }); + return await this.client.changeLease(proposedLeaseId, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -75,18 +57,9 @@ export class DataLakeLeaseClient { public async releaseLease(options: LeaseOperationOptions = {}): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakeLeaseClient-releaseLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeLeaseClient-releaseLease", options); try { - return await this.client.releaseLease({ - ...options, - tracingOptions: { - ...options.tracingOptions, - spanOptions - } - }); + return await this.client.releaseLease(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -100,18 +73,9 @@ export class DataLakeLeaseClient { public async renewLease(options: LeaseOperationOptions = {}): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakeLeaseClient-renewLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeLeaseClient-renewLease", options); try { - return await this.client.renewLease({ - ...options, - tracingOptions: { - ...options.tracingOptions, - spanOptions - } - }); + return await this.client.renewLease(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -128,18 +92,9 @@ export class DataLakeLeaseClient { options: LeaseOperationOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakeLeaseClient-renewLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeLeaseClient-renewLease", options); try { - return await this.client.breakLease(breakPeriod, { - ...options, - tracingOptions: { - ...options.tracingOptions, - spanOptions - } - }); + return await this.client.breakLease(breakPeriod, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, diff --git a/sdk/storage/storage-file-datalake/src/DataLakeServiceClient.ts b/sdk/storage/storage-file-datalake/src/DataLakeServiceClient.ts index 4473a042cb0e..3e7b88ebd39a 100644 --- a/sdk/storage/storage-file-datalake/src/DataLakeServiceClient.ts +++ b/sdk/storage/storage-file-datalake/src/DataLakeServiceClient.ts @@ -187,18 +187,12 @@ export class DataLakeServiceClient extends StorageClient { expiresOn: Date, options: ServiceGetUserDelegationKeyOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakeServiceClient-getUserDelegationKey", - options.tracingOptions + options ); try { - return await this.blobServiceClient.getUserDelegationKey(startsOn, expiresOn, { - ...options, - tracingOptions: { - ...options.tracingOptions, - spanOptions - } - }); + return await this.blobServiceClient.getUserDelegationKey(startsOn, expiresOn, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -360,19 +354,13 @@ export class DataLakeServiceClient extends StorageClient { fileSystemClient: DataLakeFileSystemClient; fileSystemRenameResponse: FileSystemRenameResponse; }> { - const { span, spanOptions } = createSpan( - "DataLakeServiceClient-renameFileSystem", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeServiceClient-renameFileSystem", options); try { // const res = await this.blobServiceClient.renameContainer( const res = await this.blobServiceClient["renameContainer"]( sourceFileSystemName, destinationFileSystemName, - { - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - } + updatedOptions ); const fileSystemClient = this.getFileSystemClient(destinationFileSystemName); @@ -407,9 +395,9 @@ export class DataLakeServiceClient extends StorageClient { fileSystemClient: DataLakeFileSystemClient; fileSystemUndeleteResponse: FileSystemUndeleteResponse; }> { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakeServiceClient-undeleteFileSystem", - options.tracingOptions + options ); try { const res = await this.blobServiceClient.undeleteContainer( @@ -418,7 +406,7 @@ export class DataLakeServiceClient extends StorageClient { { ...options, destinationContainerName: options.destinationFileSystemName, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions } ); diff --git a/sdk/storage/storage-file-datalake/src/clients.ts b/sdk/storage/storage-file-datalake/src/clients.ts index e9ff8b5fb3b5..2aa1e92c62b9 100644 --- a/sdk/storage/storage-file-datalake/src/clients.ts +++ b/sdk/storage/storage-file-datalake/src/clients.ts @@ -88,7 +88,7 @@ import { FILE_UPLOAD_MAX_CHUNK_SIZE } from "./utils/constants"; import { DataLakeAclChangeFailedError } from "./utils/DataLakeAclChangeFailedError"; -import { createSpan } from "./utils/tracing"; +import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing"; import { appendToURLPath, appendToURLQuery, @@ -134,9 +134,9 @@ export class DataLakePathClient extends StorageClient { throw RangeError(`Options batchSize must be larger than 0.`); } - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( `DataLakePathClient-setAccessControlRecursiveInternal`, - options.tracingOptions + options ); const result: PathChangeAccessControlRecursiveResponse = { @@ -161,7 +161,7 @@ export class DataLakePathClient extends StorageClient { maxRecords: options.batchSize, continuation: continuationToken, forceFlag: options.continueOnFailure, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { throw new DataLakeAclChangeFailedError(e, continuationToken); @@ -316,7 +316,7 @@ export class DataLakePathClient extends StorageClient { options: PathCreateOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("DataLakePathClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakePathClient-create", options); try { return await this.pathContext.create({ ...options, @@ -324,7 +324,7 @@ export class DataLakePathClient extends StorageClient { leaseAccessConditions: options.conditions, modifiedAccessConditions: options.conditions, properties: toProperties(options.metadata), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -349,16 +349,13 @@ export class DataLakePathClient extends StorageClient { resourceType: PathResourceTypeModel, options: PathCreateIfNotExistsOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakePathClient-createIfNotExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakePathClient-createIfNotExists", options); try { const conditions = { ifNoneMatch: ETagAny }; const res = await this.create(resourceType, { ...options, conditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); return { succeeded: true, @@ -396,12 +393,9 @@ export class DataLakePathClient extends StorageClient { * @param options - options to Exists operation. */ public async exists(options: PathExistsOptions = {}): Promise { - const { span, spanOptions } = createSpan("DataLakeFileClient-exists", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakeFileClient-exists", options); try { - return await this.blobClient.exists({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await this.blobClient.exists(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -426,7 +420,7 @@ export class DataLakePathClient extends StorageClient { options: PathDeleteOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("DataLakePathClient-delete", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakePathClient-delete", options); try { let continuation; let response; @@ -438,7 +432,7 @@ export class DataLakePathClient extends StorageClient { recursive, leaseAccessConditions: options.conditions, modifiedAccessConditions: options.conditions, - spanOptions, + ...convertTracingToRequestOptionsBase(updatedOptions), abortSignal: options.abortSignal }); continuation = response.continuation; @@ -469,15 +463,9 @@ export class DataLakePathClient extends StorageClient { options: PathDeleteOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakePathClient-deleteIfExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakePathClient-deleteIfExists", options); try { - const res = await this.delete(recursive, { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.delete(recursive, updatedOptions); return { succeeded: true, ...res @@ -515,17 +503,14 @@ export class DataLakePathClient extends StorageClient { options: PathGetAccessControlOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakePathClient-getAccessControl", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakePathClient-getAccessControl", options); try { const response = await this.pathContext.getProperties({ action: "getAccessControl", upn: options.userPrincipalName, leaseAccessConditions: options.conditions, modifiedAccessConditions: options.conditions, - spanOptions, + ...convertTracingToRequestOptionsBase(updatedOptions), abortSignal: options.abortSignal }); return toPathGetAccessControlResponse(response); @@ -553,17 +538,14 @@ export class DataLakePathClient extends StorageClient { options: PathSetAccessControlOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakePathClient-setAccessControl", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakePathClient-setAccessControl", options); try { return await this.pathContext.setAccessControl({ ...options, acl: toAclString(acl), leaseAccessConditions: options.conditions, modifiedAccessConditions: options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -588,15 +570,12 @@ export class DataLakePathClient extends StorageClient { acl: PathAccessControlItem[], options: PathChangeAccessControlRecursiveOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakePathClient-setAccessControlRecursive", - options.tracingOptions + options ); try { - return this.setAccessControlRecursiveInternal("set", acl, { - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + return this.setAccessControlRecursiveInternal("set", acl, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -620,15 +599,12 @@ export class DataLakePathClient extends StorageClient { acl: PathAccessControlItem[], options: PathChangeAccessControlRecursiveOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakePathClient-updateAccessControlRecursive", - options.tracingOptions + options ); try { - return this.setAccessControlRecursiveInternal("modify", acl, { - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + return this.setAccessControlRecursiveInternal("modify", acl, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -652,15 +628,12 @@ export class DataLakePathClient extends StorageClient { acl: RemovePathAccessControlItem[], options: PathChangeAccessControlRecursiveOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakePathClient-removeAccessControlRecursive", - options.tracingOptions + options ); try { - return this.setAccessControlRecursiveInternal("remove", acl, { - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + return this.setAccessControlRecursiveInternal("remove", acl, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -685,17 +658,14 @@ export class DataLakePathClient extends StorageClient { options: PathSetPermissionsOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakePathClient-setPermissions", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakePathClient-setPermissions", options); try { return await this.pathContext.setAccessControl({ ...options, permissions: toPermissionsString(permissions), leaseAccessConditions: options.conditions, modifiedAccessConditions: options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -724,15 +694,12 @@ export class DataLakePathClient extends StorageClient { public async getProperties( options: PathGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakePathClient-getProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakePathClient-getProperties", options); try { return await this.blobClient.getProperties({ ...options, customerProvidedKey: undefined, // Doesn't support customer provided key in data lake package yet - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -759,10 +726,7 @@ export class DataLakePathClient extends StorageClient { httpHeaders: PathHttpHeaders, options: PathSetHttpHeadersOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakePathClient-setHttpHeaders", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakePathClient-setHttpHeaders", options); try { return await this.blobClient.setHTTPHeaders( { @@ -773,10 +737,7 @@ export class DataLakePathClient extends StorageClient { blobContentLanguage: httpHeaders.contentLanguage, blobContentDisposition: httpHeaders.contentDisposition }, - { - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - } + updatedOptions ); } catch (e) { span.setStatus({ @@ -805,15 +766,12 @@ export class DataLakePathClient extends StorageClient { metadata?: Metadata, options: PathSetMetadataOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakePathClient-setMetadata", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakePathClient-setMetadata", options); try { return await this.blobClient.setMetadata(metadata, { ...options, customerProvidedKey: undefined, // Doesn't support customer provided key in data lake package yet - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -872,7 +830,7 @@ export class DataLakePathClient extends StorageClient { options.conditions = options.conditions || {}; options.destinationConditions = options.destinationConditions || {}; - const { span, spanOptions } = createSpan("DataLakePathClient-move", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakePathClient-move", options); const renameSource = getURLPathAndQuery(this.dfsEndpointUrl); @@ -904,7 +862,7 @@ export class DataLakePathClient extends StorageClient { sourceIfUnmodifiedSince: options.conditions.ifUnmodifiedSince }, modifiedAccessConditions: options.destinationConditions, - spanOptions, + ...convertTracingToRequestOptionsBase(updatedOptions), abortSignal: options.abortSignal }); } catch (e) { @@ -962,16 +920,13 @@ export class DataLakeDirectoryClient extends DataLakePathClient { options = resourceTypeOrOptions || {}; options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan( - "DataLakeDirectoryClient-create", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeDirectoryClient-create", options); try { return await super.create("directory", { ...options, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); } catch (e) { @@ -1023,16 +978,16 @@ export class DataLakeDirectoryClient extends DataLakePathClient { options = resourceTypeOrOptions || {}; } - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "DataLakeDirectoryClient-createIfNotExists", - options.tracingOptions + options ); try { return await super.createIfNotExists("directory", { ...options, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); } catch (e) { @@ -1217,13 +1172,13 @@ export class DataLakeFileClient extends DataLakePathClient { options = resourceTypeOrOptions || {}; options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("DataLakeFileClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakeFileClient-create", options); try { return await super.create("file", { ...options, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); } catch (e) { @@ -1275,16 +1230,13 @@ export class DataLakeFileClient extends DataLakePathClient { options = resourceTypeOrOptions || {}; } - const { span, spanOptions } = createSpan( - "DataLakeFileClient-createIfNotExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileClient-createIfNotExists", options); try { return await super.createIfNotExists("file", { ...options, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); } catch (e) { @@ -1357,12 +1309,13 @@ export class DataLakeFileClient extends DataLakePathClient { count?: number, options: FileReadOptions = {} ): Promise { - const { span, spanOptions } = createSpan("DataLakeFileClient-read", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakeFileClient-read", options); try { - const rawResponse = await this.blockBlobClientInternal.download(offset, count, { - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + const rawResponse = await this.blockBlobClientInternal.download( + offset, + count, + updatedOptions + ); const response = rawResponse as FileReadResponse; if (!isNode && !response.contentAsBlob) { @@ -1404,7 +1357,7 @@ export class DataLakeFileClient extends DataLakePathClient { options: FileAppendOptions = {} ): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("DataLakeFileClient-append", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakeFileClient-append", options); try { return await this.pathContextInternal.appendData(body, { pathHttpHeaders: { @@ -1415,7 +1368,7 @@ export class DataLakeFileClient extends DataLakePathClient { contentLength: length, leaseAccessConditions: options.conditions, onUploadProgress: options.onProgress, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1442,7 +1395,7 @@ export class DataLakeFileClient extends DataLakePathClient { */ public async flush(position: number, options: FileFlushOptions = {}): Promise { options.conditions = options.conditions || {}; - const { span, spanOptions } = createSpan("DataLakeFileClient-flush", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakeFileClient-flush", options); try { return await this.pathContextInternal.flushData({ ...options, @@ -1450,7 +1403,7 @@ export class DataLakeFileClient extends DataLakePathClient { contentLength: 0, leaseAccessConditions: options.conditions, modifiedAccessConditions: options.conditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1477,10 +1430,7 @@ export class DataLakeFileClient extends DataLakePathClient { filePath: string, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileClient-uploadFile", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileClient-uploadFile", options); try { const size = (await fsStat(filePath)).size; return await this.uploadSeekableInternal( @@ -1493,7 +1443,7 @@ export class DataLakeFileClient extends DataLakePathClient { }); }, size, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + updatedOptions ); } catch (e) { span.setStatus({ @@ -1516,7 +1466,7 @@ export class DataLakeFileClient extends DataLakePathClient { data: Buffer | Blob | ArrayBuffer | ArrayBufferView, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan("DataLakeFileClient-upload", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakeFileClient-upload", options); try { if (isNode) { let buffer: Buffer; @@ -1532,17 +1482,14 @@ export class DataLakeFileClient extends DataLakePathClient { return this.uploadSeekableInternal( (offset: number, size: number): Buffer => buffer.slice(offset, offset + size), buffer.length, - { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - } + updatedOptions ); } else { const browserBlob = new Blob([data]); return this.uploadSeekableInternal( (offset: number, size: number): Blob => browserBlob.slice(offset, offset + size), browserBlob.size, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + updatedOptions ); } } catch (e) { @@ -1561,10 +1508,7 @@ export class DataLakeFileClient extends DataLakePathClient { size: number, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileClient-uploadData", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileClient-uploadData", options); try { if (size > FILE_MAX_SIZE_BYTES) { throw new RangeError(`size must be <= ${FILE_MAX_SIZE_BYTES}.`); @@ -1578,7 +1522,7 @@ export class DataLakeFileClient extends DataLakePathClient { umask: options.umask, conditions: options.conditions, pathHttpHeaders: options.pathHttpHeaders, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // append() with empty data would return error, so do not continue if (size === 0) { @@ -1625,7 +1569,7 @@ export class DataLakeFileClient extends DataLakePathClient { abortSignal: options.abortSignal, conditions: options.conditions, onProgress: options.onProgress, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); return await this.flush(size, { @@ -1633,7 +1577,7 @@ export class DataLakeFileClient extends DataLakePathClient { conditions: options.conditions, close: options.close, pathHttpHeaders: options.pathHttpHeaders, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } @@ -1657,7 +1601,7 @@ export class DataLakeFileClient extends DataLakePathClient { await this.append(bodyFactory(start, contentLength), start, contentLength, { abortSignal: options.abortSignal, conditions: options.conditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); transferProgress += contentLength; @@ -1674,7 +1618,7 @@ export class DataLakeFileClient extends DataLakePathClient { conditions: options.conditions, close: options.close, pathHttpHeaders: options.pathHttpHeaders, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -1706,10 +1650,7 @@ export class DataLakeFileClient extends DataLakePathClient { stream: Readable, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileClient-uploadStream", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileClient-uploadStream", options); try { // Create the file await this.create({ @@ -1719,7 +1660,7 @@ export class DataLakeFileClient extends DataLakePathClient { umask: options.umask, conditions: options.conditions, pathHttpHeaders: options.pathHttpHeaders, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // After the File is Create, Lease ID is the only valid request parameter. @@ -1747,7 +1688,7 @@ export class DataLakeFileClient extends DataLakePathClient { await this.append(body, offset!, length, { abortSignal: options.abortSignal, conditions: options.conditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // Update progress after block is successfully uploaded to server, in case of block trying @@ -1769,7 +1710,7 @@ export class DataLakeFileClient extends DataLakePathClient { conditions: options.conditions, close: options.close, pathHttpHeaders: options.pathHttpHeaders, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -1843,24 +1784,21 @@ export class DataLakeFileClient extends DataLakePathClient { count = typeof offsetOrCount === "number" ? offsetOrCount : 0; options = (countOrOptions as FileReadToBufferOptions) || {}; } - const { span, spanOptions } = createSpan( - "DataLakeFileClient-readToBuffer", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileClient-readToBuffer", options); try { if (buffer) { return await this.blockBlobClientInternal.downloadToBuffer(buffer, offset, count, { ...options, maxRetryRequestsPerBlock: options.maxRetryRequestsPerChunk, blockSize: options.chunkSize, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } else { return await this.blockBlobClientInternal.downloadToBuffer(offset, count, { ...options, maxRetryRequestsPerBlock: options.maxRetryRequestsPerChunk, blockSize: options.chunkSize, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } } catch (e) { @@ -1896,15 +1834,14 @@ export class DataLakeFileClient extends DataLakePathClient { count?: number, options: FileReadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileClient-readToFile", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileClient-readToFile", options); try { - return await this.blockBlobClientInternal.downloadToFile(filePath, offset, count, { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await this.blockBlobClientInternal.downloadToFile( + filePath, + offset, + count, + updatedOptions + ); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -1945,13 +1882,10 @@ export class DataLakeFileClient extends DataLakePathClient { * @param options - */ public async query(query: string, options: FileQueryOptions = {}): Promise { - const { span, spanOptions } = createSpan("DataLakeFileClient-query", options.tracingOptions); + const { span, updatedOptions } = createSpan("DataLakeFileClient-query", options); try { - const rawResponse = await this.blockBlobClientInternal.query(query, { - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + const rawResponse = await this.blockBlobClientInternal.query(query, updatedOptions); const response = rawResponse as FileReadResponse; if (!isNode && !response.contentAsBlob) { response.contentAsBlob = rawResponse.blobBody; @@ -1983,10 +1917,7 @@ export class DataLakeFileClient extends DataLakePathClient { mode: FileExpiryMode, options: FileSetExpiryOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "DataLakeFileClient-setExpiry", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("DataLakeFileClient-setExpiry", options); try { let expiresOn: string | undefined = undefined; if (mode === "RelativeToNow" || mode === "RelativeToCreation") { @@ -2013,7 +1944,7 @@ export class DataLakeFileClient extends DataLakePathClient { const adaptedOptions = { ...options, expiresOn }; return await this.pathContextInternalToBlobEndpoint.setExpiry(mode, { ...adaptedOptions, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ diff --git a/sdk/storage/storage-file-datalake/src/utils/tracing.ts b/sdk/storage/storage-file-datalake/src/utils/tracing.ts index 138c20f51c86..19f15498e6ca 100644 --- a/sdk/storage/storage-file-datalake/src/utils/tracing.ts +++ b/sdk/storage/storage-file-datalake/src/utils/tracing.ts @@ -1,40 +1,29 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { Span, SpanKind, SpanOptions as OTSpanOptions } from "@opentelemetry/api"; -import { getTracer, SpanOptions, OperationTracingOptions } from "@azure/core-tracing"; + +import { OperationOptions, RequestOptionsBase } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - tracingOptions: OperationTracingOptions = {} -): { span: Span; spanOptions: SpanOptions } { - const tracer = getTracer(); - const spanOptions: OTSpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Storage.DataLake.${operationName}`, spanOptions); - span.setAttribute("az.namespace", "Microsoft.Storage"); - - let newOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Storage" - } - }; - } +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Storage.DataLake", + namespace: "Microsoft.Storage" +}); +/** + * @internal + * + * Adapt the tracing options from OperationOptions to what they need to be for + * RequestOptionsBase (when we update to later OpenTelemetry versions this is now + * two separate fields, not just one). + */ +export function convertTracingToRequestOptionsBase( + options?: OperationOptions +): Pick { return { - span, - spanOptions: newOptions + spanOptions: options?.tracingOptions?.spanOptions }; } diff --git a/sdk/storage/storage-file-share/package.json b/sdk/storage/storage-file-share/package.json index 772bf9c25f96..47d5c51ea781 100644 --- a/sdk/storage/storage-file-share/package.json +++ b/sdk/storage/storage-file-share/package.json @@ -113,7 +113,7 @@ "@azure/abort-controller": "^1.0.0", "@azure/core-http": "^1.2.0", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "events": "^3.0.0", diff --git a/sdk/storage/storage-file-share/src/Clients.ts b/sdk/storage/storage-file-share/src/Clients.ts index 07944212b84b..d5ed2701023b 100644 --- a/sdk/storage/storage-file-share/src/Clients.ts +++ b/sdk/storage/storage-file-share/src/Clients.ts @@ -72,7 +72,7 @@ import { import { Credential } from "./credentials/Credential"; import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential"; import { AnonymousCredential } from "./credentials/AnonymousCredential"; -import { createSpan } from "./utils/tracing"; +import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing"; import { StorageClient, CommonOptions } from "./StorageClient"; import "@azure/core-paging"; import { PageSettings, PagedAsyncIterableIterator } from "@azure/core-paging"; @@ -645,12 +645,12 @@ export class ShareClient extends StorageClient { * @returns Response data for the Share Create operation. */ public async create(options: ShareCreateOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-create", options); try { return await this.context.create({ ...options, enabledProtocols: toShareProtocolsString(options.protocols), - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -673,15 +673,9 @@ export class ShareClient extends StorageClient { public async createIfNotExists( options: ShareCreateOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareClient-createIfNotExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareClient-createIfNotExists", options); try { - const res = await this.create({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.create(updatedOptions); return { succeeded: true, ...res @@ -746,13 +740,10 @@ export class ShareClient extends StorageClient { directoryClient: ShareDirectoryClient; directoryCreateResponse: DirectoryCreateResponse; }> { - const { span, spanOptions } = createSpan("ShareClient-createDirectory", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-createDirectory", options); try { const directoryClient = this.getDirectoryClient(directoryName); - const directoryCreateResponse = await directoryClient.create({ - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + const directoryCreateResponse = await directoryClient.create(updatedOptions); return { directoryClient, directoryCreateResponse @@ -781,13 +772,10 @@ export class ShareClient extends StorageClient { directoryName: string, options: DirectoryDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-deleteDirectory", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-deleteDirectory", options); try { const directoryClient = this.getDirectoryClient(directoryName); - return await directoryClient.delete({ - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + return await directoryClient.delete(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -814,14 +802,11 @@ export class ShareClient extends StorageClient { size: number, options: FileCreateOptions = {} ): Promise<{ fileClient: ShareFileClient; fileCreateResponse: FileCreateResponse }> { - const { span, spanOptions } = createSpan("ShareClient-createFile", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-createFile", options); try { const directoryClient = this.rootDirectoryClient; const fileClient = directoryClient.getFileClient(fileName); - const fileCreateResponse = await fileClient.create(size, { - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + const fileCreateResponse = await fileClient.create(size, updatedOptions); return { fileClient, fileCreateResponse @@ -861,14 +846,11 @@ export class ShareClient extends StorageClient { fileName: string, options: FileDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-deleteFile", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-deleteFile", options); try { const directoryClient = this.rootDirectoryClient; const fileClient = directoryClient.getFileClient(fileName); - return await fileClient.delete({ - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + return await fileClient.delete(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -890,12 +872,9 @@ export class ShareClient extends StorageClient { * @param options - options to Exists operation. */ public async exists(options: ShareExistsOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareClient-exists", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-exists", options); try { - await this.getProperties({ - ...options, - tracingOptions: { ...options.tracingOptions, spanOptions } - }); + await this.getProperties(updatedOptions); return true; } catch (e) { if (e.statusCode === 404) { @@ -930,11 +909,11 @@ export class ShareClient extends StorageClient { public async getProperties( options: ShareGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-getProperties", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-getProperties", options); try { const res = await this.context.getProperties({ ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); // parse protocols @@ -961,11 +940,11 @@ export class ShareClient extends StorageClient { * @returns Response data for the Share Delete operation. */ public async delete(options: ShareDeleteMethodOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareClient-delete", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-delete", options); try { return await this.context.deleteMethod({ ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -988,12 +967,9 @@ export class ShareClient extends StorageClient { public async deleteIfExists( options: ShareDeleteMethodOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-deleteIfExists", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-deleteIfExists", options); try { - const res = await this.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.delete(updatedOptions); return { succeeded: true, ...res @@ -1035,12 +1011,12 @@ export class ShareClient extends StorageClient { metadata?: Metadata, options: ShareSetMetadataOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-setMetadata", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-setMetadata", options); try { return await this.context.setMetadata({ ...options, metadata, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1068,11 +1044,11 @@ export class ShareClient extends StorageClient { public async getAccessPolicy( options: ShareGetAccessPolicyOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-getAccessPolicy", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-getAccessPolicy", options); try { const response = await this.context.getAccessPolicy({ ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const res: ShareGetAccessPolicyResponse = { @@ -1140,7 +1116,7 @@ export class ShareClient extends StorageClient { shareAcl?: SignedIdentifier[], options: ShareSetAccessPolicyOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-setAccessPolicy", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-setAccessPolicy", options); try { const acl: SignedIdentifierModel[] = []; for (const identifier of shareAcl || []) { @@ -1161,7 +1137,7 @@ export class ShareClient extends StorageClient { return await this.context.setAccessPolicy({ ...options, shareAcl: acl, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1183,12 +1159,12 @@ export class ShareClient extends StorageClient { public async createSnapshot( options: ShareCreateSnapshotOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-createSnapshot", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-createSnapshot", options); try { return await this.context.createSnapshot({ abortSignal: options.abortSignal, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1214,12 +1190,12 @@ export class ShareClient extends StorageClient { quotaInGB: number, options: ShareSetQuotaOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-setQuota", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-setQuota", options); try { return await this.context.setProperties({ ...options, quota: quotaInGB, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1241,12 +1217,12 @@ export class ShareClient extends StorageClient { public async setProperties( options: ShareSetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-setProperties", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-setProperties", options); try { return await this.context.setProperties({ ...options, quota: options.quotaInGB, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -1268,11 +1244,11 @@ export class ShareClient extends StorageClient { public async getStatistics( options: ShareGetStatisticsOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-getStatistics", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-getStatistics", options); try { const response = await this.context.getStatistics({ ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const GBBytes = 1024 * 1024 * 1024; @@ -1300,10 +1276,7 @@ export class ShareClient extends StorageClient { filePermission: string, options: ShareCreatePermissionOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareClient-createPermission", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareClient-createPermission", options); try { return await this.context.createPermission( { @@ -1311,7 +1284,7 @@ export class ShareClient extends StorageClient { }, { abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -1337,11 +1310,11 @@ export class ShareClient extends StorageClient { filePermissionKey: string, options: ShareGetPermissionOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareClient-getPermission", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareClient-getPermission", options); try { return await this.context.getPermission(filePermissionKey, { aborterSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -1729,7 +1702,7 @@ export class ShareDirectoryClient extends StorageClient { * @returns Response data for the Directory operation. */ public async create(options: DirectoryCreateOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareDirectoryClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-create", options); try { if (!options.fileAttributes) { options = validateAndSetDefaultsForFileAndDirectoryCreateCommonOptions(options); @@ -1748,7 +1721,7 @@ export class ShareDirectoryClient extends StorageClient { metadata: options.metadata, filePermission: options.filePermission, filePermissionKey: options.filePermissionKey, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -1772,15 +1745,9 @@ export class ShareDirectoryClient extends StorageClient { public async createIfNotExists( options: DirectoryCreateOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-createIfNotExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-createIfNotExists", options); try { - const res = await this.create({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.create(updatedOptions); return { succeeded: true, ...res @@ -1817,10 +1784,7 @@ export class ShareDirectoryClient extends StorageClient { public async setProperties( properties: DirectoryProperties = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-setProperties", - properties.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-setProperties", properties); try { properties = validateAndSetDefaultsForFileAndDirectorySetPropertiesCommonOptions(properties); @@ -1832,7 +1796,7 @@ export class ShareDirectoryClient extends StorageClient { abortSignal: properties.abortSignal, filePermission: properties.filePermission, filePermissionKey: properties.filePermissionKey, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -1882,16 +1846,10 @@ export class ShareDirectoryClient extends StorageClient { directoryClient: ShareDirectoryClient; directoryCreateResponse: DirectoryCreateResponse; }> { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-createSubdirectory", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-createSubdirectory", options); try { const directoryClient = this.getDirectoryClient(directoryName); - const directoryCreateResponse = await directoryClient.create({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const directoryCreateResponse = await directoryClient.create(updatedOptions); return { directoryClient, directoryCreateResponse @@ -1920,16 +1878,10 @@ export class ShareDirectoryClient extends StorageClient { directoryName: string, options: DirectoryDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-deleteSubdirectory", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-deleteSubdirectory", options); try { const directoryClient = this.getDirectoryClient(directoryName); - return await directoryClient.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await directoryClient.delete(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -1955,16 +1907,10 @@ export class ShareDirectoryClient extends StorageClient { size: number, options: FileCreateOptions = {} ): Promise<{ fileClient: ShareFileClient; fileCreateResponse: FileCreateResponse }> { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-createFile", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-createFile", options); try { const fileClient = this.getFileClient(fileName); - const fileCreateResponse = await fileClient.create(size, { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const fileCreateResponse = await fileClient.create(size, updatedOptions); return { fileClient, fileCreateResponse @@ -2002,16 +1948,10 @@ export class ShareDirectoryClient extends StorageClient { fileName: string, options: FileDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-deleteFile", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-deleteFile", options); try { const fileClient = this.getFileClient(fileName); - return await fileClient.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await fileClient.delete(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -2060,13 +2000,13 @@ export class ShareDirectoryClient extends StorageClient { * @param options - options to Exists operation. */ public async exists(options: DirectoryExistsOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareDirectoryClient-exists", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-exists", options); try { await this.getProperties({ abortSignal: options.abortSignal, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); return true; @@ -2100,14 +2040,11 @@ export class ShareDirectoryClient extends StorageClient { public async getProperties( options: DirectoryGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-getProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-getProperties", options); try { return await this.context.getProperties({ abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -2129,11 +2066,11 @@ export class ShareDirectoryClient extends StorageClient { * @returns Response data for the Directory Delete operation. */ public async delete(options: DirectoryDeleteOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareDirectoryClient-delete", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-delete", options); try { return await this.context.deleteMethod({ abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -2156,15 +2093,9 @@ export class ShareDirectoryClient extends StorageClient { public async deleteIfExists( options: DirectoryDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-deleteIfExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-deleteIfExists", options); try { - const res = await this.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.delete(updatedOptions); return { succeeded: true, ...res @@ -2206,15 +2137,12 @@ export class ShareDirectoryClient extends StorageClient { metadata?: Metadata, options: DirectorySetMetadataOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-setMetadata", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-setMetadata", options); try { return await this.context.setMetadata({ abortSignal: options.abortSignal, metadata, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -2423,9 +2351,9 @@ export class ShareDirectoryClient extends StorageClient { marker?: string, options: DirectoryListFilesAndDirectoriesSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ShareDirectoryClient-listFilesAndDirectoriesSegment", - options.tracingOptions + options ); if (options.prefix === "") { @@ -2436,7 +2364,7 @@ export class ShareDirectoryClient extends StorageClient { return await this.context.listFilesAndDirectoriesSegment({ marker, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -2612,16 +2540,13 @@ export class ShareDirectoryClient extends StorageClient { marker?: string, options: DirectoryListHandlesSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-listHandlesSegment", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-listHandlesSegment", options); try { marker = marker === "" ? undefined : marker; const response = await this.context.listHandles({ marker, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); // TODO: Protocol layer issue that when handle list is in returned XML @@ -2656,16 +2581,16 @@ export class ShareDirectoryClient extends StorageClient { marker?: string, options: DirectoryForceCloseHandlesSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ShareDirectoryClient-forceCloseHandlesSegment", - options.tracingOptions + options ); try { marker = marker === "" ? undefined : marker; const rawResponse = await this.context.forceCloseHandles("*", { marker, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const response = rawResponse as DirectoryForceCloseHandlesResponse; response.closedHandlesCount = rawResponse.numberOfHandlesClosed || 0; @@ -2691,9 +2616,9 @@ export class ShareDirectoryClient extends StorageClient { public async forceCloseAllHandles( options: DirectoryForceCloseHandlesSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ShareDirectoryClient-forceCloseAllHandles", - options.tracingOptions + options ); try { let handlesClosed = 0; @@ -2703,7 +2628,7 @@ export class ShareDirectoryClient extends StorageClient { do { const response: DirectoryForceCloseHandlesResponse = await this.forceCloseHandlesSegment( marker, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + updatedOptions ); marker = response.marker; response.closedHandlesCount && (handlesClosed += response.closedHandlesCount); @@ -2736,10 +2661,7 @@ export class ShareDirectoryClient extends StorageClient { handleId: string, options: DirectoryForceCloseHandlesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareDirectoryClient-forceCloseHandle", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareDirectoryClient-forceCloseHandle", options); try { if (handleId === "*") { throw new RangeError( @@ -2749,7 +2671,7 @@ export class ShareDirectoryClient extends StorageClient { const rawResponse = await this.context.forceCloseHandles(handleId, { abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const response = rawResponse as DirectoryForceCloseHandlesResponse; response.closedHandlesCount = rawResponse.numberOfHandlesClosed || 0; @@ -3495,7 +3417,7 @@ export class ShareFileClient extends StorageClient { * ``` */ public async create(size: number, options: FileCreateOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-create", options); try { if (size < 0 || size > FILE_MAX_SIZE_BYTES) { throw new RangeError(`File size must >= 0 and < ${FILE_MAX_SIZE_BYTES}.`); @@ -3523,7 +3445,7 @@ export class ShareFileClient extends StorageClient { filePermission: options.filePermission, filePermissionKey: options.filePermissionKey, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -3603,7 +3525,7 @@ export class ShareFileClient extends StorageClient { count?: number, options: FileDownloadOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-download", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-download", options); try { if (options.rangeGetContentMD5 && offset === 0 && count === undefined) { throw new RangeError(`rangeGetContentMD5 only works with partial data downloading`); @@ -3616,7 +3538,7 @@ export class ShareFileClient extends StorageClient { range: downloadFullFile ? undefined : rangeToString({ offset, count }), rangeGetContentMD5: options.rangeGetContentMD5, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); // Return browser response immediately @@ -3660,7 +3582,7 @@ export class ShareFileClient extends StorageClient { abortSignal: options.abortSignal, leaseAccessConditions: options.leaseAccessConditions, ...updatedOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }) ).readableStreamBody!; }, @@ -3693,13 +3615,13 @@ export class ShareFileClient extends StorageClient { * @param options - options to Exists operation. */ public async exists(options: FileExistsOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-exists", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-exists", options); try { await this.getProperties({ abortSignal: options.abortSignal, tracingOptions: { ...options.tracingOptions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } }); return true; @@ -3732,15 +3654,12 @@ export class ShareFileClient extends StorageClient { public async getProperties( options: FileGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-getProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-getProperties", options); try { return this.context.getProperties({ abortSignal: options.abortSignal, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -3763,10 +3682,7 @@ export class ShareFileClient extends StorageClient { * existing values will be preserved. */ public async setProperties(properties: FileProperties = {}): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-setProperties", - properties.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-setProperties", properties); try { properties = validateAndSetDefaultsForFileAndDirectorySetPropertiesCommonOptions(properties); @@ -3782,7 +3698,7 @@ export class ShareFileClient extends StorageClient { filePermission: properties.filePermission, filePermissionKey: properties.filePermissionKey, leaseAccessConditions: properties.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -3814,12 +3730,12 @@ export class ShareFileClient extends StorageClient { * @returns Response data for the File Delete operation. */ public async delete(options: FileDeleteOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-delete", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-delete", options); try { return await this.context.deleteMethod({ abortSignal: options.abortSignal, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -3851,15 +3767,9 @@ export class ShareFileClient extends StorageClient { public async deleteIfExists( options: FileDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-deleteIfExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-deleteIfExists", options); try { - const res = await this.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.delete(updatedOptions); return { succeeded: true, ...res @@ -3905,10 +3815,7 @@ export class ShareFileClient extends StorageClient { fileHttpHeaders: FileHttpHeaders = {}, options: FileSetHttpHeadersOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-setHTTPHeaders", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-setHTTPHeaders", options); try { // FileAttributes, filePermission, createTime, lastWriteTime will all be preserved options = validateAndSetDefaultsForFileAndDirectorySetPropertiesCommonOptions(options); @@ -3922,7 +3829,7 @@ export class ShareFileClient extends StorageClient { filePermission: options.filePermission, filePermissionKey: options.filePermissionKey, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -3951,7 +3858,7 @@ export class ShareFileClient extends StorageClient { length: number, options: FileResizeOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-resize", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-resize", options); try { if (length < 0) { throw new RangeError(`Size cannot less than 0 when resizing file.`); @@ -3969,7 +3876,7 @@ export class ShareFileClient extends StorageClient { filePermission: options.filePermission, filePermissionKey: options.filePermissionKey, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -3998,13 +3905,13 @@ export class ShareFileClient extends StorageClient { metadata: Metadata = {}, options: FileSetMetadataOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-setMetadata", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-setMetadata", options); try { return await this.context.setMetadata({ abortSignal: options.abortSignal, metadata, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -4050,7 +3957,7 @@ export class ShareFileClient extends StorageClient { contentLength: number, options: FileUploadRangeOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-uploadRange", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-uploadRange", options); try { if (offset < 0) { throw new RangeError(`offset must be >= 0`); @@ -4073,7 +3980,7 @@ export class ShareFileClient extends StorageClient { contentMD5: options.contentMD5, onUploadProgress: options.onProgress, body: body, - spanOptions, + ...convertTracingToRequestOptionsBase(updatedOptions), leaseAccessConditions: options.leaseAccessConditions } ); @@ -4105,10 +4012,7 @@ export class ShareFileClient extends StorageClient { count: number, options: FileUploadRangeFromURLOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-uploadRangeFromURL", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-uploadRangeFromURL", options); try { if (sourceOffset < 0 || destOffset < 0) { throw new RangeError(`sourceOffset and destOffset must be >= 0`); @@ -4127,7 +4031,7 @@ export class ShareFileClient extends StorageClient { sourceRange: rangeToString({ offset: sourceOffset, count }), sourceModifiedAccessConditions: options.sourceConditions, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) } ); } catch (e) { @@ -4153,7 +4057,7 @@ export class ShareFileClient extends StorageClient { contentLength: number, options: FileClearRangeOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-clearRange", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-clearRange", options); try { if (offset < 0 || contentLength <= 0) { throw new RangeError(`offset must >= 0 and contentLength must be > 0`); @@ -4165,7 +4069,7 @@ export class ShareFileClient extends StorageClient { 0, { abortSignal: options.abortSignal, - spanOptions, + ...convertTracingToRequestOptionsBase(updatedOptions), leaseAccessConditions: options.leaseAccessConditions } ); @@ -4188,16 +4092,13 @@ export class ShareFileClient extends StorageClient { public async getRangeList( options: FileGetRangeListOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-getRangeList", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-getRangeList", options); try { const originalResponse = await this.context.getRangeList({ abortSignal: options.abortSignal, range: options.range ? rangeToString(options.range) : undefined, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); // Only returns ranges, ignoring clearRanges. @@ -4230,16 +4131,13 @@ export class ShareFileClient extends StorageClient { prevShareSnapshot: string, options: FileGetRangeListOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-getRangeListDiff", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-getRangeListDiff", options); try { return await this.context.getRangeList({ prevsharesnapshot: prevShareSnapshot, ...options, range: options.range ? rangeToString(options.range) : undefined, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -4268,10 +4166,7 @@ export class ShareFileClient extends StorageClient { copySource: string, options: FileStartCopyOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-startCopyFromURL", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-startCopyFromURL", options); try { return await this.context.startCopy(copySource, { abortSignal: options.abortSignal, @@ -4280,7 +4175,7 @@ export class ShareFileClient extends StorageClient { filePermission: options.filePermission, filePermissionKey: options.filePermissionKey, copyFileSmbInfo: options.copyFileSmbInfo, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -4305,15 +4200,12 @@ export class ShareFileClient extends StorageClient { copyId: string, options: FileAbortCopyFromURLOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-abortCopyFromURL", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-abortCopyFromURL", options); try { return await this.context.abortCopy(copyId, { abortSignal: options.abortSignal, leaseAccessConditions: options.leaseAccessConditions, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -4338,7 +4230,7 @@ export class ShareFileClient extends StorageClient { data: Buffer | Blob | ArrayBuffer | ArrayBufferView, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-uploadData", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-uploadData", options); try { if (isNode) { let buffer: Buffer; @@ -4354,17 +4246,14 @@ export class ShareFileClient extends StorageClient { return this.uploadSeekableInternal( (offset: number, size: number): Buffer => buffer.slice(offset, offset + size), buffer.byteLength, - { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - } + updatedOptions ); } else { const browserBlob = new Blob([data]); return this.uploadSeekableInternal( (offset: number, size: number): Blob => browserBlob.slice(offset, offset + size), browserBlob.size, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + updatedOptions ); } } catch (e) { @@ -4393,15 +4282,9 @@ export class ShareFileClient extends StorageClient { size: number, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-UploadSeekableBlob", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-UploadSeekableBlob", options); try { - return this.uploadSeekableInternal(blobFactory, size, { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return this.uploadSeekableInternal(blobFactory, size, updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -4426,7 +4309,7 @@ export class ShareFileClient extends StorageClient { filePath: string, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan("ShareFileClient-uploadFile", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareFileClient-uploadFile", options); try { const size = (await fsStat(filePath)).size; return await this.uploadSeekableInternal( @@ -4439,7 +4322,7 @@ export class ShareFileClient extends StorageClient { }); }, size, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + updatedOptions ); } catch (e) { span.setStatus({ @@ -4470,17 +4353,14 @@ export class ShareFileClient extends StorageClient { size: number, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-uploadResetableStream", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-uploadResetableStream", options); try { return await this.uploadSeekableInternal( (offset: number, count?: number) => { return () => streamFactory(offset, count); }, size, - { ...options, tracingOptions: { ...options!.tracingOptions, spanOptions } } + updatedOptions ); } catch (e) { span.setStatus({ @@ -4505,10 +4385,7 @@ export class ShareFileClient extends StorageClient { size: number, options: FileParallelUploadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-uploadSeekableInternal", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-uploadSeekableInternal", options); try { if (!options.rangeSize) { options.rangeSize = FILE_RANGE_MAX_SIZE_BYTES; @@ -4534,7 +4411,7 @@ export class ShareFileClient extends StorageClient { fileHttpHeaders: options.fileHttpHeaders, metadata: options.metadata, leaseAccessConditions: options.leaseAccessConditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); const numBlocks: number = Math.floor((size - 1) / options.rangeSize) + 1; @@ -4550,7 +4427,7 @@ export class ShareFileClient extends StorageClient { await this.uploadRange(bodyFactory(start, contentLength), start, contentLength, { abortSignal: options.abortSignal, leaseAccessConditions: options.leaseAccessConditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // Update progress after block is successfully uploaded to server, in case of block trying transferProgress += contentLength; @@ -4635,10 +4512,7 @@ export class ShareFileClient extends StorageClient { options = (countOrOptions as FileDownloadToBufferOptions) || {}; } - const { span, spanOptions } = createSpan( - "ShareFileClient-downloadToBuffer", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-downloadToBuffer", options); try { if (!options.rangeSize) { @@ -4668,7 +4542,7 @@ export class ShareFileClient extends StorageClient { const response = await this.getProperties({ abortSignal: options.abortSignal, leaseAccessConditions: options.leaseAccessConditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); count = response.contentLength! - offset; if (count < 0) { @@ -4709,7 +4583,7 @@ export class ShareFileClient extends StorageClient { abortSignal: options.abortSignal, maxRetryRequests: options.maxRetryRequestsPerRange, leaseAccessConditions: options.leaseAccessConditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); const stream = response.readableStreamBody!; await streamToBuffer(stream, buffer!, off - offset, chunkEnd - offset); @@ -4763,10 +4637,7 @@ export class ShareFileClient extends StorageClient { maxBuffers: number, options: FileUploadStreamOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-uploadStream", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-uploadStream", options); try { if (!options.fileHttpHeaders) { options.fileHttpHeaders = {}; @@ -4786,7 +4657,7 @@ export class ShareFileClient extends StorageClient { fileHttpHeaders: options.fileHttpHeaders, metadata: options.metadata, leaseAccessConditions: options.leaseAccessConditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); let transferProgress: number = 0; @@ -4805,7 +4676,7 @@ export class ShareFileClient extends StorageClient { await this.uploadRange(buffer, offset!, buffer.length, { abortSignal: options.abortSignal, leaseAccessConditions: options.leaseAccessConditions, - tracingOptions: { ...options!.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); // Update progress after block is successfully uploaded to server, in case of block trying @@ -4854,15 +4725,9 @@ export class ShareFileClient extends StorageClient { count?: number, options: FileDownloadOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-downloadToFile", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-downloadToFile", options); try { - const response = await this.download(offset, count, { - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const response = await this.download(offset, count, updatedOptions); if (response.readableStreamBody) { await readStreamToLocalFile(response.readableStreamBody, filePath); } @@ -4896,17 +4761,14 @@ export class ShareFileClient extends StorageClient { marker?: string, options: FileListHandlesSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-listHandlesSegment", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-listHandlesSegment", options); try { marker = marker === "" ? undefined : marker; const response = await this.context.listHandles({ abortSignal: options.abortSignal, marker, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); // TODO: Protocol layer issue that when handle list is in returned XML @@ -5023,16 +4885,16 @@ export class ShareFileClient extends StorageClient { marker?: string, options: FileForceCloseHandlesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( + const { span, updatedOptions } = createSpan( "ShareFileClient-forceCloseHandlesSegment", - options.tracingOptions + options ); try { marker = marker === "" ? undefined : marker; const rawResponse = await this.context.forceCloseHandles("*", { abortSignal: options.abortSignal, marker, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const response = rawResponse as FileForceCloseHandlesResponse; response.closedHandlesCount = rawResponse.numberOfHandlesClosed || 0; @@ -5058,10 +4920,7 @@ export class ShareFileClient extends StorageClient { public async forceCloseAllHandles( options: FileForceCloseHandlesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-forceCloseAllHandles", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-forceCloseAllHandles", options); try { let handlesClosed = 0; let numberOfHandlesFailedToClose = 0; @@ -5070,7 +4929,7 @@ export class ShareFileClient extends StorageClient { do { const response: FileForceCloseHandlesResponse = await this.forceCloseHandlesSegment( marker, - { tracingOptions: { ...options!.tracingOptions, spanOptions } } + { tracingOptions: updatedOptions.tracingOptions } ); marker = response.marker; response.closedHandlesCount && (handlesClosed += response.closedHandlesCount); @@ -5104,10 +4963,7 @@ export class ShareFileClient extends StorageClient { handleId: string, options: FileForceCloseHandlesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareFileClient-forceCloseHandle", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareFileClient-forceCloseHandle", options); try { if (handleId === "*") { throw new RangeError( @@ -5117,7 +4973,7 @@ export class ShareFileClient extends StorageClient { const rawResponse = await this.context.forceCloseHandles(handleId, { abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); const response = rawResponse as FileForceCloseHandlesResponse; response.closedHandlesCount = rawResponse.numberOfHandlesClosed || 0; @@ -5311,16 +5167,13 @@ export class ShareLeaseClient { duration: number = -1, options: LeaseOperationOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareLeaseClient-acquireLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareLeaseClient-acquireLease", options); try { return await this.fileOrShare.acquireLease({ abortSignal: options.abortSignal, duration, proposedLeaseId: this._leaseId, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -5344,15 +5197,12 @@ export class ShareLeaseClient { proposedLeaseId: string, options: LeaseOperationOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareLeaseClient-changeLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareLeaseClient-changeLease", options); try { const response = await this.fileOrShare.changeLease(this._leaseId, { proposedLeaseId, abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); this._leaseId = proposedLeaseId; return response; @@ -5375,14 +5225,11 @@ export class ShareLeaseClient { * @returns Response data for release lease operation. */ public async releaseLease(options: LeaseOperationOptions = {}): Promise { - const { span, spanOptions } = createSpan( - "ShareLeaseClient-releaseLease", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareLeaseClient-releaseLease", options); try { return await this.fileOrShare.releaseLease(this._leaseId, { abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -5402,11 +5249,11 @@ export class ShareLeaseClient { * @returns Response data for break lease operation. */ public async breakLease(options: LeaseOperationOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareLeaseClient-breakLease", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareLeaseClient-breakLease", options); try { return await this.fileOrShare.breakLease({ abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -5428,7 +5275,7 @@ export class ShareLeaseClient { * @returns Response data for renew lease operation. */ public async renewLease(options: LeaseOperationOptions = {}): Promise { - const { span, spanOptions } = createSpan("ShareLeaseClient-renewLease", options.tracingOptions); + const { span, updatedOptions } = createSpan("ShareLeaseClient-renewLease", options); if (!this.isShare) { throw new RangeError("The renewLease operation is not available for lease on file."); @@ -5437,7 +5284,7 @@ export class ShareLeaseClient { try { return await (this.fileOrShare as Share).renewLease(this._leaseId, { abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ diff --git a/sdk/storage/storage-file-share/src/ShareServiceClient.ts b/sdk/storage/storage-file-share/src/ShareServiceClient.ts index f9d7cb272ac6..3912992b3dfe 100644 --- a/sdk/storage/storage-file-share/src/ShareServiceClient.ts +++ b/sdk/storage/storage-file-share/src/ShareServiceClient.ts @@ -26,7 +26,7 @@ import "@azure/core-paging"; import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { isNode, HttpResponse } from "@azure/core-http"; import { CanonicalCode } from "@opentelemetry/api"; -import { createSpan } from "./utils/tracing"; +import { convertTracingToRequestOptionsBase, createSpan } from "./utils/tracing"; import { ShareProtocols, toShareProtocols } from "./models"; import { AccountSASPermissions } from "./AccountSASPermissions"; import { generateAccountSASQueryParameters } from "./AccountSASSignatureValues"; @@ -335,16 +335,10 @@ export class ShareServiceClient extends StorageClient { shareName: string, options: ShareCreateOptions = {} ): Promise<{ shareCreateResponse: ShareCreateResponse; shareClient: ShareClient }> { - const { span, spanOptions } = createSpan( - "ShareServiceClient-createShare", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareServiceClient-createShare", options); try { const shareClient = this.getShareClient(shareName); - const shareCreateResponse = await shareClient.create({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const shareCreateResponse = await shareClient.create(updatedOptions); return { shareCreateResponse, shareClient @@ -371,16 +365,10 @@ export class ShareServiceClient extends StorageClient { shareName: string, options: ShareDeleteMethodOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareServiceClient-deleteShare", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareServiceClient-deleteShare", options); try { const shareClient = this.getShareClient(shareName); - return await shareClient.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await shareClient.delete(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -403,14 +391,11 @@ export class ShareServiceClient extends StorageClient { public async getProperties( options: ServiceGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareServiceClient-getProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareServiceClient-getProperties", options); try { return await this.serviceContext.getProperties({ abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -436,14 +421,11 @@ export class ShareServiceClient extends StorageClient { properties: FileServiceProperties, options: ServiceSetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareServiceClient-setProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareServiceClient-setProperties", options); try { return await this.serviceContext.setProperties(properties, { abortSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); } catch (e) { span.setStatus({ @@ -645,10 +627,7 @@ export class ShareServiceClient extends StorageClient { marker?: string, options: ServiceListSharesSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareServiceClient-listSharesSegment", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareServiceClient-listSharesSegment", options); if (options.prefix === "") { options.prefix = undefined; @@ -658,7 +637,7 @@ export class ShareServiceClient extends StorageClient { const res = await this.serviceContext.listSharesSegment({ marker, ...options, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); // parse protocols @@ -696,17 +675,14 @@ export class ShareServiceClient extends StorageClient { deletedShareVersion: string, options: ServiceUndeleteShareOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "ShareServiceClient-undeleteShare", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("ShareServiceClient-undeleteShare", options); try { const shareClient = this.getShareClient(deletedShareName); await new ShareClientInternal(shareClient.url, this.pipeline).restore({ deletedShareName: deletedShareName, deletedShareVersion: deletedShareVersion, aborterSignal: options.abortSignal, - spanOptions + ...convertTracingToRequestOptionsBase(updatedOptions) }); return shareClient; } catch (e) { diff --git a/sdk/storage/storage-file-share/src/utils/tracing.ts b/sdk/storage/storage-file-share/src/utils/tracing.ts index 5f12d9a7d628..2ad2f29025b9 100644 --- a/sdk/storage/storage-file-share/src/utils/tracing.ts +++ b/sdk/storage/storage-file-share/src/utils/tracing.ts @@ -1,41 +1,29 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { Span, SpanOptions as OTSpanOptions, SpanKind } from "@opentelemetry/api"; -import { getTracer, SpanOptions, OperationTracingOptions } from "@azure/core-tracing"; +import { OperationOptions, RequestOptionsBase } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. - * @param name - The name of the operation being performed. - * @param tracingOptions - The tracingOptions for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - tracingOptions: OperationTracingOptions = {} -): { span: Span; spanOptions: SpanOptions } { - const tracer = getTracer(); - const spanOptions: OTSpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Storage.File.${operationName}`, spanOptions); - span.setAttribute("az.namespace", "Microsoft.Storage"); - - let newOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Storage" - } - }; - } +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Storage.File", + namespace: "Microsoft.Storage" +}); +/** + * @internal + * + * Adapt the tracing options from OperationOptions to what they need to be for + * RequestOptionsBase (when we update to later OpenTelemetry versions this is now + * two separate fields, not just one). + */ +export function convertTracingToRequestOptionsBase( + options?: OperationOptions +): Pick { return { - span, - spanOptions: newOptions + spanOptions: options?.tracingOptions?.spanOptions }; } diff --git a/sdk/storage/storage-queue/package.json b/sdk/storage/storage-queue/package.json index 3298bc729206..58db2ad01306 100644 --- a/sdk/storage/storage-queue/package.json +++ b/sdk/storage/storage-queue/package.json @@ -108,7 +108,7 @@ "@azure/abort-controller": "^1.0.0", "@azure/core-http": "^1.2.0", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/storage/storage-queue/src/QueueClient.ts b/sdk/storage/storage-queue/src/QueueClient.ts index 4a58570261fb..d78021020cc1 100644 --- a/sdk/storage/storage-queue/src/QueueClient.ts +++ b/sdk/storage/storage-queue/src/QueueClient.ts @@ -8,8 +8,7 @@ import { isNode, getDefaultProxySettings, URLBuilder, - RequestOptionsBase, - OperationOptions + RequestOptionsBase } from "@azure/core-http"; import { CanonicalCode } from "@opentelemetry/api"; import { @@ -50,7 +49,6 @@ import { generateQueueSASQueryParameters } from "./QueueSASSignatureValues"; import { SasIPRange } from "./SasIPRange"; import { QueueSASPermissions } from "./QueueSASPermissions"; import { SASProtocol } from "./SASQueryParameters"; -import { SpanOptions } from "@azure/core-tracing"; /** * Options to configure {@link QueueClient.create} operation @@ -618,14 +616,11 @@ export class QueueClient extends StorageClient { * ``` */ public async create(options: QueueCreateOptions = {}): Promise { - const { span, spanOptions } = createSpan("QueueClient-create", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-create", options); try { return await this.queueContext.create({ - ...options, - abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + ...updatedOptions, + abortSignal: options.abortSignal }); } catch (e) { span.setStatus({ @@ -648,15 +643,9 @@ export class QueueClient extends StorageClient { public async createIfNotExists( options: QueueCreateOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "QueueClient-createIfNotExists", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("QueueClient-createIfNotExists", options); try { - const response = await this.create({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const response = await this.create(updatedOptions); // When a queue with the specified name already exists, the Queue service checks the metadata associated with the existing queue. // If the existing metadata is identical to the metadata specified on the Create Queue request, status code 204 (No Content) is returned. @@ -703,12 +692,9 @@ export class QueueClient extends StorageClient { public async deleteIfExists( options: QueueDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-deleteIfExists", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-deleteIfExists", options); try { - const res = await this.delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + const res = await this.delete(updatedOptions); return { succeeded: true, ...res @@ -752,13 +738,11 @@ export class QueueClient extends StorageClient { * ``` */ public async delete(options: QueueDeleteOptions = {}): Promise { - const { span, spanOptions } = createSpan("QueueClient-delete", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-delete", options); try { return await this.queueContext.delete({ abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -781,11 +765,11 @@ export class QueueClient extends StorageClient { * @param options - options to Exists operation. */ public async exists(options: QueueExistsOptions = {}): Promise { - const { span, spanOptions } = createSpan("QueueClient-exists", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-exists", options); try { await this.getProperties({ abortSignal: options.abortSignal, - tracingOptions: { ...options.tracingOptions, spanOptions } + tracingOptions: updatedOptions.tracingOptions }); return true; } catch (e) { @@ -822,13 +806,11 @@ export class QueueClient extends StorageClient { public async getProperties( options: QueueGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-getProperties", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-getProperties", options); try { return await this.queueContext.getProperties({ abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -856,14 +838,12 @@ export class QueueClient extends StorageClient { metadata?: Metadata, options: QueueSetMetadataOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-setMetadata", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-setMetadata", options); try { return await this.queueContext.setMetadata({ abortSignal: options.abortSignal, metadata, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -890,13 +870,11 @@ export class QueueClient extends StorageClient { public async getAccessPolicy( options: QueueGetAccessPolicyOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-getAccessPolicy", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-getAccessPolicy", options); try { const response = await this.queueContext.getAccessPolicy({ abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); const res: QueueGetAccessPolicyResponse = { @@ -955,7 +933,7 @@ export class QueueClient extends StorageClient { queueAcl?: SignedIdentifier[], options: QueueSetAccessPolicyOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-setAccessPolicy", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-setAccessPolicy", options); try { const acl: SignedIdentifierModel[] = []; for (const identifier of queueAcl || []) { @@ -976,9 +954,7 @@ export class QueueClient extends StorageClient { return await this.queueContext.setAccessPolicy({ abortSignal: options.abortSignal, queueAcl: acl, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -1001,13 +977,11 @@ export class QueueClient extends StorageClient { public async clearMessages( options: QueueClearMessagesOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-clearMessages", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-clearMessages", options); try { return await this.messagesContext.clear({ abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -1045,13 +1019,13 @@ export class QueueClient extends StorageClient { messageText: string, options: QueueSendMessageOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-sendMessage", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-sendMessage", options); try { const response = await this.messagesContext.enqueue( { messageText: messageText }, - requestOptionsBaseToOperationOptions(options, spanOptions) + updatedOptions ); const item = response[0]; return { @@ -1106,11 +1080,9 @@ export class QueueClient extends StorageClient { public async receiveMessages( options: QueueReceiveMessageOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-receiveMessages", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-receiveMessages", options); try { - const response = await this.messagesContext.dequeue( - requestOptionsBaseToOperationOptions(options, spanOptions) - ); + const response = await this.messagesContext.dequeue(updatedOptions); const res: QueueReceiveMessageResponse = { _response: response._response, @@ -1155,11 +1127,9 @@ export class QueueClient extends StorageClient { public async peekMessages( options: QueuePeekMessagesOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-peekMessages", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-peekMessages", options); try { - const response = await this.messagesContext.peek( - requestOptionsBaseToOperationOptions(options, spanOptions) - ); + const response = await this.messagesContext.peek(updatedOptions); const res: QueuePeekMessagesResponse = { _response: response._response, @@ -1201,13 +1171,11 @@ export class QueueClient extends StorageClient { popReceipt: string, options: QueueDeleteMessageOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-deleteMessage", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-deleteMessage", options); try { return await this.getMessageIdContext(messageId).delete(popReceipt, { abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -1244,7 +1212,7 @@ export class QueueClient extends StorageClient { visibilityTimeout?: number, options: QueueUpdateMessageOptions = {} ): Promise { - const { span, spanOptions } = createSpan("QueueClient-updateMessage", options.tracingOptions); + const { span, updatedOptions } = createSpan("QueueClient-updateMessage", options); let queueMessage = undefined; if (message !== undefined) { queueMessage = { messageText: message }; @@ -1253,9 +1221,7 @@ export class QueueClient extends StorageClient { try { return await this.getMessageIdContext(messageId).update(popReceipt, visibilityTimeout || 0, { abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - }, + tracingOptions: updatedOptions.tracingOptions, queueMessage }); } catch (e) { @@ -1334,45 +1300,3 @@ export class QueueClient extends StorageClient { return appendToURLQuery(this.url, sas); } } - -/** - * Converts an RequestOptionsBase to a OperationOptions - * - * @param opts - RequestOptionsBase object to convert to OperationOptions - */ -function requestOptionsBaseToOperationOptions( - opts: T, - spanOptions?: SpanOptions -): OperationOptions { - const { - abortSignal, - customHeaders, - timeout, - onUploadProgress, - onDownloadProgress, - shouldDeserialize, - ...additionalOptions - } = opts; - - let result: OperationOptions = { ...additionalOptions }; - - if (abortSignal) { - result.abortSignal = abortSignal; - } - - result.requestOptions = { - customHeaders: customHeaders ?? undefined, - timeout: timeout ?? undefined, - onUploadProgress: onUploadProgress ?? undefined, - onDownloadProgress: onDownloadProgress ?? undefined, - shouldDeserialize: shouldDeserialize ?? undefined - }; - - if (spanOptions) { - result.tracingOptions = { - spanOptions: spanOptions - }; - } - - return result; -} diff --git a/sdk/storage/storage-queue/src/QueueServiceClient.ts b/sdk/storage/storage-queue/src/QueueServiceClient.ts index fdefd526f5ed..bdc542c0a976 100644 --- a/sdk/storage/storage-queue/src/QueueServiceClient.ts +++ b/sdk/storage/storage-queue/src/QueueServiceClient.ts @@ -320,10 +320,7 @@ export class QueueServiceClient extends StorageClient { marker?: string, options: ServiceListQueuesSegmentOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "QueueServiceClient-listQueuesSegment", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("QueueServiceClient-listQueuesSegment", options); if (options.prefix === "") { options.prefix = undefined; @@ -336,9 +333,7 @@ export class QueueServiceClient extends StorageClient { maxPageSize: options.maxPageSize, prefix: options.prefix, include: options.include === undefined ? undefined : [options.include], - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -526,16 +521,11 @@ export class QueueServiceClient extends StorageClient { public async getProperties( options: ServiceGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "QueueServiceClient-getProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("QueueServiceClient-getProperties", options); try { return await this.serviceContext.getProperties({ abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -561,16 +551,11 @@ export class QueueServiceClient extends StorageClient { properties: QueueServiceProperties, options: ServiceGetPropertiesOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "QueueServiceClient-setProperties", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("QueueServiceClient-setProperties", options); try { return await this.serviceContext.setProperties(properties, { abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -595,16 +580,11 @@ export class QueueServiceClient extends StorageClient { public async getStatistics( options: ServiceGetStatisticsOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "QueueServiceClient-getStatistics", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("QueueServiceClient-getStatistics", options); try { return await this.serviceContext.getStatistics({ abortSignal: options.abortSignal, - tracingOptions: { - spanOptions - } + tracingOptions: updatedOptions.tracingOptions }); } catch (e) { span.setStatus({ @@ -629,15 +609,9 @@ export class QueueServiceClient extends StorageClient { queueName: string, options: QueueCreateOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "QueueServiceClient-createQueue", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("QueueServiceClient-createQueue", options); try { - return await this.getQueueClient(queueName).create({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await this.getQueueClient(queueName).create(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, @@ -661,15 +635,9 @@ export class QueueServiceClient extends StorageClient { queueName: string, options: QueueDeleteOptions = {} ): Promise { - const { span, spanOptions } = createSpan( - "QueueServiceClient-deleteQueue", - options.tracingOptions - ); + const { span, updatedOptions } = createSpan("QueueServiceClient-deleteQueue", options); try { - return await this.getQueueClient(queueName).delete({ - ...options, - tracingOptions: { ...options!.tracingOptions, spanOptions } - }); + return await this.getQueueClient(queueName).delete(updatedOptions); } catch (e) { span.setStatus({ code: CanonicalCode.UNKNOWN, diff --git a/sdk/storage/storage-queue/src/utils/tracing.ts b/sdk/storage/storage-queue/src/utils/tracing.ts index 78a05e6170bf..7de33fd48a31 100644 --- a/sdk/storage/storage-queue/src/utils/tracing.ts +++ b/sdk/storage/storage-queue/src/utils/tracing.ts @@ -1,41 +1,29 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { Span, SpanOptions as OTSpanOptions, SpanKind } from "@opentelemetry/api"; -import { getTracer, SpanOptions, OperationTracingOptions } from "@azure/core-tracing"; +import { OperationOptions, RequestOptionsBase } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. - * @param operationName - The name of the operation being performed. - * @param options - The options for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - tracingOptions: OperationTracingOptions = {} -): { span: Span; spanOptions: SpanOptions } { - const tracer = getTracer(); - const spanOptions: OTSpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Storage.Queue.${operationName}`, spanOptions); - span.setAttribute("az.namespace", "Microsoft.Storage"); - - let newOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Storage" - } - }; - } +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Storage.Queue", + namespace: "Microsoft.Storage" +}); +/** + * @internal + * + * Adapt the tracing options from OperationOptions to what they need to be for + * RequestOptionsBase (when we update to later OpenTelemetry versions this is now + * two separate fields, not just one). + */ +export function convertTracingToRequestOptionsBase( + options?: OperationOptions +): Pick { return { - span, - spanOptions: newOptions + spanOptions: options?.tracingOptions?.spanOptions }; } diff --git a/sdk/synapse/synapse-access-control/package.json b/sdk/synapse/synapse-access-control/package.json index bc159c210dc5..65cfb27fefac 100644 --- a/sdk/synapse/synapse-access-control/package.json +++ b/sdk/synapse/synapse-access-control/package.json @@ -9,6 +9,7 @@ "dependencies": { "@azure/core-paging": "^1.1.1", "@azure/core-http": "^1.2.0", + "@azure/core-tracing": "1.0.0-beta.1", "tslib": "^2.0.0" }, "keywords": [ diff --git a/sdk/synapse/synapse-access-control/src/accessControlClient.ts b/sdk/synapse/synapse-access-control/src/accessControlClient.ts index 01a072537bb0..bd77c5092885 100644 --- a/sdk/synapse/synapse-access-control/src/accessControlClient.ts +++ b/sdk/synapse/synapse-access-control/src/accessControlClient.ts @@ -86,12 +86,9 @@ export class AccessControlClient extends AccessControlClientContext { private async _getRoleDefinitions( options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "AccessControlClient-_getRoleDefinitions", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("AccessControlClient-_getRoleDefinitions", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.sendOperationRequest( @@ -121,11 +118,11 @@ export class AccessControlClient extends AccessControlClientContext { ): Promise { const { span, updatedOptions } = createSpan( "AccessControlClient-getRoleDefinitionById", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { roleId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.sendOperationRequest( @@ -155,11 +152,11 @@ export class AccessControlClient extends AccessControlClientContext { ): Promise { const { span, updatedOptions } = createSpan( "AccessControlClient-createRoleAssignment", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { createRoleAssignmentOptions, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.sendOperationRequest( @@ -185,12 +182,9 @@ export class AccessControlClient extends AccessControlClientContext { async getRoleAssignments( options?: AccessControlClientGetRoleAssignmentsOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "AccessControlClient-getRoleAssignments", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("AccessControlClient-getRoleAssignments", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.sendOperationRequest( @@ -220,11 +214,11 @@ export class AccessControlClient extends AccessControlClientContext { ): Promise { const { span, updatedOptions } = createSpan( "AccessControlClient-getRoleAssignmentById", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { roleAssignmentId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.sendOperationRequest( @@ -254,11 +248,11 @@ export class AccessControlClient extends AccessControlClientContext { ): Promise { const { span, updatedOptions } = createSpan( "AccessControlClient-deleteRoleAssignmentById", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { roleAssignmentId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.sendOperationRequest( @@ -286,10 +280,10 @@ export class AccessControlClient extends AccessControlClientContext { ): Promise { const { span, updatedOptions } = createSpan( "AccessControlClient-getCallerRoleAssignments", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.sendOperationRequest( @@ -319,11 +313,11 @@ export class AccessControlClient extends AccessControlClientContext { ): Promise { const { span, updatedOptions } = createSpan( "AccessControlClient-_getRoleDefinitionsNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.sendOperationRequest( diff --git a/sdk/synapse/synapse-access-control/src/tracing.ts b/sdk/synapse/synapse-access-control/src/tracing.ts index bd5964daaed0..05a45bbbe4bc 100644 --- a/sdk/synapse/synapse-access-control/src/tracing.ts +++ b/sdk/synapse/synapse-access-control/src/tracing.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { createSpanFunction } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; export const createSpan = createSpanFunction({ namespace: "Azure.Synapse.AccessControl", diff --git a/sdk/synapse/synapse-artifacts/package.json b/sdk/synapse/synapse-artifacts/package.json index 268864491bd6..27e60bca0d41 100644 --- a/sdk/synapse/synapse-artifacts/package.json +++ b/sdk/synapse/synapse-artifacts/package.json @@ -10,6 +10,7 @@ "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", "@azure/core-http": "^1.2.0", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" }, diff --git a/sdk/synapse/synapse-artifacts/src/operations/bigDataPools.ts b/sdk/synapse/synapse-artifacts/src/operations/bigDataPools.ts index 6d2569067c71..96074d78373e 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/bigDataPools.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/bigDataPools.ts @@ -25,12 +25,10 @@ export class BigDataPools { * @param options The options parameters. */ async list(options?: coreHttp.OperationOptions): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-list", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-list", options); + const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, listOperationSpec); @@ -55,13 +53,11 @@ export class BigDataPools { bigDataPoolName: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-get", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-get", options); + const operationArguments: coreHttp.OperationArguments = { bigDataPoolName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, getOperationSpec); diff --git a/sdk/synapse/synapse-artifacts/src/operations/dataFlow.ts b/sdk/synapse/synapse-artifacts/src/operations/dataFlow.ts index bf0a7b5dab4e..fbfb22b8bf78 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/dataFlow.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/dataFlow.ts @@ -84,14 +84,11 @@ export class DataFlow { dataFlow: DataFlowResource, options?: DataFlowCreateOrUpdateDataFlowOptionalParams ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-createOrUpdateDataFlow", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-createOrUpdateDataFlow", options); const operationArguments: coreHttp.OperationArguments = { dataFlowName, dataFlow, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -132,13 +129,10 @@ export class DataFlow { dataFlowName: string, options?: DataFlowGetDataFlowOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getDataFlow", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getDataFlow", options); const operationArguments: coreHttp.OperationArguments = { dataFlowName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -166,13 +160,10 @@ export class DataFlow { dataFlowName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-deleteDataFlow", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-deleteDataFlow", options); const operationArguments: coreHttp.OperationArguments = { dataFlowName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -215,14 +206,11 @@ export class DataFlow { request: ArtifactRenameRequest, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-renameDataFlow", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-renameDataFlow", options); const operationArguments: coreHttp.OperationArguments = { dataFlowName, request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -263,10 +251,10 @@ export class DataFlow { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getDataFlowsByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -297,11 +285,11 @@ export class DataFlow { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getDataFlowsByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/dataFlowDebugSession.ts b/sdk/synapse/synapse-artifacts/src/operations/dataFlowDebugSession.ts index ae834b9efea8..0e1d94e49ba4 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/dataFlowDebugSession.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/dataFlowDebugSession.ts @@ -86,11 +86,11 @@ export class DataFlowDebugSession { ): Promise> { const { span, updatedOptions } = createSpan( "ArtifactsClient-createDataFlowDebugSession", - this.getOperationOptions(options, "undefined") + options ); const operationArguments: coreHttp.OperationArguments = { request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -131,10 +131,10 @@ export class DataFlowDebugSession { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_queryDataFlowDebugSessionsByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -162,13 +162,10 @@ export class DataFlowDebugSession { request: DataFlowDebugPackage, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-addDataFlow", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-addDataFlow", options); const operationArguments: coreHttp.OperationArguments = { request, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -198,11 +195,11 @@ export class DataFlowDebugSession { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-deleteDataFlowDebugSession", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { request, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -230,13 +227,10 @@ export class DataFlowDebugSession { request: DataFlowDebugCommandRequest, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-executeCommand", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-executeCommand", options); const operationArguments: coreHttp.OperationArguments = { request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -280,11 +274,11 @@ export class DataFlowDebugSession { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_queryDataFlowDebugSessionsByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/dataset.ts b/sdk/synapse/synapse-artifacts/src/operations/dataset.ts index f91bd321185b..f313d4e8b78e 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/dataset.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/dataset.ts @@ -80,12 +80,9 @@ export class Dataset { private async _getDatasetsByWorkspace( options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-_getDatasetsByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-_getDatasetsByWorkspace", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -115,14 +112,11 @@ export class Dataset { dataset: DatasetResource, options?: DatasetCreateOrUpdateDatasetOptionalParams ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-createOrUpdateDataset", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-createOrUpdateDataset", options); const operationArguments: coreHttp.OperationArguments = { datasetName, dataset, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -163,13 +157,10 @@ export class Dataset { datasetName: string, options?: DatasetGetDatasetOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getDataset", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getDataset", options); const operationArguments: coreHttp.OperationArguments = { datasetName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -197,13 +188,10 @@ export class Dataset { datasetName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-deleteDataset", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-deleteDataset", options); const operationArguments: coreHttp.OperationArguments = { datasetName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -246,14 +234,11 @@ export class Dataset { request: ArtifactRenameRequest, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-renameDataset", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-renameDataset", options); const operationArguments: coreHttp.OperationArguments = { datasetName, request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -296,11 +281,11 @@ export class Dataset { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getDatasetsByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/integrationRuntimes.ts b/sdk/synapse/synapse-artifacts/src/operations/integrationRuntimes.ts index 50b6c8b1d795..da4b56b8910e 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/integrationRuntimes.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/integrationRuntimes.ts @@ -25,12 +25,9 @@ export class IntegrationRuntimes { * @param options The options parameters. */ async list(options?: coreHttp.OperationOptions): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-list", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-list", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, listOperationSpec); @@ -55,13 +52,10 @@ export class IntegrationRuntimes { integrationRuntimeName: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-get", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-get", options); const operationArguments: coreHttp.OperationArguments = { integrationRuntimeName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, getOperationSpec); diff --git a/sdk/synapse/synapse-artifacts/src/operations/library.ts b/sdk/synapse/synapse-artifacts/src/operations/library.ts index dca79830fb19..279995660418 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/library.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/library.ts @@ -74,12 +74,9 @@ export class Library { * @param options The options parameters. */ private async _list(options?: coreHttp.OperationOptions): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-_list", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-_list", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, listOperationSpec); @@ -105,13 +102,10 @@ export class Library { libraryName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-flush", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-flush", options); const operationArguments: coreHttp.OperationArguments = { libraryName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -149,13 +143,10 @@ export class Library { operationId: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getOperationResult", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getOperationResult", options); const operationArguments: coreHttp.OperationArguments = { operationId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -184,13 +175,10 @@ export class Library { libraryName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-delete", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-delete", options); const operationArguments: coreHttp.OperationArguments = { libraryName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -226,13 +214,10 @@ export class Library { * @param options The options parameters. */ async get(libraryName: string, options?: coreHttp.OperationOptions): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-get", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-get", options); const operationArguments: coreHttp.OperationArguments = { libraryName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, getOperationSpec); @@ -261,14 +246,11 @@ export class Library { content: coreHttp.HttpRequestBody, options?: LibraryCreateOrAppendOptionalParams ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-createOrAppend", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-createOrAppend", options); const operationArguments: coreHttp.OperationArguments = { libraryName, content, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -309,13 +291,10 @@ export class Library { nextLink: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-_listNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-_listNext", options); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/linkedService.ts b/sdk/synapse/synapse-artifacts/src/operations/linkedService.ts index ae3c1ddfd384..516228766151 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/linkedService.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/linkedService.ts @@ -82,10 +82,10 @@ export class LinkedService { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getLinkedServicesByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -117,12 +117,12 @@ export class LinkedService { ): Promise> { const { span, updatedOptions } = createSpan( "ArtifactsClient-createOrUpdateLinkedService", - this.getOperationOptions(options, "undefined") + options ); const operationArguments: coreHttp.OperationArguments = { linkedServiceName, linkedService, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -163,13 +163,10 @@ export class LinkedService { linkedServiceName: string, options?: LinkedServiceGetLinkedServiceOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getLinkedService", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getLinkedService", options); const operationArguments: coreHttp.OperationArguments = { linkedServiceName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -197,13 +194,10 @@ export class LinkedService { linkedServiceName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-deleteLinkedService", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-deleteLinkedService", options); const operationArguments: coreHttp.OperationArguments = { linkedServiceName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -246,14 +240,11 @@ export class LinkedService { request: ArtifactRenameRequest, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-renameLinkedService", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-renameLinkedService", options); const operationArguments: coreHttp.OperationArguments = { linkedServiceName, request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -297,11 +288,11 @@ export class LinkedService { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getLinkedServicesByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/notebook.ts b/sdk/synapse/synapse-artifacts/src/operations/notebook.ts index efbf1d810a79..79180b5df90c 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/notebook.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/notebook.ts @@ -126,10 +126,10 @@ export class Notebook { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getNotebooksByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -157,10 +157,10 @@ export class Notebook { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getNotebookSummaryByWorkSpace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -190,14 +190,11 @@ export class Notebook { notebook: NotebookResource, options?: NotebookCreateOrUpdateNotebookOptionalParams ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-createOrUpdateNotebook", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-createOrUpdateNotebook", options); const operationArguments: coreHttp.OperationArguments = { notebookName, notebook, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -238,13 +235,10 @@ export class Notebook { notebookName: string, options?: NotebookGetNotebookOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getNotebook", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getNotebook", options); const operationArguments: coreHttp.OperationArguments = { notebookName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -272,13 +266,10 @@ export class Notebook { notebookName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-deleteNotebook", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-deleteNotebook", options); const operationArguments: coreHttp.OperationArguments = { notebookName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -321,14 +312,11 @@ export class Notebook { request: ArtifactRenameRequest, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-renameNotebook", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-renameNotebook", options); const operationArguments: coreHttp.OperationArguments = { notebookName, request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -372,11 +360,11 @@ export class Notebook { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getNotebooksByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -407,11 +395,11 @@ export class Notebook { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getNotebookSummaryByWorkSpaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/pipeline.ts b/sdk/synapse/synapse-artifacts/src/operations/pipeline.ts index 38b55e8d9bd5..b6b4397106da 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/pipeline.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/pipeline.ts @@ -84,10 +84,10 @@ export class Pipeline { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getPipelinesByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -117,14 +117,11 @@ export class Pipeline { pipeline: PipelineResource, options?: PipelineCreateOrUpdatePipelineOptionalParams ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-createOrUpdatePipeline", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-createOrUpdatePipeline", options); const operationArguments: coreHttp.OperationArguments = { pipelineName, pipeline, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -165,13 +162,10 @@ export class Pipeline { pipelineName: string, options?: PipelineGetPipelineOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getPipeline", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getPipeline", options); const operationArguments: coreHttp.OperationArguments = { pipelineName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -199,13 +193,10 @@ export class Pipeline { pipelineName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-deletePipeline", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-deletePipeline", options); const operationArguments: coreHttp.OperationArguments = { pipelineName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -248,14 +239,11 @@ export class Pipeline { request: ArtifactRenameRequest, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-renamePipeline", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-renamePipeline", options); const operationArguments: coreHttp.OperationArguments = { pipelineName, request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -296,13 +284,10 @@ export class Pipeline { pipelineName: string, options?: PipelineCreatePipelineRunOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-createPipelineRun", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-createPipelineRun", options); const operationArguments: coreHttp.OperationArguments = { pipelineName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -333,11 +318,11 @@ export class Pipeline { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getPipelinesByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/pipelineRun.ts b/sdk/synapse/synapse-artifacts/src/operations/pipelineRun.ts index e0303a0aec15..0f54e1716736 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/pipelineRun.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/pipelineRun.ts @@ -37,11 +37,11 @@ export class PipelineRun { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-queryPipelineRunsByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { filterParameters, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -69,13 +69,10 @@ export class PipelineRun { runId: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getPipelineRun", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getPipelineRun", options); const operationArguments: coreHttp.OperationArguments = { runId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -107,15 +104,12 @@ export class PipelineRun { filterParameters: RunFilterParameters, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-queryActivityRuns", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-queryActivityRuns", options); const operationArguments: coreHttp.OperationArguments = { pipelineName, runId, filterParameters, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -143,13 +137,10 @@ export class PipelineRun { runId: string, options?: PipelineRunCancelPipelineRunOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-cancelPipelineRun", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-cancelPipelineRun", options); const operationArguments: coreHttp.OperationArguments = { runId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/sparkJobDefinition.ts b/sdk/synapse/synapse-artifacts/src/operations/sparkJobDefinition.ts index f1d87432c05d..fc8bec0ad299 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/sparkJobDefinition.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/sparkJobDefinition.ts @@ -84,10 +84,10 @@ export class SparkJobDefinition { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getSparkJobDefinitionsByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -119,12 +119,12 @@ export class SparkJobDefinition { ): Promise> { const { span, updatedOptions } = createSpan( "ArtifactsClient-createOrUpdateSparkJobDefinition", - this.getOperationOptions(options, "undefined") + options ); const operationArguments: coreHttp.OperationArguments = { sparkJobDefinitionName, sparkJobDefinition, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -165,13 +165,10 @@ export class SparkJobDefinition { sparkJobDefinitionName: string, options?: SparkJobDefinitionGetSparkJobDefinitionOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getSparkJobDefinition", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getSparkJobDefinition", options); const operationArguments: coreHttp.OperationArguments = { sparkJobDefinitionName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -201,11 +198,11 @@ export class SparkJobDefinition { ): Promise> { const { span, updatedOptions } = createSpan( "ArtifactsClient-deleteSparkJobDefinition", - this.getOperationOptions(options, "undefined") + options ); const operationArguments: coreHttp.OperationArguments = { sparkJobDefinitionName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -248,11 +245,11 @@ export class SparkJobDefinition { ): Promise> { const { span, updatedOptions } = createSpan( "ArtifactsClient-executeSparkJobDefinition", - this.getOperationOptions(options, "location") + options ); const operationArguments: coreHttp.OperationArguments = { sparkJobDefinitionName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "location") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -298,12 +295,12 @@ export class SparkJobDefinition { ): Promise> { const { span, updatedOptions } = createSpan( "ArtifactsClient-renameSparkJobDefinition", - this.getOperationOptions(options, "undefined") + options ); const operationArguments: coreHttp.OperationArguments = { sparkJobDefinitionName, request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -344,13 +341,10 @@ export class SparkJobDefinition { sparkJobDefinitionAzureResource: SparkJobDefinitionResource, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-debugSparkJobDefinition", - this.getOperationOptions(options, "location") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-debugSparkJobDefinition", options); const operationArguments: coreHttp.OperationArguments = { sparkJobDefinitionAzureResource, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "location") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -395,11 +389,11 @@ export class SparkJobDefinition { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getSparkJobDefinitionsByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/sqlPools.ts b/sdk/synapse/synapse-artifacts/src/operations/sqlPools.ts index 05848db9e408..92f522939d1a 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/sqlPools.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/sqlPools.ts @@ -25,12 +25,9 @@ export class SqlPools { * @param options The options parameters. */ async list(options?: coreHttp.OperationOptions): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-list", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-list", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, listOperationSpec); @@ -55,13 +52,10 @@ export class SqlPools { sqlPoolName: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-get", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-get", options); const operationArguments: coreHttp.OperationArguments = { sqlPoolName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, getOperationSpec); diff --git a/sdk/synapse/synapse-artifacts/src/operations/sqlScript.ts b/sdk/synapse/synapse-artifacts/src/operations/sqlScript.ts index 255ec198f0c3..8c41ab577075 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/sqlScript.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/sqlScript.ts @@ -82,10 +82,10 @@ export class SqlScript { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getSqlScriptsByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -115,14 +115,11 @@ export class SqlScript { sqlScript: SqlScriptResource, options?: SqlScriptCreateOrUpdateSqlScriptOptionalParams ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-createOrUpdateSqlScript", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-createOrUpdateSqlScript", options); const operationArguments: coreHttp.OperationArguments = { sqlScriptName, sqlScript, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -163,13 +160,10 @@ export class SqlScript { sqlScriptName: string, options?: SqlScriptGetSqlScriptOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getSqlScript", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getSqlScript", options); const operationArguments: coreHttp.OperationArguments = { sqlScriptName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -197,13 +191,10 @@ export class SqlScript { sqlScriptName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-deleteSqlScript", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-deleteSqlScript", options); const operationArguments: coreHttp.OperationArguments = { sqlScriptName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -246,14 +237,11 @@ export class SqlScript { request: ArtifactRenameRequest, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-renameSqlScript", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-renameSqlScript", options); const operationArguments: coreHttp.OperationArguments = { sqlScriptName, request, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -297,11 +285,11 @@ export class SqlScript { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getSqlScriptsByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/trigger.ts b/sdk/synapse/synapse-artifacts/src/operations/trigger.ts index 503cd613b8ed..f94cd6188ef7 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/trigger.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/trigger.ts @@ -82,12 +82,9 @@ export class Trigger { private async _getTriggersByWorkspace( options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-_getTriggersByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-_getTriggersByWorkspace", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -117,14 +114,11 @@ export class Trigger { trigger: TriggerResource, options?: TriggerCreateOrUpdateTriggerOptionalParams ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-createOrUpdateTrigger", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-createOrUpdateTrigger", options); const operationArguments: coreHttp.OperationArguments = { triggerName, trigger, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -165,13 +159,10 @@ export class Trigger { triggerName: string, options?: TriggerGetTriggerOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getTrigger", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getTrigger", options); const operationArguments: coreHttp.OperationArguments = { triggerName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -199,13 +190,10 @@ export class Trigger { triggerName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-deleteTrigger", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-deleteTrigger", options); const operationArguments: coreHttp.OperationArguments = { triggerName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -248,11 +236,11 @@ export class Trigger { ): Promise> { const { span, updatedOptions } = createSpan( "ArtifactsClient-subscribeTriggerToEvents", - this.getOperationOptions(options, "undefined") + options ); const operationArguments: coreHttp.OperationArguments = { triggerName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -295,11 +283,11 @@ export class Trigger { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-getEventSubscriptionStatus", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { triggerName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -329,11 +317,11 @@ export class Trigger { ): Promise> { const { span, updatedOptions } = createSpan( "ArtifactsClient-unsubscribeTriggerFromEvents", - this.getOperationOptions(options, "undefined") + options ); const operationArguments: coreHttp.OperationArguments = { triggerName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -374,13 +362,10 @@ export class Trigger { triggerName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-startTrigger", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-startTrigger", options); const operationArguments: coreHttp.OperationArguments = { triggerName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -421,13 +406,10 @@ export class Trigger { triggerName: string, options?: coreHttp.OperationOptions ): Promise> { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-stopTrigger", - this.getOperationOptions(options, "undefined") - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-stopTrigger", options); const operationArguments: coreHttp.OperationArguments = { triggerName, - options: updatedOptions + options: this.getOperationOptions(updatedOptions, "undefined") }; const sendOperation = async ( args: coreHttp.OperationArguments, @@ -470,11 +452,11 @@ export class Trigger { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-_getTriggersByWorkspaceNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/triggerRun.ts b/sdk/synapse/synapse-artifacts/src/operations/triggerRun.ts index 4dafcc9228da..dd8202fc3dc0 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/triggerRun.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/triggerRun.ts @@ -31,14 +31,11 @@ export class TriggerRun { runId: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-rerunTriggerInstance", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-rerunTriggerInstance", options); const operationArguments: coreHttp.OperationArguments = { triggerName, runId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -68,14 +65,11 @@ export class TriggerRun { runId: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-cancelTriggerInstance", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-cancelTriggerInstance", options); const operationArguments: coreHttp.OperationArguments = { triggerName, runId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -105,11 +99,11 @@ export class TriggerRun { ): Promise { const { span, updatedOptions } = createSpan( "ArtifactsClient-queryTriggerRunsByWorkspace", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) + options ); const operationArguments: coreHttp.OperationArguments = { filterParameters, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/operations/workspace.ts b/sdk/synapse/synapse-artifacts/src/operations/workspace.ts index 9fab49db7fd5..46d6c87b83bb 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/workspace.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/workspace.ts @@ -25,12 +25,9 @@ export class Workspace { * @param options The options parameters. */ async get(options?: coreHttp.OperationOptions): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-get", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-get", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, getOperationSpec); diff --git a/sdk/synapse/synapse-artifacts/src/operations/workspaceGitRepoManagement.ts b/sdk/synapse/synapse-artifacts/src/operations/workspaceGitRepoManagement.ts index 910b262a5cf4..9a34ca199221 100644 --- a/sdk/synapse/synapse-artifacts/src/operations/workspaceGitRepoManagement.ts +++ b/sdk/synapse/synapse-artifacts/src/operations/workspaceGitRepoManagement.ts @@ -33,13 +33,10 @@ export class WorkspaceGitRepoManagement { gitHubAccessTokenRequest: GitHubAccessTokenRequest, options?: WorkspaceGitRepoManagementGetGitHubAccessTokenOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "ArtifactsClient-getGitHubAccessToken", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ArtifactsClient-getGitHubAccessToken", options); const operationArguments: coreHttp.OperationArguments = { gitHubAccessTokenRequest, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-artifacts/src/tracing.ts b/sdk/synapse/synapse-artifacts/src/tracing.ts index 36ffdc4f7e26..91d8fa2dcf21 100644 --- a/sdk/synapse/synapse-artifacts/src/tracing.ts +++ b/sdk/synapse/synapse-artifacts/src/tracing.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { createSpanFunction } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; export const createSpan = createSpanFunction({ namespace: "Azure.Synapse.Artifacts", diff --git a/sdk/synapse/synapse-managed-private-endpoints/package.json b/sdk/synapse/synapse-managed-private-endpoints/package.json index f0c06ce1961e..493d320ee257 100644 --- a/sdk/synapse/synapse-managed-private-endpoints/package.json +++ b/sdk/synapse/synapse-managed-private-endpoints/package.json @@ -9,6 +9,7 @@ "dependencies": { "@azure/core-paging": "^1.1.1", "@azure/core-http": "^1.2.0", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" }, diff --git a/sdk/synapse/synapse-managed-private-endpoints/src/operations/managedPrivateEndpoints.ts b/sdk/synapse/synapse-managed-private-endpoints/src/operations/managedPrivateEndpoints.ts index b089042fd23f..23b267eaa645 100644 --- a/sdk/synapse/synapse-managed-private-endpoints/src/operations/managedPrivateEndpoints.ts +++ b/sdk/synapse/synapse-managed-private-endpoints/src/operations/managedPrivateEndpoints.ts @@ -84,14 +84,11 @@ export class ManagedPrivateEndpoints { managedPrivateEndpointName: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ManagedPrivateEndpointsClient-get", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ManagedPrivateEndpointsClient-get", options); const operationArguments: coreHttp.OperationArguments = { managedVirtualNetworkName, managedPrivateEndpointName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, getOperationSpec); @@ -120,15 +117,12 @@ export class ManagedPrivateEndpoints { managedPrivateEndpoint: ManagedPrivateEndpoint, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ManagedPrivateEndpointsClient-create", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ManagedPrivateEndpointsClient-create", options); const operationArguments: coreHttp.OperationArguments = { managedVirtualNetworkName, managedPrivateEndpointName, managedPrivateEndpoint, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -158,14 +152,11 @@ export class ManagedPrivateEndpoints { managedPrivateEndpointName: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ManagedPrivateEndpointsClient-delete", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ManagedPrivateEndpointsClient-delete", options); const operationArguments: coreHttp.OperationArguments = { managedVirtualNetworkName, managedPrivateEndpointName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -193,13 +184,10 @@ export class ManagedPrivateEndpoints { managedVirtualNetworkName: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ManagedPrivateEndpointsClient-_list", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ManagedPrivateEndpointsClient-_list", options); const operationArguments: coreHttp.OperationArguments = { managedVirtualNetworkName, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest(operationArguments, listOperationSpec); @@ -226,14 +214,11 @@ export class ManagedPrivateEndpoints { nextLink: string, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "ManagedPrivateEndpointsClient-_listNext", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("ManagedPrivateEndpointsClient-_listNext", options); const operationArguments: coreHttp.OperationArguments = { managedVirtualNetworkName, nextLink, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-managed-private-endpoints/src/tracing.ts b/sdk/synapse/synapse-managed-private-endpoints/src/tracing.ts index ec5a2da97e89..a2368a37a779 100644 --- a/sdk/synapse/synapse-managed-private-endpoints/src/tracing.ts +++ b/sdk/synapse/synapse-managed-private-endpoints/src/tracing.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { createSpanFunction } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; export const createSpan = createSpanFunction({ namespace: "Azure.Synapse.ManagedPrivateEndpoints", diff --git a/sdk/synapse/synapse-monitoring/package.json b/sdk/synapse/synapse-monitoring/package.json index 7715d81dd0b4..3140e4016a93 100644 --- a/sdk/synapse/synapse-monitoring/package.json +++ b/sdk/synapse/synapse-monitoring/package.json @@ -8,6 +8,7 @@ "version": "1.0.0-beta.3", "dependencies": { "@azure/core-http": "^1.2.0", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" }, diff --git a/sdk/synapse/synapse-monitoring/src/operations/monitoring.ts b/sdk/synapse/synapse-monitoring/src/operations/monitoring.ts index d6ee4e590a64..d07da553832c 100644 --- a/sdk/synapse/synapse-monitoring/src/operations/monitoring.ts +++ b/sdk/synapse/synapse-monitoring/src/operations/monitoring.ts @@ -32,12 +32,9 @@ export class Monitoring { async getSparkJobList( options?: MonitoringGetSparkJobListOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "MonitoringClient-getSparkJobList", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("MonitoringClient-getSparkJobList", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -63,12 +60,9 @@ export class Monitoring { async getSqlJobQueryString( options?: MonitoringGetSqlJobQueryStringOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "MonitoringClient-getSqlJobQueryString", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("MonitoringClient-getSqlJobQueryString", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-monitoring/src/tracing.ts b/sdk/synapse/synapse-monitoring/src/tracing.ts index bf65d560face..200976381478 100644 --- a/sdk/synapse/synapse-monitoring/src/tracing.ts +++ b/sdk/synapse/synapse-monitoring/src/tracing.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { createSpanFunction } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; export const createSpan = createSpanFunction({ namespace: "Azure.Synapse.Monitoring", diff --git a/sdk/synapse/synapse-spark/package.json b/sdk/synapse/synapse-spark/package.json index b339a5f8b89f..9d1a75ac6689 100644 --- a/sdk/synapse/synapse-spark/package.json +++ b/sdk/synapse/synapse-spark/package.json @@ -8,6 +8,7 @@ "version": "1.0.0-beta.3", "dependencies": { "@azure/core-http": "^1.2.0", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" }, diff --git a/sdk/synapse/synapse-spark/src/operations/sparkBatch.ts b/sdk/synapse/synapse-spark/src/operations/sparkBatch.ts index 56d101867c09..2d358ddfb88e 100644 --- a/sdk/synapse/synapse-spark/src/operations/sparkBatch.ts +++ b/sdk/synapse/synapse-spark/src/operations/sparkBatch.ts @@ -35,12 +35,9 @@ export class SparkBatch { async getSparkBatchJobs( options?: SparkBatchGetSparkBatchJobsOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-getSparkBatchJobs", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-getSparkBatchJobs", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -68,13 +65,10 @@ export class SparkBatch { sparkBatchJobOptions: SparkBatchJobOptions, options?: SparkBatchCreateSparkBatchJobOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-createSparkBatchJob", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-createSparkBatchJob", options); const operationArguments: coreHttp.OperationArguments = { sparkBatchJobOptions, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -102,13 +96,10 @@ export class SparkBatch { batchId: number, options?: SparkBatchGetSparkBatchJobOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-getSparkBatchJob", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-getSparkBatchJob", options); const operationArguments: coreHttp.OperationArguments = { batchId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -136,13 +127,10 @@ export class SparkBatch { batchId: number, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-cancelSparkBatchJob", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-cancelSparkBatchJob", options); const operationArguments: coreHttp.OperationArguments = { batchId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-spark/src/operations/sparkSession.ts b/sdk/synapse/synapse-spark/src/operations/sparkSession.ts index 0780d182a66a..d2e44b95646a 100644 --- a/sdk/synapse/synapse-spark/src/operations/sparkSession.ts +++ b/sdk/synapse/synapse-spark/src/operations/sparkSession.ts @@ -40,12 +40,9 @@ export class SparkSession { async getSparkSessions( options?: SparkSessionGetSparkSessionsOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-getSparkSessions", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-getSparkSessions", options); const operationArguments: coreHttp.OperationArguments = { - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -73,13 +70,10 @@ export class SparkSession { sparkSessionOptions: SparkSessionOptions, options?: SparkSessionCreateSparkSessionOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-createSparkSession", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-createSparkSession", options); const operationArguments: coreHttp.OperationArguments = { sparkSessionOptions, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -107,13 +101,10 @@ export class SparkSession { sessionId: number, options?: SparkSessionGetSparkSessionOptionalParams ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-getSparkSession", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-getSparkSession", options); const operationArguments: coreHttp.OperationArguments = { sessionId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -141,13 +132,10 @@ export class SparkSession { sessionId: number, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-cancelSparkSession", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-cancelSparkSession", options); const operationArguments: coreHttp.OperationArguments = { sessionId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -175,13 +163,10 @@ export class SparkSession { sessionId: number, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-resetSparkSessionTimeout", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-resetSparkSessionTimeout", options); const operationArguments: coreHttp.OperationArguments = { sessionId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -209,13 +194,10 @@ export class SparkSession { sessionId: number, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-getSparkStatements", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-getSparkStatements", options); const operationArguments: coreHttp.OperationArguments = { sessionId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -245,14 +227,11 @@ export class SparkSession { sparkStatementOptions: SparkStatementOptions, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-createSparkStatement", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-createSparkStatement", options); const operationArguments: coreHttp.OperationArguments = { sessionId, sparkStatementOptions, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -282,14 +261,11 @@ export class SparkSession { statementId: number, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-getSparkStatement", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-getSparkStatement", options); const operationArguments: coreHttp.OperationArguments = { sessionId, statementId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( @@ -319,14 +295,11 @@ export class SparkSession { statementId: number, options?: coreHttp.OperationOptions ): Promise { - const { span, updatedOptions } = createSpan( - "SparkClient-cancelSparkStatement", - coreHttp.operationOptionsToRequestOptionsBase(options || {}) - ); + const { span, updatedOptions } = createSpan("SparkClient-cancelSparkStatement", options); const operationArguments: coreHttp.OperationArguments = { sessionId, statementId, - options: updatedOptions + options: coreHttp.operationOptionsToRequestOptionsBase(updatedOptions) }; try { const result = await this.client.sendOperationRequest( diff --git a/sdk/synapse/synapse-spark/src/tracing.ts b/sdk/synapse/synapse-spark/src/tracing.ts index 08ce4428a831..9d08d59a6c3e 100644 --- a/sdk/synapse/synapse-spark/src/tracing.ts +++ b/sdk/synapse/synapse-spark/src/tracing.ts @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { createSpanFunction } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; export const createSpan = createSpanFunction({ namespace: "Azure.Synapse.Spark", diff --git a/sdk/tables/data-tables/package.json b/sdk/tables/data-tables/package.json index 075d52283a80..45aecf7fd670 100644 --- a/sdk/tables/data-tables/package.json +++ b/sdk/tables/data-tables/package.json @@ -71,7 +71,7 @@ "@azure/core-paging": "^1.1.1", "@azure/core-xml": "1.0.0-beta.1", "@azure/logger": "^1.0.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0", "uuid": "^8.3.0" diff --git a/sdk/tables/data-tables/src/utils/tracing.ts b/sdk/tables/data-tables/src/utils/tracing.ts index bb3113ffe0ec..842b41f1d24d 100644 --- a/sdk/tables/data-tables/src/utils/tracing.ts +++ b/sdk/tables/data-tables/src/utils/tracing.ts @@ -1,57 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-client"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. * @internal - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan(`Azure.Data.Tables.${operationName}`, spanOptions); - - span.setAttribute("az.namespace", "Microsoft.Data.Tables"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.Data.Tables" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Data.Tables", + namespace: "Microsoft.Data.Tables" +}); diff --git a/sdk/template/template/package.json b/sdk/template/template/package.json index 408a7d36baa6..18ffb652e71f 100644 --- a/sdk/template/template/package.json +++ b/sdk/template/template/package.json @@ -74,7 +74,7 @@ "dependencies": { "@azure/core-auth": "^1.2.0", "@azure/core-http": "^1.2.0", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/template/template/src/tracing.ts b/sdk/template/template/src/tracing.ts index 6281d205232e..fa1e65d70523 100644 --- a/sdk/template/template/src/tracing.ts +++ b/sdk/template/template/src/tracing.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. // -import { createSpanFunction } from "@azure/core-http"; +import { createSpanFunction } from "@azure/core-tracing"; /** * Creates a span using the global tracer. diff --git a/sdk/textanalytics/ai-text-analytics/package.json b/sdk/textanalytics/ai-text-analytics/package.json index 1db4adde8e38..d33bf2f207d3 100644 --- a/sdk/textanalytics/ai-text-analytics/package.json +++ b/sdk/textanalytics/ai-text-analytics/package.json @@ -86,7 +86,7 @@ "@azure/core-http": "^1.2.0", "@azure/core-lro": "^1.0.2", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.9", + "@azure/core-tracing": "1.0.0-beta.1", "@azure/logger": "^1.0.0", "@opentelemetry/api": "^0.10.2", "tslib": "^2.0.0" diff --git a/sdk/textanalytics/ai-text-analytics/src/tracing.ts b/sdk/textanalytics/ai-text-analytics/src/tracing.ts index 8ed4b7e36505..9f785fd9deb9 100644 --- a/sdk/textanalytics/ai-text-analytics/src/tracing.ts +++ b/sdk/textanalytics/ai-text-analytics/src/tracing.ts @@ -1,60 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { getTracer } from "@azure/core-tracing"; -import { Span, SpanOptions, SpanKind } from "@opentelemetry/api"; -import { OperationOptions } from "@azure/core-http"; - -type OperationTracingOptions = OperationOptions["tracingOptions"]; +import { createSpanFunction } from "@azure/core-tracing"; /** - * @internal * Creates a span using the global tracer. - * @param name - The name of the operation being performed. - * @param tracingOptions - The options for the underlying http request. + * @internal */ -export function createSpan( - operationName: string, - operationOptions: T -): { span: Span; updatedOptions: T } { - const tracer = getTracer(); - const tracingOptions = operationOptions.tracingOptions || {}; - const spanOptions: SpanOptions = { - ...tracingOptions.spanOptions, - kind: SpanKind.INTERNAL - }; - - const span = tracer.startSpan( - `Azure.CognitiveServices.TextAnalytics.${operationName}`, - spanOptions - ); - - span.setAttribute("az.namespace", "Microsoft.CognitiveServices"); - - let newSpanOptions = tracingOptions.spanOptions || {}; - if (span.isRecording()) { - newSpanOptions = { - ...tracingOptions.spanOptions, - parent: span.context(), - attributes: { - ...spanOptions.attributes, - "az.namespace": "Microsoft.CognitiveServices" - } - }; - } - - const newTracingOptions: OperationTracingOptions = { - ...tracingOptions, - spanOptions: newSpanOptions - }; - - const newOperationOptions: T = { - ...operationOptions, - tracingOptions: newTracingOptions - }; - - return { - span, - updatedOptions: newOperationOptions - }; -} +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.CognitiveServices.TextAnalytics", + namespace: "Microsoft.CognitiveServices" +});