Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] - Move core-tracing to @opentelemetry/api 0.20.0 #15672

Merged
merged 8 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion common/config/rush/common-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"@azure/identity": ["2.0.0-beta.3", "^1.1.0"],
// Issue #14771 tracks updating to these versions
"@microsoft/api-extractor": ["7.13.2"],
"prettier": ["2.2.1"]
"prettier": ["2.2.1"],
// All packages should move to 1.0.0-preview.12 once core-rest-pipeline 1.1.0 GAs
"@azure/core-tracing": ["1.0.0-preview.11"]
}
}
197 changes: 103 additions & 94 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sdk/anomalydetector/ai-anomaly-detector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@azure/core-paging": "^1.1.1",
"@azure/logger": "^1.0.0",
"tslib": "^2.2.0",
"@azure/core-tracing": "1.0.0-preview.11"
"@azure/core-tracing": "1.0.0-preview.12"
},
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions sdk/appconfiguration/app-configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@
"@azure/core-asynciterator-polyfill": "^1.0.0",
"@azure/core-http": "^1.2.0",
"@azure/core-paging": "^1.1.1",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"tslib": "^2.2.0"
},
"devDependencies": {
"@azure/dev-tool": "^1.0.0",
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
"@azure/identity": "2.0.0-beta.3",
"@azure/identity": "2.0.0-beta.4",
maorleger marked this conversation as resolved.
Show resolved Hide resolved
"@azure/keyvault-secrets": "^4.2.0",
"@azure/test-utils-recorder": "^1.0.0",
"@microsoft/api-extractor": "7.7.11",
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/communication-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@azure/communication-signaling": "1.0.0-beta.5",
"@azure/core-auth": "^1.3.0",
"@azure/core-http": "^1.2.0",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"@azure/logger": "^1.0.0",
"events": "^3.0.0",
"tslib": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/communication-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@azure/abort-controller": "^1.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-http": "^1.2.0",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"events": "^3.0.0",
"jwt-decode": "~2.2.0",
"tslib": "^2.2.0"
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/communication-identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@azure/core-http": "^1.2.0",
"@azure/core-lro": "^1.0.2",
"@azure/core-paging": "^1.1.1",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"@azure/logger": "^1.0.0",
"events": "^3.0.0",
"tslib": "^2.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@azure/communication-common": "^1.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-http": "^1.2.0",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"@azure/logger": "^1.0.0",
"events": "^3.0.0",
"tslib": "^2.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@azure/core-http": "^1.2.0",
"@azure/core-lro": "^1.0.2",
"@azure/core-paging": "^1.1.1",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"@azure/logger": "^1.0.0",
"events": "^3.0.0",
"tslib": "^2.2.0"
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/communication-sms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@azure/communication-common": "^1.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-http": "^1.2.0",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"@azure/logger": "^1.0.0",
"events": "^3.0.0",
"tslib": "^2.2.0"
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ Client libraries have preliminary support for [OpenTelemetry](https://openteleme

Each client library internally does the work to create a new OpenTelemetry `Span` for each service operation, making sure to end the `Span` after the result is returned back to the consumer. Many clients use a helper method called [createSpan](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/textanalytics/ai-text-analytics/src/tracing.ts) to create the new `Span`.

When `tracingOptions.spanOptions.parent` is set on an operation, a default request policy will automatically create a span for each HTTP request that is issued.
When `tracingOptions.tracingContext` is set on an operation, a default request policy will automatically create a span for each HTTP request that is issued.

Consumers are expected to pass in the `SpanContext` of the parent `Span` when calling an operation, such as:
Consumers are expected to pass in the `Context` of the parent `Span` when calling an operation, such as:

```ts
const result = await blobClient.download(undefined, undefined, {
tracingOptions: {
spanOptions: { parent: rootSpan.context() },
tracingContext: activeContext
},
});
```
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"@azure/abort-controller": "^1.0.0",
"@azure/core-asynciterator-polyfill": "^1.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"@azure/logger": "^1.0.0",
"@types/node-fetch": "^2.5.0",
"@types/tunnel": "^0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-http/src/policies/tracingPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class TracingPolicy extends BaseRequestPolicy {

try {
// set headers
const spanContext = span.context();
const spanContext = span.spanContext();
const traceParentHeader = getTraceParentHeader(spanContext);
if (traceParentHeader) {
request.headers.set("traceparent", traceParentHeader);
Expand Down
44 changes: 32 additions & 12 deletions sdk/core/core-http/test/policies/tracingPolicyTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,49 @@ import {
import {
setTracer,
NoOpTracer,
NoOpSpan,
SpanOptions,
SpanContext,
TraceFlags,
TraceState,
setSpan,
context,
SpanStatusCode,
SpanStatus
SpanStatus,
Span,
SpanAttributes,
SpanAttributeValue,
Tracer
} from "@azure/core-tracing";
import { tracingPolicy } from "../../src/policies/tracingPolicy";

class MockSpan extends NoOpSpan {
class MockSpan implements Span {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much simpler! Good discovery here

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("Not implemented.");
}

isRecording(): boolean {
return true;
}

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

updateName(): this {
throw new Error("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];
}

context(): SpanContext {
spanContext(): 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
2 changes: 1 addition & 1 deletion sdk/core/core-lro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-http": "^1.2.0",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"events": "^3.0.0",
"tslib": "^2.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-rest-pipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"dependencies": {
"@azure/abort-controller": "^1.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/core-tracing": "1.0.0-preview.12",
"@azure/logger": "^1.0.0",
"form-data": "^3.0.0",
"tslib": "^2.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function tracingPolicy(options: TracingPolicyOptions = {}): PipelinePolic

try {
// set headers
const spanContext = span.context();
const spanContext = span.spanContext();
const traceParentHeader = getTraceParentHeader(spanContext);
if (traceParentHeader) {
request.headers.set("traceparent", traceParentHeader);
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-rest-pipeline/test/tracingPolicy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MockSpan extends NoOpSpan {
return this._attributes[key];
}

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

const traceState = {
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"homepage": "https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-tracing/README.md",
"sideEffects": false,
"dependencies": {
"@opentelemetry/api": "1.0.0-rc.0",
"@opentelemetry/api": "0.20.0",
"tslib": "^2.2.0"
},
"devDependencies": {
Expand Down
14 changes: 4 additions & 10 deletions sdk/core/core-tracing/review/core-tracing.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,19 @@ export type HrTime = [number, number];
// @public
export interface Link {
attributes?: SpanAttributes;
context: LinkContext;
context: SpanContext;
}

// @public
export type LinkContext = {
traceId: string;
spanId: string;
};

// @public
export class NoOpSpan implements Span {
addEvent(_name: string, _attributes?: SpanAttributes): this;
context(): SpanContext;
end(_endTime?: number): void;
isRecording(): boolean;
recordException(_exception: Exception, _time?: TimeInput): void;
setAttribute(_key: string, _value: unknown): this;
setAttributes(_attributes: SpanAttributes): this;
setStatus(_status: SpanStatus): this;
spanContext(): SpanContext;
updateName(_name: string): this;
}

Expand Down Expand Up @@ -129,13 +123,13 @@ export function setTracer(tracer: Tracer): void;
// @public
export interface Span {
addEvent(name: string, attributesOrStartTime?: SpanAttributes | TimeInput, startTime?: TimeInput): this;
context(): SpanContext;
end(endTime?: TimeInput): void;
isRecording(): boolean;
recordException(exception: Exception, time?: TimeInput): void;
setAttribute(key: string, value: SpanAttributeValue): this;
setAttributes(attributes: SpanAttributes): this;
setStatus(status: SpanStatus): this;
spanContext(): SpanContext;
updateName(name: string): this;
}

Expand Down Expand Up @@ -200,7 +194,6 @@ export enum SpanStatusCode {
export class TestSpan extends NoOpSpan {
constructor(parentTracer: Tracer, name: string, context: SpanContext, kind: SpanKind, parentSpanId?: string, startTime?: TimeInput);
readonly attributes: SpanAttributes;
context(): SpanContext;
end(_endTime?: number): void;
endCalled: boolean;
isRecording(): boolean;
Expand All @@ -210,6 +203,7 @@ export class TestSpan extends NoOpSpan {
setAttribute(key: string, value: SpanAttributeValue): this;
setAttributes(attributes: SpanAttributes): this;
setStatus(status: SpanStatus): this;
spanContext(): SpanContext;
readonly startTime: TimeInput;
status: SpanStatus;
tracer(): Tracer;
Expand Down
1 change: 0 additions & 1 deletion sdk/core/core-tracing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export {
getSpanContext,
HrTime,
Link,
LinkContext,
OperationTracingOptions,
setSpan,
setSpanContext,
Expand Down
Loading