Skip to content

Commit

Permalink
[core] Update @azure/core-tracing to use @opentelemetry/[email protected] (#1…
Browse files Browse the repository at this point in the history
…5883)

Now that `@opentelemetry/api` GA'd at [1.0.0](https://www.npmjs.com/package/@opentelemetry/api) we can bump our 
own dependency to `@opentelemetry/[email protected]`

Reminder: not _all_ packages are on the latest @opentelemetry/api... those that depend on @azure/core-rest-pipeline 
cannot be upgraded yet.
  • Loading branch information
maorleger authored Jun 22, 2021
1 parent 8ab9b83 commit ac8d65c
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 92 deletions.
6 changes: 4 additions & 2 deletions common/config/rush/common-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
// ]
// Following is required to allow for backward compatibility with Event Processor Host Track 1
"@azure/event-hubs": ["^2.1.4"],
"@opentelemetry/api": ["^0.18.1"],
// Monitor-opentelemetry-exporter and monitor-query both depend on different versions of @opentelemetry and need to be updated
"@opentelemetry/api": ["^0.18.1", "0.21.0"],
// Monitor: Allow node 10 types until Timeout / Timer conflict is resolved in OpenTelemetry repo
// TODO: remove when released https://github.com/open-telemetry/opentelemetry-js/pull/1352
// eslint v7.15 needs node v10.12
Expand All @@ -74,7 +75,8 @@
// Issue #14771 tracks updating to these versions
"@microsoft/api-extractor": ["7.13.2"],
"prettier": ["2.2.1"],
// All packages should move to 1.0.0-preview.12 once core-rest-pipeline 1.1.0 GAs
// All packages should move to 1.0.0 once core-rest-pipeline 1.1.0 GAs
"@azure/core-tracing": ["1.0.0-preview.11"]

}
}
151 changes: 79 additions & 72 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

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.12",
"@azure/core-tracing": "1.0.0-preview.11",
"@azure/logger": "^1.0.0",
"form-data": "^3.0.0",
"tslib": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-rest-pipeline/src/policies/tracingPolicy.ts
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.spanContext();
const spanContext = span.context();
const traceParentHeader = getTraceParentHeader(spanContext);
if (traceParentHeader) {
request.headers.set("traceparent", traceParentHeader);
Expand Down
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,
SpanContext,
TraceFlags,
Span,
TraceState,
context,
setSpan,
SpanStatus,
SpanStatusCode
SpanStatusCode,
SpanAttributes,
Tracer,
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
2 changes: 2 additions & 0 deletions sdk/core/core-tracing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 1.0.0-preview.12 (Unreleased)

- Update `@opentelemetry/api` to version 1.0.0 [PR #15883](https://github.com/Azure/azure-sdk-for-js/pull/15883)

### Breaking Changes

- Removed `OpenCensusSpanWrapper` and `OpenCensusTracerWrapper` from the public API. Customers using these wrappers should migrate to using `OpenTelemetry` directly. [PR #15770](https://github.com/Azure/azure-sdk-for-js/pull/15770)
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": "0.20.0",
"@opentelemetry/api": "^1.0.0",
"tslib": "^2.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-tracing/test/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fs from "fs";
import { Context } from "mocha";
import * as path from "path";

const validOpenTelemetryVersions = ["0.20.0"];
const validOpenTelemetryVersions = ["^1.0.0"];

describe("cache", () => {
it("ensure current @opentelemetry/api has been validated", function(this: Context) {
Expand Down
4 changes: 2 additions & 2 deletions sdk/monitor/monitor-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
"@azure/monitor-opentelemetry-exporter": "1.0.0-beta.4",
"@azure/test-utils-recorder": "^1.0.0",
"@microsoft/api-extractor": "7.7.11",
"@opentelemetry/api": "0.20.0",
"@opentelemetry/node": "0.20.0",
"@opentelemetry/api": "0.21.0",
"@opentelemetry/node": "0.21.0",
"@opentelemetry/tracing": "^0.18.2",
"@types/chai-as-promised": "^7.1.0",
"@types/chai": "^4.1.6",
Expand Down

0 comments on commit ac8d65c

Please sign in to comment.