diff --git a/sdk/core/core-http/test/policies/tracingPolicyTests.ts b/sdk/core/core-http/test/policies/tracingPolicyTests.ts index ee9b43769f5e..09f1b43610eb 100644 --- a/sdk/core/core-http/test/policies/tracingPolicyTests.ts +++ b/sdk/core/core-http/test/policies/tracingPolicyTests.ts @@ -13,15 +13,15 @@ import { SpanContext, TraceFlags, TraceState, - setSpan, context, SpanStatusCode, SpanStatus, SpanAttributes, + SpanOptions, SpanAttributeValue } from "@azure/core-tracing"; import { tracingPolicy } from "../../src/policies/tracingPolicy"; -import { TracerProvider, Tracer, Span, SpanOptions, trace } from "@opentelemetry/api"; +import { TracerProvider, Tracer, Span, trace } from "@opentelemetry/api"; import sinon from "sinon"; class MockSpan implements Span { @@ -210,7 +210,7 @@ describe("tracingPolicy", function() { mockTracerProvider.setTracer(mockTracer); const request = new WebResource(); - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); await policy.sendRequest(request); @@ -237,7 +237,7 @@ describe("tracingPolicy", function() { mockTracerProvider.setTracer(mockTracer); const request = new WebResource(); - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); await policy.sendRequest(request); @@ -265,7 +265,7 @@ describe("tracingPolicy", function() { const mockTracer = new MockTracer(mockTraceId, mockSpanId, TraceFlags.SAMPLED, mockTraceState); mockTracerProvider.setTracer(mockTracer); const request = new WebResource(); - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); await policy.sendRequest(request); @@ -293,7 +293,7 @@ describe("tracingPolicy", function() { const mockTracer = new MockTracer(mockTraceId, mockSpanId, TraceFlags.SAMPLED, mockTraceState); mockTracerProvider.setTracer(mockTracer); const request = new WebResource(); - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create( { @@ -336,7 +336,7 @@ describe("tracingPolicy", function() { it("will not set headers if span is a NoOpSpan", async () => { mockTracerProvider.disable(); const request = new WebResource(); - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); await policy.sendRequest(request); @@ -351,7 +351,7 @@ describe("tracingPolicy", function() { mockTracerProvider.setTracer(mockTracer); const request = new WebResource(); - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); await policy.sendRequest(request); @@ -366,7 +366,7 @@ describe("tracingPolicy", function() { mockTracerProvider.setTracer(errorTracer); const request = new WebResource(); - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); @@ -382,7 +382,7 @@ describe("tracingPolicy", function() { sinon.stub(errorTracer, "startSpan").returns(errorSpan); const request = new WebResource(); - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); @@ -398,10 +398,9 @@ describe("tracingPolicy", function() { request.spanOptions = { attributes: { "az.namespace": "value_from_span_options" } }; - request.tracingContext = setSpan(context.active(), ROOT_SPAN).setValue( - Symbol.for("az.namespace"), - "value_from_context" - ); + request.tracingContext = trace + .setSpan(context.active(), ROOT_SPAN) + .setValue(Symbol.for("az.namespace"), "value_from_context"); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); await policy.sendRequest(request); @@ -420,7 +419,7 @@ describe("tracingPolicy", function() { request.spanOptions = { attributes: { "az.namespace": "value_from_span_options" } }; - request.tracingContext = setSpan(context.active(), ROOT_SPAN); + request.tracingContext = trace.setSpan(context.active(), ROOT_SPAN); const policy = tracingPolicy().create(mockPolicy, new RequestPolicyOptions()); await policy.sendRequest(request); diff --git a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts index e6c8ccea2a47..41c6c1a20237 100644 --- a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts +++ b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts @@ -16,12 +16,11 @@ import { TraceFlags, TraceState, context, - setSpan, SpanStatus, SpanStatusCode, SpanAttributes, - SpanAttributeValue, - SpanOptions + SpanOptions, + SpanAttributeValue } from "@azure/core-tracing"; import { TracerProvider, Tracer, Span, trace } from "@opentelemetry/api"; @@ -212,7 +211,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const response: PipelineResponse = { @@ -251,7 +250,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const response: PipelineResponse = { @@ -290,7 +289,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const response: PipelineResponse = { @@ -328,7 +327,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const policy = tracingPolicy(); @@ -366,7 +365,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const response: PipelineResponse = { @@ -391,7 +390,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const response: PipelineResponse = { @@ -416,7 +415,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const response: PipelineResponse = { @@ -443,7 +442,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const response: PipelineResponse = { @@ -469,10 +468,9 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN).setValue( - Symbol.for("az.namespace"), - "value_from_context" - ) + tracingContext: trace + .setSpan(context.active(), ROOT_SPAN) + .setValue(Symbol.for("az.namespace"), "value_from_context") } }); Object.assign(request.tracingOptions, { @@ -503,7 +501,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); Object.assign(request.tracingOptions, { @@ -534,7 +532,7 @@ describe("tracingPolicy", function() { const request = createPipelineRequest({ url: "https://bing.com", tracingOptions: { - tracingContext: setSpan(context.active(), ROOT_SPAN) + tracingContext: trace.setSpan(context.active(), ROOT_SPAN) } }); const response: PipelineResponse = { diff --git a/sdk/core/core-tracing/review/core-tracing.api.md b/sdk/core/core-tracing/review/core-tracing.api.md index b3f6de52d44d..be5bd88f2df6 100644 --- a/sdk/core/core-tracing/review/core-tracing.api.md +++ b/sdk/core/core-tracing/review/core-tracing.api.md @@ -33,42 +33,9 @@ export interface CreateSpanFunctionArgs { packagePrefix: string; } -// @public -export type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string; - -// @public -export interface ExceptionWithCode { - code: string | number; - message?: string; - name?: string; - stack?: string; -} - -// @public -export interface ExceptionWithMessage { - code?: string | number; - message: string; - name?: string; - stack?: string; -} - -// @public -export interface ExceptionWithName { - code?: string | number; - message?: string; - name: string; - stack?: string; -} - // @public export function extractSpanContextFromTraceParentHeader(traceParentHeader: string): SpanContext | undefined; -// @public -export function getSpan(context: Context): Span | undefined; - -// @public -export function getSpanContext(context: Context): SpanContext | undefined; - // @public export function getTraceParentHeader(spanContext: SpanContext): string | undefined; @@ -78,9 +45,6 @@ export function getTracer(): Tracer; // @public export function getTracer(name: string, version?: string): Tracer; -// @public -export type HrTime = [number, number]; - // @public export function isSpanContextValid(context: SpanContext): boolean; @@ -95,18 +59,12 @@ export interface OperationTracingOptions { tracingContext?: Context; } -// @public -export function setSpan(context: Context, span: Span): Context; - -// @public -export function setSpanContext(context: Context, spanContext: SpanContext): Context; - // @public export interface Span { - addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this; - end(endTime?: TimeInput): void; + addEvent(name: string, attributesOrStartTime?: SpanAttributes | Date, startTime?: Date): this; + end(endTime?: Date): void; isRecording(): boolean; - recordException(exception: Exception, time?: TimeInput): void; + recordException(exception: Error, time?: Date): void; setAttribute(key: string, value: SpanAttributeValue): this; setAttributes(attributes: SpanAttributes): this; setStatus(status: SpanStatus): this; @@ -116,11 +74,11 @@ export interface Span { // @public export interface SpanAttributes { - [attributeKey: string]: SpanAttributeValue | undefined; + [attributeKey: string]: SpanAttributeValue; } // @public -export type SpanAttributeValue = string | number | boolean | Array | Array | Array; +export type SpanAttributeValue = string | number | boolean; // @public export interface SpanContext { @@ -144,7 +102,7 @@ export interface SpanOptions { attributes?: SpanAttributes; kind?: SpanKind; links?: Link[]; - startTime?: TimeInput; + startTime?: Date; } // @public @@ -160,9 +118,6 @@ export enum SpanStatusCode { UNSET = 0 } -// @public -export type TimeInput = HrTime | number | Date; - // @public export const enum TraceFlags { NONE = 0, diff --git a/sdk/core/core-tracing/src/createSpan.ts b/sdk/core/core-tracing/src/createSpan.ts index 77f3e56d7d47..be581c00655e 100644 --- a/sdk/core/core-tracing/src/createSpan.ts +++ b/sdk/core/core-tracing/src/createSpan.ts @@ -5,7 +5,6 @@ import { OperationTracingOptions, Span, SpanOptions, - setSpan, context as otContext, getTracer, Context, @@ -199,7 +198,7 @@ export function createSpanFunction(args: CreateSpanFunctionArgs) { const newTracingOptions = { ...tracingOptions, spanOptions: newSpanOptions, - tracingContext: setSpan(tracingContext, span) + tracingContext: trace.setSpan(tracingContext, span) }; const newOperationOptions = { diff --git a/sdk/core/core-tracing/src/index.ts b/sdk/core/core-tracing/src/index.ts index 590c2eb032ef..8251bf55d4b7 100644 --- a/sdk/core/core-tracing/src/index.ts +++ b/sdk/core/core-tracing/src/index.ts @@ -9,19 +9,10 @@ export { context, Context, ContextAPI, - Exception, - ExceptionWithCode, - ExceptionWithMessage, - ExceptionWithName, - getSpan, - getSpanContext, getTracer, - HrTime, isSpanContextValid, Link, OperationTracingOptions, - setSpan, - setSpanContext, Span, SpanAttributes, SpanAttributeValue, @@ -30,7 +21,6 @@ export { SpanOptions, SpanStatus, SpanStatusCode, - TimeInput, TraceFlags, Tracer, TraceState diff --git a/sdk/core/core-tracing/src/interfaces.ts b/sdk/core/core-tracing/src/interfaces.ts index 4672755e2d3a..af55fd8bc19c 100644 --- a/sdk/core/core-tracing/src/interfaces.ts +++ b/sdk/core/core-tracing/src/interfaces.ts @@ -65,16 +65,6 @@ export interface TraceState { serialize(): string; } -/** - * Represents high resolution time. - */ -export declare type HrTime = [number, number]; - -/** - * Used to represent a Time. - */ -export type TimeInput = HrTime | number | Date; - /** * The status for a span. */ @@ -115,96 +105,6 @@ export enum SpanKind { CONSUMER = 4 } -/** - * An Exception for a Span. - */ -export declare type Exception = - | ExceptionWithCode - | ExceptionWithMessage - | ExceptionWithName - | string; - -/** - * An Exception with a code. - */ -export interface ExceptionWithCode { - /** The code. */ - code: string | number; - /** The name. */ - name?: string; - /** The message. */ - message?: string; - /** The stack. */ - stack?: string; -} - -/** - * An Exception with a message. - */ -export interface ExceptionWithMessage { - /** The code. */ - code?: string | number; - /** The message. */ - message: string; - /** The name. */ - name?: string; - /** The stack. */ - stack?: string; -} - -/** - * An Exception with a name. - */ -export interface ExceptionWithName { - /** The code. */ - code?: string | number; - /** The message. */ - message?: string; - /** The name. */ - name: string; - /** The stack. */ - stack?: string; -} - -/** - * Return the span if one exists - * - * @param context - context to get span from - */ -export function getSpan(context: Context): Span | undefined { - return otTrace.getSpan(context); -} - -/** - * Set the span on a context - * - * @param context - context to use as parent - * @param span - span to set active - */ -export function setSpan(context: Context, span: Span): Context { - return otTrace.setSpan(context, span); -} - -/** - * Wrap span context in a NoopSpan and set as span in a new - * context - * - * @param context - context to set active span on - * @param spanContext - span context to be wrapped - */ -export function setSpanContext(context: Context, spanContext: SpanContext): Context { - return otTrace.setSpanContext(context, spanContext); -} - -/** - * Get the span context of the span if it exists. - * - * @param context - context to get values from - */ -export function getSpanContext(context: Context): SpanContext | undefined { - return otTrace.getSpanContext(context); -} - /** * Singleton object which represents the entry point to the OpenTelemetry Context API */ @@ -303,14 +203,10 @@ export interface Span { * @param name - the name of the event. * @param attributesOrStartTime - the attributes that will be added; these are * associated with this event. Can be also a start time - * if type is TimeInput and 3rd param is undefined + * if type is Date and 3rd param is undefined * @param startTime - start time of the event. */ - addEvent( - name: string, - attributesOrStartTime?: SpanAttributes | TimeInput, - startTime?: TimeInput - ): this; + addEvent(name: string, attributesOrStartTime?: SpanAttributes | Date, startTime?: Date): this; /** * Sets a status to the span. If used, this will override the default Span * status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value @@ -331,7 +227,7 @@ export interface Span { * @param endTime - the time to set as Span's end time. If not provided, * use the current time as the span's end time. */ - end(endTime?: TimeInput): void; + end(endTime?: Date): void; /** * Returns the flag whether this span will be recorded. * @@ -342,11 +238,11 @@ export interface Span { /** * Sets exception as a span event - * @param exception - the exception the only accepted values are string or Error + * @param exception - the exception to record. * @param time - the time to set as Span's event time. If not provided, * use the current time. */ - recordException(exception: Exception, time?: TimeInput): void; + recordException(exception: Error, time?: Date): void; /** * Updates the Span name. @@ -372,7 +268,7 @@ export const enum TraceFlags { } /** - * A light interface that tries to be structurally compatible with OpenTelemetry + * A SpanContext represents the portion of a {@link Span} which must be serialized and propagated. */ export interface SpanContext { /** @@ -424,20 +320,13 @@ export interface SpanAttributes { /** * Attributes for a Span. */ - [attributeKey: string]: SpanAttributeValue | undefined; + [attributeKey: string]: SpanAttributeValue; } + /** - * Attribute values may be any non-nullish primitive value except an object. - * - * null or undefined attribute values are invalid and will result in undefined behavior. + * The types that can be used as a value for {@link SpanAttributes}. */ -export declare type SpanAttributeValue = - | string - | number - | boolean - | Array - | Array - | Array; +export type SpanAttributeValue = string | number | boolean; /** * An interface that enables manual propagation of Spans @@ -459,7 +348,7 @@ export interface SpanOptions { /** * A manually specified start time for the created `Span` object. */ - startTime?: TimeInput; + startTime?: Date; } /** diff --git a/sdk/core/core-tracing/test/createSpan.spec.ts b/sdk/core/core-tracing/test/createSpan.spec.ts index 62476592d227..b2b65eddcb2d 100644 --- a/sdk/core/core-tracing/test/createSpan.spec.ts +++ b/sdk/core/core-tracing/test/createSpan.spec.ts @@ -2,13 +2,8 @@ // Licensed under the MIT license. import { assert } from "chai"; -import { - setSpan, - SpanKind, - context as otContext, - getSpanContext, - Context -} from "../src/interfaces"; +import { SpanKind, context as otContext, Context } from "../src/interfaces"; +import { trace } from "@opentelemetry/api"; import { TestSpan } from "./util/testSpan"; import { createSpanFunction, isTracingDisabled, knownSpanAttributes } from "../src/createSpan"; @@ -31,7 +26,7 @@ describe("createSpan", () => { it("is backwards compatible at runtime with versions prior to preview.13", () => { const testSpan = tracerProvider.getTracer("test").startSpan("test"); - const someContext = setSpan(otContext.active(), testSpan); + const someContext = trace.setSpan(otContext.active(), testSpan); // Ensure we are backwards compatible with { tracingOptions: { spanOptions } } shape which was // used prior to preview.13 for setting span options. @@ -73,7 +68,7 @@ describe("createSpan", () => { it("returns a created span with the right metadata", () => { const testSpan = tracerProvider.getTracer("test").startSpan("testing"); - const someContext = setSpan(otContext.active(), testSpan); + const someContext = trace.setSpan(otContext.active(), testSpan); const { span, updatedOptions } = <{ span: TestSpan; updatedOptions: any }>createSpan( "testMethod", @@ -104,10 +99,9 @@ describe("createSpan", () => { it("preserves existing attributes", () => { const testSpan = tracerProvider.getTracer("test").startSpan("testing"); - const someContext = setSpan(otContext.active(), testSpan).setValue( - Symbol.for("someOtherKey"), - "someOtherValue" - ); + const someContext = trace + .setSpan(otContext.active(), testSpan) + .setValue(Symbol.for("someOtherKey"), "someOtherValue"); const { span, updatedOptions } = <{ span: TestSpan; updatedOptions: any }>( createSpan("testMethod", { @@ -178,7 +172,7 @@ describe("createSpan", () => { assert.ok(parentContext); assert.notDeepEqual(parentContext, otContext.active(), "new child context should be created"); assert.equal( - getSpanContext(parentContext!)?.spanId, + trace.getSpanContext(parentContext!)?.spanId, span.spanContext().spanId, "context returned in the updated options should point to our newly created span" ); @@ -193,7 +187,7 @@ describe("createSpan", () => { assert.ok(updatedOptions.tracingOptions.tracingContext); assert.equal( - getSpanContext(updatedOptions.tracingOptions.tracingContext!)?.spanId, + trace.getSpanContext(updatedOptions.tracingOptions.tracingContext!)?.spanId, childSpan.spanContext().spanId ); }); @@ -214,7 +208,7 @@ describe("createSpan", () => { const testSpan = tracerProvider.getTracer("test").startSpan("testing"); - const someContext = setSpan(otContext.active(), testSpan); + const someContext = trace.setSpan(otContext.active(), testSpan); const { span } = <{ span: TestSpan; updatedOptions: any }>createSpan("testMethod", { tracingOptions: ({ diff --git a/sdk/core/core-tracing/test/util/testSpan.ts b/sdk/core/core-tracing/test/util/testSpan.ts index 5a9abca70535..5f3ae61d9346 100644 --- a/sdk/core/core-tracing/test/util/testSpan.ts +++ b/sdk/core/core-tracing/test/util/testSpan.ts @@ -2,16 +2,15 @@ // Licensed under the MIT license. import { - TimeInput, Tracer, SpanKind, SpanStatus, SpanContext, SpanAttributes, SpanStatusCode, - SpanAttributeValue, Span, - SpanOptions + SpanOptions, + SpanAttributeValue } from "../../src/interfaces"; /** @@ -41,7 +40,7 @@ export class TestSpan implements Span { /** * The start time of the Span */ - readonly startTime: TimeInput; + readonly startTime: Date; /** * The id of the parent Span, if any. @@ -75,7 +74,7 @@ export class TestSpan implements Span { this._tracer = parentTracer; this.name = name; this.kind = options?.kind || SpanKind.INTERNAL; - this.startTime = options?.startTime || Date.now(); + this.startTime = options?.startTime || new Date(); this.parentSpanId = parentSpanId; this.attributes = options?.attributes || {}; this.status = { @@ -104,7 +103,7 @@ export class TestSpan implements Span { * @param _endTime - The time to use as the Span's end time. Defaults to * the current time. */ - end(_endTime?: number): void { + end(_endTime?: Date): void { this.endCalled = true; } diff --git a/sdk/core/core-tracing/test/util/testTracer.ts b/sdk/core/core-tracing/test/util/testTracer.ts index 6e1b855c6f68..63fb8f70921e 100644 --- a/sdk/core/core-tracing/test/util/testTracer.ts +++ b/sdk/core/core-tracing/test/util/testTracer.ts @@ -8,9 +8,9 @@ import { TraceFlags, Context as OTContext, context as otContext, - getSpanContext, Tracer } from "../../src/interfaces"; +import { trace } from "@opentelemetry/api"; /** * Simple representation of a Span that only has name and child relationships. @@ -125,7 +125,7 @@ export class TestTracer implements Tracer { * @param options - The SpanOptions used during Span creation. */ startSpan(name: string, options?: SpanOptions, context?: OTContext): TestSpan { - const parentContext = getSpanContext(context || otContext.active()); + const parentContext = trace.getSpanContext(context || otContext.active()); let traceId: string; let isRootSpan = false; diff --git a/sdk/digitaltwins/digital-twins-core/package.json b/sdk/digitaltwins/digital-twins-core/package.json index a46d4b2c4c1d..857c04829e84 100644 --- a/sdk/digitaltwins/digital-twins-core/package.json +++ b/sdk/digitaltwins/digital-twins-core/package.json @@ -76,6 +76,7 @@ "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@azure/identity": "2.0.0-beta.6", "@azure-tools/test-recorder": "^1.0.0", + "@azure/test-utils": "^1.0.0", "@microsoft/api-extractor": "7.7.11", "@rollup/plugin-commonjs": "11.0.2", "@rollup/plugin-json": "^4.0.0", diff --git a/sdk/digitaltwins/digital-twins-core/test/internal/digitalTwinsClient.spec.ts b/sdk/digitaltwins/digital-twins-core/test/internal/digitalTwinsClient.spec.ts index 765bc9ff5c27..53b74e465379 100644 --- a/sdk/digitaltwins/digital-twins-core/test/internal/digitalTwinsClient.spec.ts +++ b/sdk/digitaltwins/digital-twins-core/test/internal/digitalTwinsClient.spec.ts @@ -33,7 +33,7 @@ import { } from "../../src/generated/models"; import { DigitalTwinsClient } from "../../src/index"; import { createSpan } from "../../src/tracing"; -import { getSpanContext } from "@azure/core-tracing"; +import { trace } from "@azure/test-utils"; describe("DigitalTwinsClient", () => { let operationOptions: OperationOptions; @@ -749,8 +749,8 @@ function operationOptionsSinonMatcher( const expectedContext = _expectedOptions!.tracingOptions!.tracingContext!; assert.deepEqual( - getSpanContext(expectedContext), - getSpanContext(actualOptions.tracingOptions!.tracingContext!) + trace.getSpanContext(expectedContext), + trace.getSpanContext(actualOptions.tracingOptions!.tracingContext!) ); // check all the other properties that aren't interestingly unique diff --git a/sdk/eventgrid/eventgrid/test/public/eventGridClient.spec.ts b/sdk/eventgrid/eventgrid/test/public/eventGridClient.spec.ts index 96d39e1de156..2c9d19b068d8 100644 --- a/sdk/eventgrid/eventgrid/test/public/eventGridClient.spec.ts +++ b/sdk/eventgrid/eventgrid/test/public/eventGridClient.spec.ts @@ -8,13 +8,13 @@ import { Recorder } from "@azure-tools/test-recorder"; import { createRecordedClient, testEnv } from "./utils/recordedClient"; -import { resetTracer, setTracer } from "@azure/test-utils"; +import { resetTracer, setTracer, trace } from "@azure/test-utils"; import { AzureKeyCredential, EventGridPublisherClient } from "../../src"; import { FullOperationResponse } from "@azure/core-client"; import { RestError } from "@azure/core-rest-pipeline"; -import { setSpan, context } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; describe("EventGridPublisherClient", function(this: Suite) { let recorder: Recorder; @@ -218,7 +218,7 @@ describe("EventGridPublisherClient", function(this: Suite) { ], { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) }, onResponse: (response) => (res = response) } diff --git a/sdk/eventhub/event-hubs/test/internal/partitionPump.spec.ts b/sdk/eventhub/event-hubs/test/internal/partitionPump.spec.ts index 19cca3013964..4a1fd7fd8bc2 100644 --- a/sdk/eventhub/event-hubs/test/internal/partitionPump.spec.ts +++ b/sdk/eventhub/event-hubs/test/internal/partitionPump.spec.ts @@ -2,15 +2,8 @@ // Licensed under the MIT license. import { createProcessingSpan, trace } from "../../src/partitionPump"; -import { - SpanStatusCode, - SpanKind, - SpanOptions, - Context, - setSpanContext, - context -} from "@azure/core-tracing"; -import { TestSpan, TestTracer } from "@azure/test-utils"; +import { SpanStatusCode, SpanKind, SpanOptions, Context, context } from "@azure/core-tracing"; +import { TestSpan, TestTracer, trace as otTrace } from "@azure/test-utils"; import chai from "chai"; import { ReceivedEventData } from "../../src/eventData"; import { instrumentEventData } from "../../src/diagnostics/instrumentEventData"; @@ -42,7 +35,7 @@ testWithServiceTypes(() => { it("basic span properties are set", async () => { const { tracer, resetTracer } = setTracerForTest(new TestTracer2()); - const fakeParentSpanContext = setSpanContext( + const fakeParentSpanContext = otTrace.setSpanContext( context.active(), tracer.startSpan("test").spanContext() ); @@ -93,7 +86,7 @@ testWithServiceTypes(() => { { ...requiredEventProperties }, { tracingOptions: { - tracingContext: setSpanContext(context.active(), firstEvent.spanContext()) + tracingContext: otTrace.setSpanContext(context.active(), firstEvent.spanContext()) } }, "entityPath", @@ -104,7 +97,7 @@ testWithServiceTypes(() => { { ...requiredEventProperties }, { tracingOptions: { - tracingContext: setSpanContext(context.active(), thirdEvent.spanContext()) + tracingContext: otTrace.setSpanContext(context.active(), thirdEvent.spanContext()) } }, "entityPath", diff --git a/sdk/eventhub/event-hubs/test/internal/sender.spec.ts b/sdk/eventhub/event-hubs/test/internal/sender.spec.ts index 8fd70aad66cf..3813808d61f9 100644 --- a/sdk/eventhub/event-hubs/test/internal/sender.spec.ts +++ b/sdk/eventhub/event-hubs/test/internal/sender.spec.ts @@ -23,10 +23,10 @@ import { getStartingPositionsForTests, setTracerForTest } from "../public/utils/testUtils"; -import { SpanGraph, TestSpan } from "@azure/test-utils"; +import { SpanGraph, TestSpan, trace } from "@azure/test-utils"; import { TRACEPARENT_PROPERTY } from "../../src/diagnostics/instrumentEventData"; import { SubscriptionHandlerForTests } from "../public/utils/subscriptionHandlerForTests"; -import { setSpan, context } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; import { testWithServiceTypes } from "../public/utils/testWithServiceTypes"; import { createMockServer } from "../public/utils/mockService"; @@ -338,7 +338,7 @@ testWithServiceTypes((serviceVersion) => { { body: `${list[i].name}` }, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } } ); @@ -407,7 +407,7 @@ testWithServiceTypes((serviceVersion) => { function modernOptions(rootSpan: TestSpan): OperationOptions { return { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }; } @@ -483,7 +483,7 @@ testWithServiceTypes((serviceVersion) => { } await producerClient.sendBatch(eventDataBatch, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); @@ -668,7 +668,7 @@ testWithServiceTypes((serviceVersion) => { await producerClient.sendBatch(events, { partitionId: "0", tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); @@ -730,7 +730,7 @@ testWithServiceTypes((serviceVersion) => { await producerClient.sendBatch(events, { partitionId: "0", tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); @@ -887,7 +887,7 @@ testWithServiceTypes((serviceVersion) => { } await producerClient.sendBatch(events, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); @@ -957,7 +957,7 @@ testWithServiceTypes((serviceVersion) => { events[0].properties = { [TRACEPARENT_PROPERTY]: "foo" }; await producerClient.sendBatch(events, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); diff --git a/sdk/eventhub/event-hubs/test/public/hubruntime.spec.ts b/sdk/eventhub/event-hubs/test/public/hubruntime.spec.ts index 2914c1567841..6c3703571bb7 100644 --- a/sdk/eventhub/event-hubs/test/public/hubruntime.spec.ts +++ b/sdk/eventhub/event-hubs/test/public/hubruntime.spec.ts @@ -8,9 +8,9 @@ chai.use(chaiAsPromised); import debugModule from "debug"; const debug = debugModule("azure:event-hubs:hubruntime-spec"); import { EnvVarKeys, getEnvVars, setTracerForTest } from "./utils/testUtils"; -import { setSpan, context } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; -import { SpanGraph } from "@azure/test-utils"; +import { SpanGraph, trace } from "@azure/test-utils"; import { EventHubProducerClient, EventHubConsumerClient, MessagingError } from "../../src"; import { testWithServiceTypes } from "./utils/testWithServiceTypes"; import { createMockServer } from "./utils/mockService"; @@ -91,7 +91,7 @@ testWithServiceTypes((serviceVersion) => { const rootSpan = tracer.startSpan("root"); const ids = await producerClient.getPartitionIds({ tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); ids.should.have.members(arrayOfIncreasingNumbersFromZero(ids.length)); @@ -126,7 +126,7 @@ testWithServiceTypes((serviceVersion) => { const rootSpan = tracer.startSpan("root"); const ids = await consumerClient.getPartitionIds({ tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); ids.should.have.members(arrayOfIncreasingNumbersFromZero(ids.length)); @@ -189,7 +189,7 @@ testWithServiceTypes((serviceVersion) => { const rootSpan = tracer.startSpan("root"); const hubRuntimeInfo = await producerClient.getEventHubProperties({ tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); hubRuntimeInfo.partitionIds.should.have.members( @@ -226,7 +226,7 @@ testWithServiceTypes((serviceVersion) => { const rootSpan = tracer.startSpan("root"); const hubRuntimeInfo = await consumerClient.getEventHubProperties({ tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); hubRuntimeInfo.partitionIds.should.have.members( @@ -367,7 +367,7 @@ testWithServiceTypes((serviceVersion) => { const rootSpan = tracer.startSpan("root"); const partitionRuntimeInfo = await producerClient.getPartitionProperties("0", { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); partitionRuntimeInfo.partitionId.should.equal("0"); @@ -406,7 +406,7 @@ testWithServiceTypes((serviceVersion) => { const rootSpan = tracer.startSpan("root"); const partitionRuntimeInfo = await consumerClient.getPartitionProperties("0", { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); partitionRuntimeInfo.partitionId.should.equal("0"); diff --git a/sdk/identity/identity/test/msalTestUtils.ts b/sdk/identity/identity/test/msalTestUtils.ts index 666f65bc6afd..8008d5d66d3d 100644 --- a/sdk/identity/identity/test/msalTestUtils.ts +++ b/sdk/identity/identity/test/msalTestUtils.ts @@ -10,8 +10,8 @@ import { } from "@azure-tools/test-recorder"; import Sinon, { createSandbox } from "sinon"; import { assert } from "chai"; -import { OperationTracingOptions, setSpan, context as otContext } from "@azure/core-tracing"; -import { SpanGraph, setTracer } from "@azure/test-utils"; +import { OperationTracingOptions, context as otContext } from "@azure/core-tracing"; +import { SpanGraph, setTracer, trace } from "@azure/test-utils"; import { MsalBaseUtilities } from "../src/msal/utils"; export type MsalTestCleanup = () => Promise; @@ -169,7 +169,7 @@ export function testTracing(options: TestTracingOptions): () => Promise { const tracer = setTracer(); const rootSpan = tracer.startSpan("root"); - const tracingContext = setSpan(otContext.active(), rootSpan); + const tracingContext = trace.setSpan(otContext.active(), rootSpan); await test({ tracingContext diff --git a/sdk/keyvault/keyvault-admin/test/utils/supportsTracing.ts b/sdk/keyvault/keyvault-admin/test/utils/supportsTracing.ts index a4110b3af896..15d717811eb1 100644 --- a/sdk/keyvault/keyvault-admin/test/utils/supportsTracing.ts +++ b/sdk/keyvault/keyvault-admin/test/utils/supportsTracing.ts @@ -1,5 +1,5 @@ -import { setSpan, context as otContext, OperationTracingOptions } from "@azure/core-tracing"; -import { setTracer } from "@azure/test-utils"; +import { context as otContext, OperationTracingOptions } from "@azure/core-tracing"; +import { setTracer, trace } from "@azure/test-utils"; import { assert } from "chai"; const prefix = "Azure.KeyVault"; @@ -10,7 +10,7 @@ export async function supportsTracing( ): Promise { const tracer = setTracer(); const rootSpan = tracer.startSpan("root"); - const tracingContext = setSpan(otContext.active(), rootSpan); + const tracingContext = trace.setSpan(otContext.active(), rootSpan); try { await callback({ tracingContext }); diff --git a/sdk/keyvault/keyvault-common/test/utils/supportsTracing.ts b/sdk/keyvault/keyvault-common/test/utils/supportsTracing.ts index a4110b3af896..15d717811eb1 100644 --- a/sdk/keyvault/keyvault-common/test/utils/supportsTracing.ts +++ b/sdk/keyvault/keyvault-common/test/utils/supportsTracing.ts @@ -1,5 +1,5 @@ -import { setSpan, context as otContext, OperationTracingOptions } from "@azure/core-tracing"; -import { setTracer } from "@azure/test-utils"; +import { context as otContext, OperationTracingOptions } from "@azure/core-tracing"; +import { setTracer, trace } from "@azure/test-utils"; import { assert } from "chai"; const prefix = "Azure.KeyVault"; @@ -10,7 +10,7 @@ export async function supportsTracing( ): Promise { const tracer = setTracer(); const rootSpan = tracer.startSpan("root"); - const tracingContext = setSpan(otContext.active(), rootSpan); + const tracingContext = trace.setSpan(otContext.active(), rootSpan); try { await callback({ tracingContext }); diff --git a/sdk/servicebus/service-bus/src/diagnostics/instrumentServiceBusMessage.ts b/sdk/servicebus/service-bus/src/diagnostics/instrumentServiceBusMessage.ts index 44004faccce6..27d2f95287bd 100644 --- a/sdk/servicebus/service-bus/src/diagnostics/instrumentServiceBusMessage.ts +++ b/sdk/servicebus/service-bus/src/diagnostics/instrumentServiceBusMessage.ts @@ -7,7 +7,8 @@ import { Link, Span, SpanContext, - SpanKind + SpanKind, + SpanAttributes } from "@azure/core-tracing"; import { ConnectionContext } from "../connectionContext"; import { OperationOptionsBase } from "../modelsToBeSharedWithEventHubs"; @@ -84,12 +85,16 @@ export function createProcessingSpan( continue; } - links.push({ + const link: { context: SpanContext; attributes: SpanAttributes } = { context: spanContext, - attributes: { - enqueuedTime: receivedMessage.enqueuedTimeUtc?.getTime() - } - }); + attributes: {} + }; + + if (receivedMessage.enqueuedTimeUtc) { + link.attributes.enqueuedTime = receivedMessage.enqueuedTimeUtc.getTime(); + } + + links.push(link); } const { span } = createServiceBusSpan( diff --git a/sdk/servicebus/service-bus/test/internal/operationOptionsForATOM.spec.ts b/sdk/servicebus/service-bus/test/internal/operationOptionsForATOM.spec.ts index 1399e92c32fc..4d179e0d7385 100644 --- a/sdk/servicebus/service-bus/test/internal/operationOptionsForATOM.spec.ts +++ b/sdk/servicebus/service-bus/test/internal/operationOptionsForATOM.spec.ts @@ -11,8 +11,8 @@ import { AbortController } from "@azure/abort-controller"; import { WebResource } from "@azure/core-http"; import { executeAtomXmlOperation } from "../../src/util/atomXmlHelper"; import { NamespaceResourceSerializer } from "../../src/serializers/namespaceResourceSerializer"; -import { TestTracer, SpanGraph, setTracer } from "@azure/test-utils"; -import { setSpan, context } from "@azure/core-tracing"; +import { TestTracer, SpanGraph, setTracer, trace } from "@azure/test-utils"; +import { context } from "@azure/core-tracing"; chai.use(chaiAsPromised); chai.use(chaiExclude); @@ -245,7 +245,7 @@ describe("Operation Options", () => { setTracer(tracer); const rootSpan = tracer.startSpan("root"); await serviceBusAtomManagementClient.getNamespaceProperties({ - tracingOptions: { tracingContext: setSpan(context.active(), rootSpan) } + tracingOptions: { tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); diff --git a/sdk/servicebus/service-bus/test/internal/tracing.spec.ts b/sdk/servicebus/service-bus/test/internal/tracing.spec.ts index 619864b0328f..df73b8ff8190 100644 --- a/sdk/servicebus/service-bus/test/internal/tracing.spec.ts +++ b/sdk/servicebus/service-bus/test/internal/tracing.spec.ts @@ -1,5 +1,5 @@ -import { SpanGraph, TestSpan } from "@azure/test-utils"; -import { setSpan, Span, context } from "@azure/core-tracing"; +import { SpanGraph, TestSpan, trace } from "@azure/test-utils"; +import { Span, context } from "@azure/core-tracing"; import { ServiceBusSender, ServiceBusMessage, OperationOptions, TryAddOptions } from "../../src"; import { TRACEPARENT_PROPERTY } from "../public/sendAndSchedule.spec"; import { setTracerForTest } from "../public/utils/misc"; @@ -25,7 +25,7 @@ function legacyOptionsUsingSpan(rootSpan: TestSpan): Pick { @@ -176,7 +176,7 @@ function modernOptionsWithAccidentalParentSpanSet(rootSpan: TestSpan): TryAddOpt } await sender.sendMessages(batch, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); @@ -223,7 +223,7 @@ function modernOptionsWithAccidentalParentSpanSet(rootSpan: TestSpan): TryAddOpt } await sender.sendMessages(messages, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); @@ -295,7 +295,7 @@ function modernOptionsWithAccidentalParentSpanSet(rootSpan: TestSpan): TryAddOpt messages[0].applicationProperties = { [TRACEPARENT_PROPERTY]: "foo" }; await sender.sendMessages(messages, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); diff --git a/sdk/servicebus/service-bus/test/internal/unit/tracing.spec.ts b/sdk/servicebus/service-bus/test/internal/unit/tracing.spec.ts index 8d6c560ae8bb..a5ae681ba380 100644 --- a/sdk/servicebus/service-bus/test/internal/unit/tracing.spec.ts +++ b/sdk/servicebus/service-bus/test/internal/unit/tracing.spec.ts @@ -5,13 +5,11 @@ import chai from "chai"; import { context as otContext, Context as OTContext, - getSpanContext, getTracer, - setSpanContext, SpanOptions, SpanStatusCode } from "@azure/core-tracing"; -import { TestSpan, TestTracer } from "@azure/test-utils"; +import { TestSpan, TestTracer, trace as otTrace } from "@azure/test-utils"; import { ServiceBusMessageImpl, ServiceBusReceivedMessage } from "../../../src/serviceBusMessage"; import { createAndEndProcessingSpan, @@ -38,7 +36,7 @@ describe("Tracing tests", () => { let tracer: TestTracer2; let resetTracer: () => void; const tracingOptions: OperationOptionsBase["tracingOptions"] = { - tracingContext: setSpanContext(otContext.active(), { + tracingContext: otTrace.setSpanContext(otContext.active(), { spanId: "my parent span id", traceId: "my trace id", traceFlags: 0 @@ -104,7 +102,7 @@ describe("Tracing tests", () => { ); assert.equal( - getSpanContext(options?.tracingOptions?.tracingContext!)?.spanId, + otTrace.getSpanContext(options?.tracingOptions?.tracingContext!)?.spanId, "my parent span id", "Parent span should be properly passed in." ); @@ -287,7 +285,7 @@ describe("Tracing tests", () => { assert.isFalse(Array.isArray(messages)); assert.equal( - getSpanContext(options?.tracingOptions?.tracingContext!)!.spanId, + otTrace.getSpanContext(options?.tracingOptions?.tracingContext!)!.spanId, "my parent span id" ); @@ -313,14 +311,14 @@ describe("Tracing tests", () => { createProcessingSpan([], receiverProperties, connectionConfig, { tracingOptions: { - tracingContext: setSpanContext(otContext.active(), fakeParentSpanContext) + tracingContext: otTrace.setSpanContext(otContext.active(), fakeParentSpanContext) } }); should.equal(tracer.spanName, "Azure.ServiceBus.process"); should.exist(tracer.spanOptions); tracer.spanOptions!.kind!.should.equal(SpanKind.CONSUMER); - getSpanContext(tracer.context!)!.should.equal(fakeParentSpanContext); + otTrace.getSpanContext(tracer.context!)!.should.equal(fakeParentSpanContext); const attributes = tracer.getActiveSpans().find((s) => s.name === "Azure.ServiceBus.process") ?.attributes; diff --git a/sdk/storage/storage-blob-changefeed/test/blobchangefeedclient.spec.ts b/sdk/storage/storage-blob-changefeed/test/blobchangefeedclient.spec.ts index 5bc1ed675f54..a7c4ad3de6ce 100644 --- a/sdk/storage/storage-blob-changefeed/test/blobchangefeedclient.spec.ts +++ b/sdk/storage/storage-blob-changefeed/test/blobchangefeedclient.spec.ts @@ -6,10 +6,10 @@ import { record, isPlaybackMode, Recorder } from "@azure-tools/test-recorder"; import { recorderEnvSetup, getBlobChangeFeedClient } from "./utils"; import { BlobChangeFeedClient, BlobChangeFeedEvent, BlobChangeFeedEventPage } from "../src"; import { AbortController } from "@azure/abort-controller"; -import { setTracer } from "@azure/test-utils"; +import { setTracer, trace } from "@azure/test-utils"; import { Pipeline } from "@azure/storage-blob"; import { SDK_VERSION } from "../src/utils/constants"; -import { setSpan, context } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; import * as dotenv from "dotenv"; import { Context } from "mocha"; @@ -164,7 +164,7 @@ describe("BlobChangeFeedClient", async () => { const pageIter = changeFeedClient.listChanges({ tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); await pageIter.next(); diff --git a/sdk/storage/storage-blob/test/blobclient.spec.ts b/sdk/storage/storage-blob/test/blobclient.spec.ts index 24575b9da40a..9530cbc15d04 100644 --- a/sdk/storage/storage-blob/test/blobclient.spec.ts +++ b/sdk/storage/storage-blob/test/blobclient.spec.ts @@ -6,7 +6,7 @@ import * as dotenv from "dotenv"; import * as fs from "fs"; import { AbortController } from "@azure/abort-controller"; import { isNode, URLBuilder, URLQuery } from "@azure/core-http"; -import { SpanGraph, setTracer } from "@azure/test-utils"; +import { SpanGraph, setTracer, trace } from "@azure/test-utils"; import { bodyToString, getBSU, @@ -26,7 +26,7 @@ import { } from "../src"; import { Test_CPK_INFO } from "./utils/fakeTestSecrets"; import { base64encode } from "../src/utils/utils.common"; -import { context, setSpan } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; import { Context } from "mocha"; dotenv.config(); @@ -712,7 +712,7 @@ describe("BlobClient", () => { const result = await blobClient.download(undefined, undefined, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); assert.deepStrictEqual(await bodyToString(result, content.length), content); diff --git a/sdk/storage/storage-blob/test/containerclient.spec.ts b/sdk/storage/storage-blob/test/containerclient.spec.ts index 027b642f9b0a..bebf2bbeba6d 100644 --- a/sdk/storage/storage-blob/test/containerclient.spec.ts +++ b/sdk/storage/storage-blob/test/containerclient.spec.ts @@ -3,7 +3,7 @@ import * as assert from "assert"; import * as dotenv from "dotenv"; -import { TestTracer, SpanGraph, setTracer } from "@azure/test-utils"; +import { TestTracer, SpanGraph, setTracer, trace } from "@azure/test-utils"; import { bodyToString, getBSU, @@ -20,7 +20,7 @@ import { BlobServiceClient } from "../src"; import { Test_CPK_INFO } from "./utils/fakeTestSecrets"; -import { context, setSpan } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; import { Context } from "mocha"; dotenv.config(); @@ -724,7 +724,7 @@ describe("ContainerClient", () => { blobHTTPHeaders: options, metadata: options.metadata, tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); diff --git a/sdk/storage/storage-file-datalake/test/filesystemclient.spec.ts b/sdk/storage/storage-file-datalake/test/filesystemclient.spec.ts index 6221c56b7089..3ac814d5658c 100644 --- a/sdk/storage/storage-file-datalake/test/filesystemclient.spec.ts +++ b/sdk/storage/storage-file-datalake/test/filesystemclient.spec.ts @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { SpanGraph, setTracer } from "@azure/test-utils"; +import { SpanGraph, setTracer, trace } from "@azure/test-utils"; import { isLiveMode, record, Recorder } from "@azure-tools/test-recorder"; -import { setSpan, context } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; import * as assert from "assert"; import * as dotenv from "dotenv"; @@ -68,7 +68,7 @@ describe("DataLakeFileSystemClient", () => { }; await fileSystemClient.setMetadata(metadata, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); diff --git a/sdk/storage/storage-file-datalake/test/pathclient.spec.ts b/sdk/storage/storage-file-datalake/test/pathclient.spec.ts index d00cf211fb59..f9eda3cc8282 100644 --- a/sdk/storage/storage-file-datalake/test/pathclient.spec.ts +++ b/sdk/storage/storage-file-datalake/test/pathclient.spec.ts @@ -3,9 +3,9 @@ import { AbortController } from "@azure/abort-controller"; import { isNode, URLBuilder, delay } from "@azure/core-http"; -import { SpanGraph, setTracer } from "@azure/test-utils"; +import { SpanGraph, setTracer, trace } from "@azure/test-utils"; import { record, Recorder } from "@azure-tools/test-recorder"; -import { setSpan, context } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; import * as assert from "assert"; import * as dotenv from "dotenv"; @@ -156,7 +156,7 @@ describe("DataLakePathClient", () => { const result = await fileClient.read(undefined, undefined, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); assert.deepStrictEqual(await bodyToString(result, content.length), content); diff --git a/sdk/storage/storage-file-share/test/directoryclient.spec.ts b/sdk/storage/storage-file-share/test/directoryclient.spec.ts index ae471c199787..0dc886b29c95 100644 --- a/sdk/storage/storage-file-share/test/directoryclient.spec.ts +++ b/sdk/storage/storage-file-share/test/directoryclient.spec.ts @@ -8,11 +8,11 @@ import { ShareClient, ShareDirectoryClient, FileSystemAttributes } from "../src" import { record, Recorder } from "@azure-tools/test-recorder"; import { DirectoryCreateResponse } from "../src/generated/src/models"; import { truncatedISO8061Date } from "../src/utils/utils.common"; -import { SpanGraph, setTracer } from "@azure/test-utils"; +import { SpanGraph, setTracer, trace } from "@azure/test-utils"; import { URLBuilder } from "@azure/core-http"; import { MockPolicyFactory } from "./utils/MockPolicyFactory"; import { Pipeline } from "../src/Pipeline"; -import { setSpan, context } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; import { Context } from "mocha"; dotenv.config(); @@ -743,7 +743,7 @@ describe("DirectoryClient", () => { const tracer = setTracer(); const rootSpan = tracer.startSpan("root"); const tracingOptions = { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) }; const directoryName = recorder.getUniqueName("directory"); const { directoryClient: subDirClient } = await dirClient.createSubdirectory(directoryName, { diff --git a/sdk/storage/storage-file-share/test/fileclient.spec.ts b/sdk/storage/storage-file-share/test/fileclient.spec.ts index 5f7d5faeb886..6244a4a17f3f 100644 --- a/sdk/storage/storage-file-share/test/fileclient.spec.ts +++ b/sdk/storage/storage-file-share/test/fileclient.spec.ts @@ -6,7 +6,7 @@ import * as dotenv from "dotenv"; import { AbortController } from "@azure/abort-controller"; import { isNode, URLBuilder, URLQuery } from "@azure/core-http"; -import { SpanGraph, setTracer } from "@azure/test-utils"; +import { SpanGraph, setTracer, trace } from "@azure/test-utils"; import { delay, isLiveMode, record, Recorder } from "@azure-tools/test-recorder"; import { FileStartCopyOptions, ShareClient, ShareDirectoryClient, ShareFileClient } from "../src"; @@ -17,7 +17,7 @@ import { truncatedISO8061Date } from "../src/utils/utils.common"; import { bodyToString, compareBodyWithUint8Array, getBSU, recorderEnvSetup } from "./utils"; import { MockPolicyFactory } from "./utils/MockPolicyFactory"; import { FILE_MAX_SIZE_BYTES } from "../src/utils/constants"; -import { setSpan, context } from "@azure/core-tracing"; +import { context } from "@azure/core-tracing"; import { Context } from "mocha"; dotenv.config(); @@ -844,7 +844,7 @@ describe("FileClient", () => { const rootSpan = tracer.startSpan("root"); await fileClient.create(content.length, { tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); diff --git a/sdk/storage/storage-queue/test/queueclient.spec.ts b/sdk/storage/storage-queue/test/queueclient.spec.ts index 487b3488f036..f65962e22529 100644 --- a/sdk/storage/storage-queue/test/queueclient.spec.ts +++ b/sdk/storage/storage-queue/test/queueclient.spec.ts @@ -5,8 +5,8 @@ import * as assert from "assert"; import { getQSU, getSASConnectionStringFromEnvironment } from "./utils"; import * as dotenv from "dotenv"; import { QueueClient, QueueServiceClient } from "../src"; -import { setSpan, context } from "@azure/core-tracing"; -import { SpanGraph, setTracer } from "@azure/test-utils"; +import { context } from "@azure/core-tracing"; +import { SpanGraph, setTracer, trace } from "@azure/test-utils"; import { URLBuilder, RestError } from "@azure/core-http"; import { Recorder, record } from "@azure-tools/test-recorder"; import { recorderEnvSetup } from "./utils/testutils.common"; @@ -202,7 +202,7 @@ describe("QueueClient", () => { const rootSpan = tracer.startSpan("root"); await queueClient.getProperties({ tracingOptions: { - tracingContext: setSpan(context.active(), rootSpan) + tracingContext: trace.setSpan(context.active(), rootSpan) } }); rootSpan.end(); diff --git a/sdk/test-utils/test-utils/src/index.ts b/sdk/test-utils/test-utils/src/index.ts index 095e7d2a19d0..d2738af5b290 100644 --- a/sdk/test-utils/test-utils/src/index.ts +++ b/sdk/test-utils/test-utils/src/index.ts @@ -15,3 +15,4 @@ export { isNode, isNode8 } from "./utils"; export { TestSpan } from "./tracing/testSpan"; export * from "./tracing/testTracer"; export * from "./tracing/testTracerProvider"; +export { trace } from "@opentelemetry/api"; diff --git a/sdk/test-utils/test-utils/src/tracing/testSpan.ts b/sdk/test-utils/test-utils/src/tracing/testSpan.ts index 0aba5132910f..b2d186c9ef7c 100644 --- a/sdk/test-utils/test-utils/src/tracing/testSpan.ts +++ b/sdk/test-utils/test-utils/src/tracing/testSpan.ts @@ -2,15 +2,15 @@ // Licensed under the MIT license. import { - TimeInput, Tracer, SpanKind, SpanStatus, SpanContext, SpanAttributes, SpanStatusCode, + Span, SpanAttributeValue, - Span + TimeInput } from "@azure/core-tracing"; /** @@ -70,7 +70,7 @@ export class TestSpan implements Span { context: SpanContext, kind: SpanKind, parentSpanId?: string, - startTime: TimeInput = Date.now(), + startTime: TimeInput = new Date(), attributes: SpanAttributes = {} ) { this._tracer = parentTracer; @@ -105,7 +105,7 @@ export class TestSpan implements Span { * @param _endTime - The time to use as the Span's end time. Defaults to * the current time. */ - end(_endTime?: number): void { + end(_endTime?: Date): void { this.endCalled = true; } diff --git a/sdk/test-utils/test-utils/src/tracing/testTracer.ts b/sdk/test-utils/test-utils/src/tracing/testTracer.ts index 9ea2c62aeb93..9bd829bcce52 100644 --- a/sdk/test-utils/test-utils/src/tracing/testTracer.ts +++ b/sdk/test-utils/test-utils/src/tracing/testTracer.ts @@ -9,9 +9,9 @@ import { TraceFlags, Context as OTContext, context as otContext, - getSpanContext, Tracer } from "@azure/core-tracing"; +import { trace } from "@opentelemetry/api"; /** * Simple representation of a Span that only has name and child relationships. @@ -126,7 +126,7 @@ export class TestTracer implements Tracer { * @param options - The SpanOptions used during Span creation. */ startSpan(name: string, options?: SpanOptions, context?: OTContext): TestSpan { - const parentContext = getSpanContext(context || otContext.active()); + const parentContext = trace.getSpanContext(context || otContext.active()); let traceId: string; let isRootSpan = false;