Skip to content

Commit

Permalink
copy changes to core-rest-pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
maorleger committed Jun 22, 2021
1 parent 03f34f2 commit 4dbb469
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,47 @@ import {
import {
setTracer,
NoOpTracer,
NoOpSpan,
Span,
Tracer,
SpanContext,
TraceFlags,
TraceState,
context,
setSpan,
SpanStatus,
SpanStatusCode
SpanStatusCode,
SpanAttributes,
SpanAttributeValue
} from "@azure/core-tracing";

class MockSpan extends NoOpSpan {
class MockSpan implements Span {
private _endCalled = false;
private _status: SpanStatus = {
code: SpanStatusCode.UNSET
};
private _attributes: { [s: string]: unknown } = {};
private _attributes: SpanAttributes = {};

constructor(
private traceId: string,
private spanId: string,
private flags: TraceFlags,
private state: string
) {
super();
) {}

addEvent(): this {
throw new Error("Method not implemented.");
}

isRecording(): boolean {
return true;
}

recordException(): void {
throw new Error("Method not implemented.");
}

updateName(): this {
throw new Error("Method not implemented.");
}

didEnd(): boolean {
Expand All @@ -57,7 +74,12 @@ class MockSpan extends NoOpSpan {
return this;
}

setAttribute(key: string, value: unknown) {
setAttributes(attributes: SpanAttributes): this {
this._attributes = attributes;
return this;
}

setAttribute(key: string, value: SpanAttributeValue) {
this._attributes[key] = value;
return this;
}
Expand All @@ -66,7 +88,7 @@ class MockSpan extends NoOpSpan {
return this._attributes[key];
}

spanContext(): SpanContext {
context(): SpanContext {
const state = this.state;

const traceState = {
Expand Down Expand Up @@ -95,7 +117,7 @@ class MockSpan extends NoOpSpan {
}
}

class MockTracer extends NoOpTracer {
class MockTracer implements Tracer {
private spans: MockSpan[] = [];
private _startSpanCalled = false;

Expand All @@ -104,9 +126,7 @@ class MockTracer extends NoOpTracer {
private spanId = "",
private flags = TraceFlags.NONE,
private state = ""
) {
super();
}
) {}

getStartedSpans(): MockSpan[] {
return this.spans;
Expand Down

0 comments on commit 4dbb469

Please sign in to comment.