From 61e142782a963b37e67c9de4e09f3bd6047683db Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Tue, 14 Sep 2021 13:06:14 -0700 Subject: [PATCH 01/10] wip --- .../core-tracing/review/core-tracing.api.md | 41 +-------- sdk/core/core-tracing/src/index.ts | 6 -- sdk/core/core-tracing/src/interfaces.ts | 90 +++++-------------- sdk/core/core-tracing/test/util/testSpan.ts | 7 +- 4 files changed, 27 insertions(+), 117 deletions(-) diff --git a/sdk/core/core-tracing/review/core-tracing.api.md b/sdk/core/core-tracing/review/core-tracing.api.md index b3f6de52d44d..07487e84acd5 100644 --- a/sdk/core/core-tracing/review/core-tracing.api.md +++ b/sdk/core/core-tracing/review/core-tracing.api.md @@ -33,33 +33,6 @@ 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; @@ -78,9 +51,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; @@ -103,10 +73,10 @@ export function setSpanContext(context: Context, spanContext: SpanContext): Cont // @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; @@ -144,7 +114,7 @@ export interface SpanOptions { attributes?: SpanAttributes; kind?: SpanKind; links?: Link[]; - startTime?: TimeInput; + startTime?: Date; } // @public @@ -160,9 +130,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/index.ts b/sdk/core/core-tracing/src/index.ts index 590c2eb032ef..cc8e0f112f85 100644 --- a/sdk/core/core-tracing/src/index.ts +++ b/sdk/core/core-tracing/src/index.ts @@ -9,14 +9,9 @@ export { context, Context, ContextAPI, - Exception, - ExceptionWithCode, - ExceptionWithMessage, - ExceptionWithName, getSpan, getSpanContext, getTracer, - HrTime, isSpanContextValid, Link, OperationTracingOptions, @@ -30,7 +25,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..234f09f7e9b7 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,57 +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 * @@ -213,6 +152,21 @@ export interface ContextAPI { * Get the currently active context */ active(): Context; + + /** + * Execute a function with an active context. + * + * @param context context to be active during function execution + * @param fn function to execute in a context + * @param thisArg optional receiver to be used for calling fn + * @param args optional arguments forwarded to fn + */ + with ReturnType>( + context: Context, + fn: F, + thisArg?: ThisParameterType, + ...args: A + ): ReturnType; } /** @@ -306,11 +260,7 @@ export interface Span { * if type is TimeInput 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 +281,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 +292,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. @@ -459,7 +409,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/util/testSpan.ts b/sdk/core/core-tracing/test/util/testSpan.ts index 5a9abca70535..d1bad06ede16 100644 --- a/sdk/core/core-tracing/test/util/testSpan.ts +++ b/sdk/core/core-tracing/test/util/testSpan.ts @@ -2,7 +2,6 @@ // Licensed under the MIT license. import { - TimeInput, Tracer, SpanKind, SpanStatus, @@ -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; } From 92b05a2f5b0bf4a55cecdeb95b672e1a0e076771 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Wed, 15 Sep 2021 15:57:40 -0700 Subject: [PATCH 02/10] wip --- sdk/core/core-tracing/package.json | 2 +- sdk/core/core-tracing/review/core-tracing.api.md | 8 +++----- sdk/core/core-tracing/src/index.ts | 1 - sdk/core/core-tracing/src/interfaces.ts | 16 ++-------------- sdk/core/core-tracing/test/util/testSpan.ts | 3 +-- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/sdk/core/core-tracing/package.json b/sdk/core/core-tracing/package.json index da6f929ce675..fc0716e21a1c 100644 --- a/sdk/core/core-tracing/package.json +++ b/sdk/core/core-tracing/package.json @@ -1,6 +1,6 @@ { "name": "@azure/core-tracing", - "version": "1.0.0-preview.14", + "version": "1.0.0-preview.13", "description": "Provides low-level interfaces and helper methods for tracing in Azure SDK", "sdk-type": "client", "main": "dist/index.js", diff --git a/sdk/core/core-tracing/review/core-tracing.api.md b/sdk/core/core-tracing/review/core-tracing.api.md index 07487e84acd5..f7e8a8af94ab 100644 --- a/sdk/core/core-tracing/review/core-tracing.api.md +++ b/sdk/core/core-tracing/review/core-tracing.api.md @@ -17,6 +17,7 @@ export const context: ContextAPI; // @public export interface ContextAPI { active(): Context; + with ReturnType>(context: Context, fn: F, thisArg?: ThisParameterType, ...args: A): ReturnType; } // @public @@ -77,7 +78,7 @@ export interface Span { end(endTime?: Date): void; isRecording(): boolean; recordException(exception: Error, time?: Date): void; - setAttribute(key: string, value: SpanAttributeValue): this; + setAttribute(key: string, value: string | number): this; setAttributes(attributes: SpanAttributes): this; setStatus(status: SpanStatus): this; spanContext(): SpanContext; @@ -86,12 +87,9 @@ export interface Span { // @public export interface SpanAttributes { - [attributeKey: string]: SpanAttributeValue | undefined; + [attributeKey: string]: string | number | boolean; } -// @public -export type SpanAttributeValue = string | number | boolean | Array | Array | Array; - // @public export interface SpanContext { spanId: string; diff --git a/sdk/core/core-tracing/src/index.ts b/sdk/core/core-tracing/src/index.ts index cc8e0f112f85..0356a0fa1cc5 100644 --- a/sdk/core/core-tracing/src/index.ts +++ b/sdk/core/core-tracing/src/index.ts @@ -19,7 +19,6 @@ export { setSpanContext, Span, SpanAttributes, - SpanAttributeValue, SpanContext, SpanKind, SpanOptions, diff --git a/sdk/core/core-tracing/src/interfaces.ts b/sdk/core/core-tracing/src/interfaces.ts index 234f09f7e9b7..83c39656ee5b 100644 --- a/sdk/core/core-tracing/src/interfaces.ts +++ b/sdk/core/core-tracing/src/interfaces.ts @@ -242,7 +242,7 @@ export interface Span { * @param value - the value for this attribute. Setting a value null or * undefined is invalid and will result in undefined behavior. */ - setAttribute(key: string, value: SpanAttributeValue): this; + setAttribute(key: string, value: string | number): this; /** * Sets attributes to the span. * @@ -374,20 +374,8 @@ export interface SpanAttributes { /** * Attributes for a Span. */ - [attributeKey: string]: SpanAttributeValue | undefined; + [attributeKey: string]: string | number | boolean; } -/** - * 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. - */ -export declare type SpanAttributeValue = - | string - | number - | boolean - | Array - | Array - | Array; /** * An interface that enables manual propagation of Spans diff --git a/sdk/core/core-tracing/test/util/testSpan.ts b/sdk/core/core-tracing/test/util/testSpan.ts index d1bad06ede16..3216faeeffb0 100644 --- a/sdk/core/core-tracing/test/util/testSpan.ts +++ b/sdk/core/core-tracing/test/util/testSpan.ts @@ -8,7 +8,6 @@ import { SpanContext, SpanAttributes, SpanStatusCode, - SpanAttributeValue, Span, SpanOptions } from "../../src/interfaces"; @@ -128,7 +127,7 @@ export class TestSpan implements Span { * @param key - The attribute key * @param value - The attribute value */ - setAttribute(key: string, value: SpanAttributeValue): this { + setAttribute(key: string, value: string | number): this { this.attributes[key] = value; return this; } From 9eb638bf4b838e537de7efdd393a7b616fee0c22 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Wed, 15 Sep 2021 16:31:03 -0700 Subject: [PATCH 03/10] wip --- .../test/policies/tracingPolicyTests.ts | 5 +-- .../test/tracingPolicy.spec.ts | 3 +- .../core-tracing/review/core-tracing.api.md | 11 +----- sdk/core/core-tracing/src/index.ts | 3 -- sdk/core/core-tracing/src/interfaces.ts | 39 +++---------------- sdk/core/core-tracing/test/createSpan.spec.ts | 13 ++----- sdk/core/core-tracing/test/util/testTracer.ts | 4 +- .../test-utils/src/tracing/testSpan.ts | 10 ++--- .../test-utils/src/tracing/testTracer.ts | 4 +- 9 files changed, 21 insertions(+), 71 deletions(-) diff --git a/sdk/core/core-http/test/policies/tracingPolicyTests.ts b/sdk/core/core-http/test/policies/tracingPolicyTests.ts index ee9b43769f5e..96fc0d82061e 100644 --- a/sdk/core/core-http/test/policies/tracingPolicyTests.ts +++ b/sdk/core/core-http/test/policies/tracingPolicyTests.ts @@ -17,8 +17,7 @@ import { context, SpanStatusCode, SpanStatus, - SpanAttributes, - SpanAttributeValue + SpanAttributes } from "@azure/core-tracing"; import { tracingPolicy } from "../../src/policies/tracingPolicy"; import { TracerProvider, Tracer, Span, SpanOptions, trace } from "@opentelemetry/api"; @@ -81,7 +80,7 @@ class MockSpan implements Span { return this; } - setAttribute(key: string, value: SpanAttributeValue) { + setAttribute(key: string, value: string | number) { this._attributes[key] = value; return this; } diff --git a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts index e6c8ccea2a47..a0252c80a627 100644 --- a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts +++ b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts @@ -20,7 +20,6 @@ import { SpanStatus, SpanStatusCode, SpanAttributes, - SpanAttributeValue, SpanOptions } from "@azure/core-tracing"; import { TracerProvider, Tracer, Span, trace } from "@opentelemetry/api"; @@ -82,7 +81,7 @@ class MockSpan implements Span { return this; } - setAttribute(key: string, value: SpanAttributeValue) { + setAttribute(key: string, value: string | number) { this._attributes[key] = value; return this; } diff --git a/sdk/core/core-tracing/review/core-tracing.api.md b/sdk/core/core-tracing/review/core-tracing.api.md index f7e8a8af94ab..803d4fd72862 100644 --- a/sdk/core/core-tracing/review/core-tracing.api.md +++ b/sdk/core/core-tracing/review/core-tracing.api.md @@ -17,7 +17,7 @@ export const context: ContextAPI; // @public export interface ContextAPI { active(): Context; - with ReturnType>(context: Context, fn: F, thisArg?: ThisParameterType, ...args: A): ReturnType; + with ReturnType>(context: Context, fn: TCallback, thisArg?: ThisParameterType, ...args: TArgs): ReturnType; } // @public @@ -37,12 +37,6 @@ export interface CreateSpanFunctionArgs { // @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; @@ -69,9 +63,6 @@ export interface OperationTracingOptions { // @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 | Date, startTime?: Date): this; diff --git a/sdk/core/core-tracing/src/index.ts b/sdk/core/core-tracing/src/index.ts index 0356a0fa1cc5..11dc00319454 100644 --- a/sdk/core/core-tracing/src/index.ts +++ b/sdk/core/core-tracing/src/index.ts @@ -9,14 +9,11 @@ export { context, Context, ContextAPI, - getSpan, - getSpanContext, getTracer, isSpanContextValid, Link, OperationTracingOptions, setSpan, - setSpanContext, Span, SpanAttributes, SpanContext, diff --git a/sdk/core/core-tracing/src/interfaces.ts b/sdk/core/core-tracing/src/interfaces.ts index 83c39656ee5b..a2c68f6a9fc3 100644 --- a/sdk/core/core-tracing/src/interfaces.ts +++ b/sdk/core/core-tracing/src/interfaces.ts @@ -105,15 +105,6 @@ export enum SpanKind { CONSUMER = 4 } -/** - * 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 * @@ -124,26 +115,6 @@ 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 */ @@ -161,12 +132,12 @@ export interface ContextAPI { * @param thisArg optional receiver to be used for calling fn * @param args optional arguments forwarded to fn */ - with ReturnType>( + with ReturnType>( context: Context, - fn: F, - thisArg?: ThisParameterType, - ...args: A - ): ReturnType; + fn: TCallback, + thisArg?: ThisParameterType, + ...args: TArgs + ): ReturnType; } /** diff --git a/sdk/core/core-tracing/test/createSpan.spec.ts b/sdk/core/core-tracing/test/createSpan.spec.ts index 62476592d227..76e5819cbb2e 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 { setSpan, 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"; @@ -178,7 +173,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 +188,7 @@ describe("createSpan", () => { assert.ok(updatedOptions.tracingOptions.tracingContext); assert.equal( - getSpanContext(updatedOptions.tracingOptions.tracingContext!)?.spanId, + trace.getSpanContext(updatedOptions.tracingOptions.tracingContext!)?.spanId, childSpan.spanContext().spanId ); }); 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/test-utils/test-utils/src/tracing/testSpan.ts b/sdk/test-utils/test-utils/src/tracing/testSpan.ts index 0aba5132910f..11047b581218 100644 --- a/sdk/test-utils/test-utils/src/tracing/testSpan.ts +++ b/sdk/test-utils/test-utils/src/tracing/testSpan.ts @@ -2,14 +2,12 @@ // Licensed under the MIT license. import { - TimeInput, Tracer, SpanKind, SpanStatus, SpanContext, SpanAttributes, SpanStatusCode, - SpanAttributeValue, Span } from "@azure/core-tracing"; @@ -40,7 +38,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. @@ -70,7 +68,7 @@ export class TestSpan implements Span { context: SpanContext, kind: SpanKind, parentSpanId?: string, - startTime: TimeInput = Date.now(), + startTime = new Date(), attributes: SpanAttributes = {} ) { this._tracer = parentTracer; @@ -105,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; } @@ -130,7 +128,7 @@ export class TestSpan implements Span { * @param key - The attribute key * @param value - The attribute value */ - setAttribute(key: string, value: SpanAttributeValue): this { + setAttribute(key: string, value: string | number): this { this.attributes[key] = value; return this; } 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; From 35d018ca4c0e2f91fc5d22fbf5cc3838d5aecb62 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Wed, 15 Sep 2021 16:39:41 -0700 Subject: [PATCH 04/10] fix builds --- sdk/core/core-http/test/policies/tracingPolicyTests.ts | 7 ++++--- sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/core/core-http/test/policies/tracingPolicyTests.ts b/sdk/core/core-http/test/policies/tracingPolicyTests.ts index 96fc0d82061e..6277ae8c5d5f 100644 --- a/sdk/core/core-http/test/policies/tracingPolicyTests.ts +++ b/sdk/core/core-http/test/policies/tracingPolicyTests.ts @@ -17,10 +17,11 @@ import { context, SpanStatusCode, SpanStatus, - SpanAttributes + SpanAttributes, + SpanOptions } 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 { @@ -80,7 +81,7 @@ class MockSpan implements Span { return this; } - setAttribute(key: string, value: string | number) { + setAttribute(key: string, value: string | number | boolean) { this._attributes[key] = value; return this; } diff --git a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts index a0252c80a627..787c105d245a 100644 --- a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts +++ b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts @@ -81,7 +81,7 @@ class MockSpan implements Span { return this; } - setAttribute(key: string, value: string | number) { + setAttribute(key: string, value: string | number | boolean) { this._attributes[key] = value; return this; } From efdb0eb5e09c1f943463ca86ae651f4490f0ea80 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 17 Sep 2021 11:19:57 -0700 Subject: [PATCH 05/10] builds without helper functions --- .../test/policies/tracingPolicyTests.ts | 26 ++++++------- .../test/tracingPolicy.spec.ts | 28 +++++++------- .../core-tracing/review/core-tracing.api.md | 3 -- sdk/core/core-tracing/src/createSpan.ts | 3 +- sdk/core/core-tracing/src/index.ts | 1 - sdk/core/core-tracing/src/interfaces.ts | 18 ++++----- sdk/core/core-tracing/test/createSpan.spec.ts | 15 ++++---- .../digital-twins-core/package.json | 1 + .../test/internal/digitalTwinsClient.spec.ts | 6 +-- .../test/public/eventGridClient.spec.ts | 6 +-- .../event-hubs/src/diagnostics/tracing.ts | 37 +++++++------------ .../test/internal/partitionPump.spec.ts | 17 +++------ .../event-hubs/test/internal/sender.spec.ts | 18 ++++----- .../event-hubs/test/public/hubruntime.spec.ts | 16 ++++---- sdk/identity/identity/test/msalTestUtils.ts | 6 +-- .../test/utils/supportsTracing.ts | 6 +-- .../test/utils/supportsTracing.ts | 6 +-- .../instrumentServiceBusMessage.ts | 2 +- .../service-bus/src/diagnostics/tracing.ts | 37 +++++++++---------- .../internal/operationOptionsForATOM.spec.ts | 6 +-- .../service-bus/test/internal/tracing.spec.ts | 14 +++---- .../test/internal/unit/tracing.spec.ts | 14 +++---- .../test/blobchangefeedclient.spec.ts | 6 +-- .../storage-blob/test/blobclient.spec.ts | 6 +-- .../storage-blob/test/containerclient.spec.ts | 6 +-- .../test/filesystemclient.spec.ts | 6 +-- .../test/pathclient.spec.ts | 6 +-- .../test/directoryclient.spec.ts | 6 +-- .../test/fileclient.spec.ts | 6 +-- .../storage-queue/test/queueclient.spec.ts | 6 +-- sdk/test-utils/test-utils/src/index.ts | 1 + 31 files changed, 153 insertions(+), 182 deletions(-) diff --git a/sdk/core/core-http/test/policies/tracingPolicyTests.ts b/sdk/core/core-http/test/policies/tracingPolicyTests.ts index 6277ae8c5d5f..ba7978891b3f 100644 --- a/sdk/core/core-http/test/policies/tracingPolicyTests.ts +++ b/sdk/core/core-http/test/policies/tracingPolicyTests.ts @@ -13,7 +13,6 @@ import { SpanContext, TraceFlags, TraceState, - setSpan, context, SpanStatusCode, SpanStatus, @@ -210,7 +209,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 +236,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 +264,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 +292,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 +335,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 +350,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 +365,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 +381,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 +397,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 +418,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 787c105d245a..47f6a0e596d8 100644 --- a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts +++ b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts @@ -16,7 +16,6 @@ import { TraceFlags, TraceState, context, - setSpan, SpanStatus, SpanStatusCode, SpanAttributes, @@ -211,7 +210,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 = { @@ -250,7 +249,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 = { @@ -289,7 +288,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 = { @@ -327,7 +326,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(); @@ -365,7 +364,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 = { @@ -390,7 +389,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 = { @@ -415,7 +414,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 = { @@ -442,7 +441,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 = { @@ -468,10 +467,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, { @@ -502,7 +500,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, { @@ -533,7 +531,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 803d4fd72862..2e8af24c0013 100644 --- a/sdk/core/core-tracing/review/core-tracing.api.md +++ b/sdk/core/core-tracing/review/core-tracing.api.md @@ -60,9 +60,6 @@ export interface OperationTracingOptions { tracingContext?: Context; } -// @public -export function setSpan(context: Context, span: Span): Context; - // @public export interface Span { addEvent(name: string, attributesOrStartTime?: SpanAttributes | Date, startTime?: Date): this; 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 11dc00319454..5a7ae485a8d8 100644 --- a/sdk/core/core-tracing/src/index.ts +++ b/sdk/core/core-tracing/src/index.ts @@ -13,7 +13,6 @@ export { isSpanContextValid, Link, OperationTracingOptions, - setSpan, Span, SpanAttributes, SpanContext, diff --git a/sdk/core/core-tracing/src/interfaces.ts b/sdk/core/core-tracing/src/interfaces.ts index a2c68f6a9fc3..013dbd30668b 100644 --- a/sdk/core/core-tracing/src/interfaces.ts +++ b/sdk/core/core-tracing/src/interfaces.ts @@ -105,15 +105,15 @@ export enum SpanKind { CONSUMER = 4 } -/** - * 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); -} +// /** +// * 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); +// } /** * Singleton object which represents the entry point to the OpenTelemetry Context API diff --git a/sdk/core/core-tracing/test/createSpan.spec.ts b/sdk/core/core-tracing/test/createSpan.spec.ts index 76e5819cbb2e..b2b65eddcb2d 100644 --- a/sdk/core/core-tracing/test/createSpan.spec.ts +++ b/sdk/core/core-tracing/test/createSpan.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import { assert } from "chai"; -import { setSpan, SpanKind, context as otContext, Context } from "../src/interfaces"; +import { SpanKind, context as otContext, Context } from "../src/interfaces"; import { trace } from "@opentelemetry/api"; import { TestSpan } from "./util/testSpan"; @@ -26,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. @@ -68,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", @@ -99,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", { @@ -209,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/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/src/diagnostics/tracing.ts b/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts index fce82fff3d49..0c3ac0fe6475 100644 --- a/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts +++ b/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts @@ -1,16 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { - createSpanFunction, - SpanContext, - SpanOptions, - setSpan, - setSpanContext, - Span, - SpanKind, - context -} from "@azure/core-tracing"; +import { createSpanFunction, SpanOptions, Span, SpanKind } from "@azure/core-tracing"; import { TryAddOptions } from "../eventDataBatch"; import { EventHubConnectionConfig } from "../eventhubConnectionConfig"; import { OperationOptions } from "../util/operationOptions"; @@ -115,22 +106,22 @@ export function convertTryAddOptionsForCompatibility(tryAddOptions: TryAddOption } const convertedOptions: TryAddOptions = { - ...tryAddOptions, - tracingOptions: { - tracingContext: isSpan(legacyParentSpanOrSpanContext) - ? setSpan(context.active(), legacyParentSpanOrSpanContext) - : setSpanContext(context.active(), legacyParentSpanOrSpanContext) - } + ...tryAddOptions + // tracingOptions: { + // tracingContext: isSpan(legacyParentSpanOrSpanContext) + // ? setSpan(context.active(), legacyParentSpanOrSpanContext) + // : setSpanContext(context.active(), legacyParentSpanOrSpanContext) + // } }; return convertedOptions; } -function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span { - if (possibleSpan == null) { - return false; - } +// function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span { +// if (possibleSpan == null) { +// return false; +// } - const x = possibleSpan as Span; - return typeof x.spanContext === "function"; -} +// const x = possibleSpan as Span; +// return typeof x.spanContext === "function"; +// } 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..9c73e1861124 100644 --- a/sdk/servicebus/service-bus/src/diagnostics/instrumentServiceBusMessage.ts +++ b/sdk/servicebus/service-bus/src/diagnostics/instrumentServiceBusMessage.ts @@ -87,7 +87,7 @@ export function createProcessingSpan( links.push({ context: spanContext, attributes: { - enqueuedTime: receivedMessage.enqueuedTimeUtc?.getTime() + enqueuedTime: receivedMessage.enqueuedTimeUtc?.getTime() || Date.now() } }); } diff --git a/sdk/servicebus/service-bus/src/diagnostics/tracing.ts b/sdk/servicebus/service-bus/src/diagnostics/tracing.ts index 2a32f86b50ab..e8e3c5568470 100644 --- a/sdk/servicebus/service-bus/src/diagnostics/tracing.ts +++ b/sdk/servicebus/service-bus/src/diagnostics/tracing.ts @@ -7,12 +7,9 @@ import { extractSpanContextFromTraceParentHeader, getTraceParentHeader, SpanOptions, - setSpan, Span, SpanContext, - SpanKind, - context as otContext, - setSpanContext + SpanKind } from "@azure/core-tracing"; import { ServiceBusMessage } from "../serviceBusMessage"; import { TryAddOptions } from "../modelsToBeSharedWithEventHubs"; @@ -220,23 +217,23 @@ export function convertTryAddOptionsForCompatibility(tryAddOptions: TryAddOption return tryAddOptions; } - const convertedOptions: TryAddOptions = { - ...tryAddOptions, - tracingOptions: { - tracingContext: isSpan(legacyParentSpanOrSpanContext) - ? setSpan(otContext.active(), legacyParentSpanOrSpanContext) - : setSpanContext(otContext.active(), legacyParentSpanOrSpanContext) - } - }; + // const convertedOptions: TryAddOptions = { + // ...tryAddOptions, + // tracingOptions: { + // tracingContext: isSpan(legacyParentSpanOrSpanContext) + // ? setSpan(otContext.active(), legacyParentSpanOrSpanContext) + // : setSpanContext(otContext.active(), legacyParentSpanOrSpanContext) + // } + // }; - return convertedOptions; + return tryAddOptions; } -function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span { - if (possibleSpan == null) { - return false; - } +// function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span { +// if (possibleSpan == null) { +// return false; +// } - const x = possibleSpan as Span; - return typeof x.spanContext === "function"; -} +// const x = possibleSpan as Span; +// return typeof x.spanContext === "function"; +// } 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"; From ec84f870ecf65086b6f49a36cdf1ce8bd79daa36 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 17 Sep 2021 11:33:24 -0700 Subject: [PATCH 06/10] put SpanAttributeValue back --- .../core-tracing/review/core-tracing.api.md | 8 ++-- sdk/core/core-tracing/src/index.ts | 1 + sdk/core/core-tracing/src/interfaces.ts | 38 +++++-------------- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/sdk/core/core-tracing/review/core-tracing.api.md b/sdk/core/core-tracing/review/core-tracing.api.md index 2e8af24c0013..be5bd88f2df6 100644 --- a/sdk/core/core-tracing/review/core-tracing.api.md +++ b/sdk/core/core-tracing/review/core-tracing.api.md @@ -17,7 +17,6 @@ export const context: ContextAPI; // @public export interface ContextAPI { active(): Context; - with ReturnType>(context: Context, fn: TCallback, thisArg?: ThisParameterType, ...args: TArgs): ReturnType; } // @public @@ -66,7 +65,7 @@ export interface Span { end(endTime?: Date): void; isRecording(): boolean; recordException(exception: Error, time?: Date): void; - setAttribute(key: string, value: string | number): this; + setAttribute(key: string, value: SpanAttributeValue): this; setAttributes(attributes: SpanAttributes): this; setStatus(status: SpanStatus): this; spanContext(): SpanContext; @@ -75,9 +74,12 @@ export interface Span { // @public export interface SpanAttributes { - [attributeKey: string]: string | number | boolean; + [attributeKey: string]: SpanAttributeValue; } +// @public +export type SpanAttributeValue = string | number | boolean; + // @public export interface SpanContext { spanId: string; diff --git a/sdk/core/core-tracing/src/index.ts b/sdk/core/core-tracing/src/index.ts index 5a7ae485a8d8..8251bf55d4b7 100644 --- a/sdk/core/core-tracing/src/index.ts +++ b/sdk/core/core-tracing/src/index.ts @@ -15,6 +15,7 @@ export { OperationTracingOptions, Span, SpanAttributes, + SpanAttributeValue, SpanContext, SpanKind, SpanOptions, diff --git a/sdk/core/core-tracing/src/interfaces.ts b/sdk/core/core-tracing/src/interfaces.ts index 013dbd30668b..6bad6d2806ef 100644 --- a/sdk/core/core-tracing/src/interfaces.ts +++ b/sdk/core/core-tracing/src/interfaces.ts @@ -105,16 +105,6 @@ export enum SpanKind { CONSUMER = 4 } -// /** -// * 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); -// } - /** * Singleton object which represents the entry point to the OpenTelemetry Context API */ @@ -123,21 +113,6 @@ export interface ContextAPI { * Get the currently active context */ active(): Context; - - /** - * Execute a function with an active context. - * - * @param context context to be active during function execution - * @param fn function to execute in a context - * @param thisArg optional receiver to be used for calling fn - * @param args optional arguments forwarded to fn - */ - with ReturnType>( - context: Context, - fn: TCallback, - thisArg?: ThisParameterType, - ...args: TArgs - ): ReturnType; } /** @@ -213,7 +188,7 @@ export interface Span { * @param value - the value for this attribute. Setting a value null or * undefined is invalid and will result in undefined behavior. */ - setAttribute(key: string, value: string | number): this; + setAttribute(key: string, value: SpanAttributeValue): this; /** * Sets attributes to the span. * @@ -228,7 +203,7 @@ 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 | Date, startTime?: Date): this; @@ -345,9 +320,16 @@ export interface SpanAttributes { /** * Attributes for a Span. */ - [attributeKey: string]: string | number | boolean; + [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. + */ +export type SpanAttributeValue = string | number | boolean; + /** * An interface that enables manual propagation of Spans */ From 1d4758388cbe9ba362a0dbadd095a717b66f437e Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 17 Sep 2021 11:37:35 -0700 Subject: [PATCH 07/10] restore SpanAttributeValue --- sdk/core/core-http/test/policies/tracingPolicyTests.ts | 5 +++-- sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts | 5 +++-- sdk/core/core-tracing/test/util/testSpan.ts | 5 +++-- sdk/test-utils/test-utils/src/tracing/testSpan.ts | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/sdk/core/core-http/test/policies/tracingPolicyTests.ts b/sdk/core/core-http/test/policies/tracingPolicyTests.ts index ba7978891b3f..09f1b43610eb 100644 --- a/sdk/core/core-http/test/policies/tracingPolicyTests.ts +++ b/sdk/core/core-http/test/policies/tracingPolicyTests.ts @@ -17,7 +17,8 @@ import { SpanStatusCode, SpanStatus, SpanAttributes, - SpanOptions + SpanOptions, + SpanAttributeValue } from "@azure/core-tracing"; import { tracingPolicy } from "../../src/policies/tracingPolicy"; import { TracerProvider, Tracer, Span, trace } from "@opentelemetry/api"; @@ -80,7 +81,7 @@ class MockSpan implements Span { return this; } - setAttribute(key: string, value: string | number | boolean) { + setAttribute(key: string, value: SpanAttributeValue) { this._attributes[key] = value; return this; } diff --git a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts index 47f6a0e596d8..41c6c1a20237 100644 --- a/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts +++ b/sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts @@ -19,7 +19,8 @@ import { SpanStatus, SpanStatusCode, SpanAttributes, - SpanOptions + SpanOptions, + SpanAttributeValue } from "@azure/core-tracing"; import { TracerProvider, Tracer, Span, trace } from "@opentelemetry/api"; @@ -80,7 +81,7 @@ class MockSpan implements Span { return this; } - setAttribute(key: string, value: string | number | boolean) { + setAttribute(key: string, value: SpanAttributeValue) { this._attributes[key] = value; return this; } diff --git a/sdk/core/core-tracing/test/util/testSpan.ts b/sdk/core/core-tracing/test/util/testSpan.ts index 3216faeeffb0..5f3ae61d9346 100644 --- a/sdk/core/core-tracing/test/util/testSpan.ts +++ b/sdk/core/core-tracing/test/util/testSpan.ts @@ -9,7 +9,8 @@ import { SpanAttributes, SpanStatusCode, Span, - SpanOptions + SpanOptions, + SpanAttributeValue } from "../../src/interfaces"; /** @@ -127,7 +128,7 @@ export class TestSpan implements Span { * @param key - The attribute key * @param value - The attribute value */ - setAttribute(key: string, value: string | number): this { + setAttribute(key: string, value: SpanAttributeValue): this { this.attributes[key] = value; return this; } diff --git a/sdk/test-utils/test-utils/src/tracing/testSpan.ts b/sdk/test-utils/test-utils/src/tracing/testSpan.ts index 11047b581218..26c07f63d854 100644 --- a/sdk/test-utils/test-utils/src/tracing/testSpan.ts +++ b/sdk/test-utils/test-utils/src/tracing/testSpan.ts @@ -8,7 +8,8 @@ import { SpanContext, SpanAttributes, SpanStatusCode, - Span + Span, + SpanAttributeValue } from "@azure/core-tracing"; /** @@ -128,7 +129,7 @@ export class TestSpan implements Span { * @param key - The attribute key * @param value - The attribute value */ - setAttribute(key: string, value: string | number): this { + setAttribute(key: string, value: SpanAttributeValue): this { this.attributes[key] = value; return this; } From b023fadd552e7f93671c0b55bb928f3e87e97e3e Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 17 Sep 2021 13:00:45 -0700 Subject: [PATCH 08/10] a little bit of cleanup --- sdk/core/core-tracing/src/interfaces.ts | 6 +-- .../event-hubs/src/diagnostics/tracing.ts | 50 +++++++++++++------ .../instrumentServiceBusMessage.ts | 17 ++++--- .../service-bus/src/diagnostics/tracing.ts | 50 ++++++++++++------- 4 files changed, 82 insertions(+), 41 deletions(-) diff --git a/sdk/core/core-tracing/src/interfaces.ts b/sdk/core/core-tracing/src/interfaces.ts index 6bad6d2806ef..af55fd8bc19c 100644 --- a/sdk/core/core-tracing/src/interfaces.ts +++ b/sdk/core/core-tracing/src/interfaces.ts @@ -268,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 { /** @@ -324,9 +324,7 @@ export interface SpanAttributes { } /** - * 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 type SpanAttributeValue = string | number | boolean; diff --git a/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts b/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts index 0c3ac0fe6475..cdc12acdf2e7 100644 --- a/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts +++ b/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts @@ -1,10 +1,18 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { createSpanFunction, SpanOptions, Span, SpanKind } from "@azure/core-tracing"; +import { + createSpanFunction, + SpanOptions, + Span, + SpanKind, + SpanContext, + Context +} from "@azure/core-tracing"; import { TryAddOptions } from "../eventDataBatch"; import { EventHubConnectionConfig } from "../eventhubConnectionConfig"; import { OperationOptions } from "../util/operationOptions"; +import { context } from "@azure/core-tracing"; const _createSpan = createSpanFunction({ namespace: "Microsoft.EventHub", @@ -106,22 +114,36 @@ export function convertTryAddOptionsForCompatibility(tryAddOptions: TryAddOption } const convertedOptions: TryAddOptions = { - ...tryAddOptions - // tracingOptions: { - // tracingContext: isSpan(legacyParentSpanOrSpanContext) - // ? setSpan(context.active(), legacyParentSpanOrSpanContext) - // : setSpanContext(context.active(), legacyParentSpanOrSpanContext) - // } + ...tryAddOptions, + tracingOptions: { + tracingContext: isSpan(legacyParentSpanOrSpanContext) + ? setSpan(context.active(), legacyParentSpanOrSpanContext) + : setSpanContext(context.active(), legacyParentSpanOrSpanContext) + } }; return convertedOptions; } -// function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span { -// if (possibleSpan == null) { -// return false; -// } +function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span { + if (possibleSpan == null) { + return false; + } + + const x = possibleSpan as Span; + return typeof x.spanContext === "function"; +} + +// TODO: remove this before taking out of draft. +function setSpan(arg0: Context, legacyParentSpanOrSpanContext: Span): Context | undefined { + console.log(arg0, legacyParentSpanOrSpanContext); + return arg0; +} -// const x = possibleSpan as Span; -// return typeof x.spanContext === "function"; -// } +function setSpanContext( + arg0: Context, + legacyParentSpanOrSpanContext: SpanContext +): Context | undefined { + console.log(arg0, legacyParentSpanOrSpanContext); + return arg0; +} diff --git a/sdk/servicebus/service-bus/src/diagnostics/instrumentServiceBusMessage.ts b/sdk/servicebus/service-bus/src/diagnostics/instrumentServiceBusMessage.ts index 9c73e1861124..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() || Date.now() - } - }); + attributes: {} + }; + + if (receivedMessage.enqueuedTimeUtc) { + link.attributes.enqueuedTime = receivedMessage.enqueuedTimeUtc.getTime(); + } + + links.push(link); } const { span } = createServiceBusSpan( diff --git a/sdk/servicebus/service-bus/src/diagnostics/tracing.ts b/sdk/servicebus/service-bus/src/diagnostics/tracing.ts index e8e3c5568470..af895e146a1a 100644 --- a/sdk/servicebus/service-bus/src/diagnostics/tracing.ts +++ b/sdk/servicebus/service-bus/src/diagnostics/tracing.ts @@ -9,7 +9,9 @@ import { SpanOptions, Span, SpanContext, - SpanKind + SpanKind, + Context, + context as otContext } from "@azure/core-tracing"; import { ServiceBusMessage } from "../serviceBusMessage"; import { TryAddOptions } from "../modelsToBeSharedWithEventHubs"; @@ -217,23 +219,37 @@ export function convertTryAddOptionsForCompatibility(tryAddOptions: TryAddOption return tryAddOptions; } - // const convertedOptions: TryAddOptions = { - // ...tryAddOptions, - // tracingOptions: { - // tracingContext: isSpan(legacyParentSpanOrSpanContext) - // ? setSpan(otContext.active(), legacyParentSpanOrSpanContext) - // : setSpanContext(otContext.active(), legacyParentSpanOrSpanContext) - // } - // }; + const convertedOptions: TryAddOptions = { + ...tryAddOptions, + tracingOptions: { + tracingContext: isSpan(legacyParentSpanOrSpanContext) + ? setSpan(otContext.active(), legacyParentSpanOrSpanContext) + : setSpanContext(otContext.active(), legacyParentSpanOrSpanContext) + } + }; - return tryAddOptions; + return convertedOptions; } -// function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span { -// if (possibleSpan == null) { -// return false; -// } +function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is Span { + if (possibleSpan == null) { + return false; + } -// const x = possibleSpan as Span; -// return typeof x.spanContext === "function"; -// } + const x = possibleSpan as Span; + return typeof x.spanContext === "function"; +} + +// TODO: remove this before taking out of draft. +function setSpan(arg0: Context, legacyParentSpanOrSpanContext: Span): Context | undefined { + console.log(arg0, legacyParentSpanOrSpanContext); + return arg0; +} + +function setSpanContext( + arg0: Context, + legacyParentSpanOrSpanContext: SpanContext +): Context | undefined { + console.log(arg0, legacyParentSpanOrSpanContext); + return arg0; +} From 7eedf6733900efaa74e469f5958ece251d2f655b Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 17 Sep 2021 13:38:53 -0700 Subject: [PATCH 09/10] put core-tracing back to preview.14 --- sdk/core/core-tracing/package.json | 2 +- sdk/test-utils/test-utils/src/tracing/testSpan.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/core/core-tracing/package.json b/sdk/core/core-tracing/package.json index fc0716e21a1c..da6f929ce675 100644 --- a/sdk/core/core-tracing/package.json +++ b/sdk/core/core-tracing/package.json @@ -1,6 +1,6 @@ { "name": "@azure/core-tracing", - "version": "1.0.0-preview.13", + "version": "1.0.0-preview.14", "description": "Provides low-level interfaces and helper methods for tracing in Azure SDK", "sdk-type": "client", "main": "dist/index.js", diff --git a/sdk/test-utils/test-utils/src/tracing/testSpan.ts b/sdk/test-utils/test-utils/src/tracing/testSpan.ts index 26c07f63d854..b2d186c9ef7c 100644 --- a/sdk/test-utils/test-utils/src/tracing/testSpan.ts +++ b/sdk/test-utils/test-utils/src/tracing/testSpan.ts @@ -9,7 +9,8 @@ import { SpanAttributes, SpanStatusCode, Span, - SpanAttributeValue + SpanAttributeValue, + TimeInput } from "@azure/core-tracing"; /** @@ -39,7 +40,7 @@ export class TestSpan implements Span { /** * The start time of the Span */ - readonly startTime: Date; + readonly startTime: TimeInput; /** * The id of the parent Span, if any. @@ -69,7 +70,7 @@ export class TestSpan implements Span { context: SpanContext, kind: SpanKind, parentSpanId?: string, - startTime = new Date(), + startTime: TimeInput = new Date(), attributes: SpanAttributes = {} ) { this._tracer = parentTracer; From b5b5c842bb3f9d063fdfc2fbebba802ec95d4272 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Fri, 17 Sep 2021 14:42:38 -0700 Subject: [PATCH 10/10] restore sb and eh tracing code --- .../event-hubs/src/diagnostics/tracing.ts | 21 ++++--------------- .../service-bus/src/diagnostics/tracing.ts | 19 +++-------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts b/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts index cdc12acdf2e7..fce82fff3d49 100644 --- a/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts +++ b/sdk/eventhub/event-hubs/src/diagnostics/tracing.ts @@ -3,16 +3,17 @@ import { createSpanFunction, + SpanContext, SpanOptions, + setSpan, + setSpanContext, Span, SpanKind, - SpanContext, - Context + context } from "@azure/core-tracing"; import { TryAddOptions } from "../eventDataBatch"; import { EventHubConnectionConfig } from "../eventhubConnectionConfig"; import { OperationOptions } from "../util/operationOptions"; -import { context } from "@azure/core-tracing"; const _createSpan = createSpanFunction({ namespace: "Microsoft.EventHub", @@ -133,17 +134,3 @@ function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is S const x = possibleSpan as Span; return typeof x.spanContext === "function"; } - -// TODO: remove this before taking out of draft. -function setSpan(arg0: Context, legacyParentSpanOrSpanContext: Span): Context | undefined { - console.log(arg0, legacyParentSpanOrSpanContext); - return arg0; -} - -function setSpanContext( - arg0: Context, - legacyParentSpanOrSpanContext: SpanContext -): Context | undefined { - console.log(arg0, legacyParentSpanOrSpanContext); - return arg0; -} diff --git a/sdk/servicebus/service-bus/src/diagnostics/tracing.ts b/sdk/servicebus/service-bus/src/diagnostics/tracing.ts index af895e146a1a..2a32f86b50ab 100644 --- a/sdk/servicebus/service-bus/src/diagnostics/tracing.ts +++ b/sdk/servicebus/service-bus/src/diagnostics/tracing.ts @@ -7,11 +7,12 @@ import { extractSpanContextFromTraceParentHeader, getTraceParentHeader, SpanOptions, + setSpan, Span, SpanContext, SpanKind, - Context, - context as otContext + context as otContext, + setSpanContext } from "@azure/core-tracing"; import { ServiceBusMessage } from "../serviceBusMessage"; import { TryAddOptions } from "../modelsToBeSharedWithEventHubs"; @@ -239,17 +240,3 @@ function isSpan(possibleSpan: Span | SpanContext | undefined): possibleSpan is S const x = possibleSpan as Span; return typeof x.spanContext === "function"; } - -// TODO: remove this before taking out of draft. -function setSpan(arg0: Context, legacyParentSpanOrSpanContext: Span): Context | undefined { - console.log(arg0, legacyParentSpanOrSpanContext); - return arg0; -} - -function setSpanContext( - arg0: Context, - legacyParentSpanOrSpanContext: SpanContext -): Context | undefined { - console.log(arg0, legacyParentSpanOrSpanContext); - return arg0; -}