From 8b42fd6437311bc6ed642864fca15ee58e0e02a5 Mon Sep 17 00:00:00 2001 From: Aaron Abbott Date: Wed, 28 Oct 2020 02:18:23 +0000 Subject: [PATCH] chore: upgrade for opentelemtry js v0.12.0 --- .../package-lock.json | 46 ++++---- .../package.json | 16 +-- .../src/monitoring.ts | 2 +- .../src/transform.ts | 16 +-- .../test/transform.test.ts | 29 ----- .../package-lock.json | 56 ++++----- .../package.json | 14 +-- .../src/trace.ts | 2 +- .../test/transform.test.ts | 3 + .../package-lock.json | 24 ++-- .../package.json | 8 +- .../src/CloudPropagator.ts | 6 +- .../test/CloudPropagator.test.ts | 54 +++++---- samples/trace/package-lock.json | 106 +++++++++++------- samples/trace/package.json | 6 +- 15 files changed, 183 insertions(+), 205 deletions(-) diff --git a/packages/opentelemetry-cloud-monitoring-exporter/package-lock.json b/packages/opentelemetry-cloud-monitoring-exporter/package-lock.json index 400612bb..20ec7e11 100644 --- a/packages/opentelemetry-cloud-monitoring-exporter/package-lock.json +++ b/packages/opentelemetry-cloud-monitoring-exporter/package-lock.json @@ -300,50 +300,50 @@ "dev": true }, "@opentelemetry/api": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.11.0.tgz", - "integrity": "sha512-K+1ADLMxduhsXoZ0GRfi9Pw162FvzBQLDQlHru1lg86rpIU+4XqdJkSGo6y3Kg+GmOWq1HNHOA/ydw/rzHQkRg==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.12.0.tgz", + "integrity": "sha512-Dn4vU5GlaBrIWzLpsM6xbJwKHdlpwBQ4Bd+cL9ofJP3hKT8jBXpBpribmyaqAzrajzzl2Yt8uTa9rFVLfjDAvw==", "dev": true, "requires": { - "@opentelemetry/context-base": "^0.11.0" + "@opentelemetry/context-base": "^0.12.0" } }, "@opentelemetry/context-base": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/context-base/-/context-base-0.11.0.tgz", - "integrity": "sha512-ESRk+572bftles7CVlugAj5Azrz61VO0MO0TS2pE9MLVL/zGmWuUBQryART6/nsrFqo+v9HPt37GPNcECTZR1w==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/context-base/-/context-base-0.12.0.tgz", + "integrity": "sha512-UXwSsXo3F3yZ1dIBOG9ID8v2r9e+bqLWoizCtTb8rXtwF+N5TM7hzzvQz72o3nBU+zrI/D5e+OqAYK8ZgDd3DA==", "dev": true }, "@opentelemetry/core": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-0.11.0.tgz", - "integrity": "sha512-ZEKjBXeDGBqzouz0uJmrbEKNExEsQOhsZ3tJDCLcz5dUNoVw642oIn2LYWdQK2YdIfZbEmltiF65/csGsaBtFA==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-0.12.0.tgz", + "integrity": "sha512-oLZIkmTNWTJXzo1eA4dGu/S7wOVtylsgnEsCmhSJGhrJVDXm1eW/aGuNs3DVBeuxp0ZvQLAul3/PThsC3YrnzA==", "dev": true, "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/context-base": "^0.11.0", + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/context-base": "^0.12.0", "semver": "^7.1.3" } }, "@opentelemetry/metrics": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/metrics/-/metrics-0.11.0.tgz", - "integrity": "sha512-OlEG1yVrfxkeQinx0c9/J37RPPnFKh0wRov0t2FHf2n2OnS831xhT9jSsopYlrJ5fe3NY0HuHshDoMpBOJXaGg==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/metrics/-/metrics-0.12.0.tgz", + "integrity": "sha512-S+xEReh5Oyqiqg5mGGb5CcjA0Ki8k/iGcS3k7Pa1JhXaovzoJzCV/7CEgShTMN8PVRitlHzvqk3Bl1FioY2MNA==", "dev": true, "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0", - "@opentelemetry/resources": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0", + "@opentelemetry/resources": "^0.12.0" } }, "@opentelemetry/resources": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-0.11.0.tgz", - "integrity": "sha512-o7DwV1TcezqBtS5YW2AWBcn01nVpPptIbTr966PLlVBcS//w8LkjeOShiSZxQ0lmV4b2en0FiSouSDoXk/5qIQ==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-0.12.0.tgz", + "integrity": "sha512-8cYvIKB68cyupc7D6SWzkLtt13mbjgxMahL4JKCM6hWPyiGSJlPFEAey4XFXI5LLpPZRYTPHLVoLqI/xwCFZZA==", "dev": true, "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0" } }, "@sindresorhus/is": { diff --git a/packages/opentelemetry-cloud-monitoring-exporter/package.json b/packages/opentelemetry-cloud-monitoring-exporter/package.json index 0afad8b6..fbcf24aa 100644 --- a/packages/opentelemetry-cloud-monitoring-exporter/package.json +++ b/packages/opentelemetry-cloud-monitoring-exporter/package.json @@ -37,10 +37,10 @@ "registry": "https://wombat-dressing-room.appspot.com" }, "devDependencies": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0", - "@opentelemetry/metrics": "^0.11.0", - "@opentelemetry/resources": "^0.11.0", + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0", + "@opentelemetry/metrics": "^0.12.0", + "@opentelemetry/resources": "^0.12.0", "@types/mocha": "7.0.2", "@types/nock": "11.1.0", "@types/node": "12.12.51", @@ -60,9 +60,9 @@ "googleapis": "^46.0.0" }, "peerDependencies": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0", - "@opentelemetry/metrics": "^0.11.0", - "@opentelemetry/resources": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0", + "@opentelemetry/metrics": "^0.12.0", + "@opentelemetry/resources": "^0.12.0" } } diff --git a/packages/opentelemetry-cloud-monitoring-exporter/src/monitoring.ts b/packages/opentelemetry-cloud-monitoring-exporter/src/monitoring.ts index 87bf7aac..e7b6699a 100644 --- a/packages/opentelemetry-cloud-monitoring-exporter/src/monitoring.ts +++ b/packages/opentelemetry-cloud-monitoring-exporter/src/monitoring.ts @@ -140,7 +140,7 @@ export class MetricExporter implements IMetricExporter { cb(ExportResult.SUCCESS); } - shutdown(): void {} + async shutdown(): Promise {} /** * Returns true if the given metricDescriptor is successfully registered to diff --git a/packages/opentelemetry-cloud-monitoring-exporter/src/transform.ts b/packages/opentelemetry-cloud-monitoring-exporter/src/transform.ts index fba050c3..ec23f8e0 100644 --- a/packages/opentelemetry-cloud-monitoring-exporter/src/transform.ts +++ b/packages/opentelemetry-cloud-monitoring-exporter/src/transform.ts @@ -16,7 +16,6 @@ import { MetricDescriptor as OTMetricDescriptor, MetricKind as OTMetricKind, MetricRecord, - Distribution as OTDistribution, Histogram as OTHistogram, Point as OTPoint, PointValueType, @@ -232,10 +231,6 @@ function transformPoint( /** Transforms a OpenTelemetry Point's value to a StackDriver Point value. */ function transformValue(valueType: OTValueType, value: PointValueType) { - if (isDistributionValue(value)) { - throw Error('unsupported distribution value type'); - // no buckets aggregated, which is a required param in `distributionValue` for Cloud Monitoring v3 - } if (isHistogramValue(value)) { return { distributionValue: { @@ -258,17 +253,8 @@ function transformValue(valueType: OTValueType, value: PointValueType) { throw Error(`unsupported value type: ${valueType}`); } -/** Returns true if value is of type OTDistribution */ -function isDistributionValue( - value: number | OTDistribution | OTHistogram -): value is OTDistribution { - return Object.prototype.hasOwnProperty.call(value, 'min'); -} - /** Returns true if value is of type OTHistogram */ -function isHistogramValue( - value: number | OTDistribution | OTHistogram -): value is OTHistogram { +function isHistogramValue(value: PointValueType): value is OTHistogram { return Object.prototype.hasOwnProperty.call(value, 'buckets'); } diff --git a/packages/opentelemetry-cloud-monitoring-exporter/test/transform.test.ts b/packages/opentelemetry-cloud-monitoring-exporter/test/transform.test.ts index af496029..aa211e2f 100644 --- a/packages/opentelemetry-cloud-monitoring-exporter/test/transform.test.ts +++ b/packages/opentelemetry-cloud-monitoring-exporter/test/transform.test.ts @@ -24,7 +24,6 @@ import { MetricDescriptor as OTMetricDescriptor, Point as OTPoint, MeterProvider, - Distribution, Histogram, } from '@opentelemetry/metrics'; import { ValueType as OTValueType, Labels } from '@opentelemetry/api'; @@ -342,34 +341,6 @@ describe('transform', () => { assert(result.interval.startTime); }); - it('should export a distribution value', () => { - const metricDescriptor: OTMetricDescriptor = { - name: METRIC_NAME, - description: METRIC_DESCRIPTION, - unit: DEFAULT_UNIT, - metricKind: OTMetricKind.COUNTER, - valueType: OTValueType.DOUBLE, - }; - const point: OTPoint = { - value: { - min: 20.0, - max: 75.4, - last: 40.3, - count: 22, - sum: 150, - }, - timestamp: process.hrtime(), - }; - - assert.throws(() => { - return TEST_ONLY.transformPoint( - point, - metricDescriptor, - new Date().toISOString() - ); - }, /unsupported distribution value type/); - }); - it('should export a histogram value', () => { const metricDescriptor: OTMetricDescriptor = { name: METRIC_NAME, diff --git a/packages/opentelemetry-cloud-trace-exporter/package-lock.json b/packages/opentelemetry-cloud-trace-exporter/package-lock.json index e24a7a1a..aa07957e 100644 --- a/packages/opentelemetry-cloud-trace-exporter/package-lock.json +++ b/packages/opentelemetry-cloud-trace-exporter/package-lock.json @@ -325,58 +325,58 @@ "dev": true }, "@opentelemetry/api": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.11.0.tgz", - "integrity": "sha512-K+1ADLMxduhsXoZ0GRfi9Pw162FvzBQLDQlHru1lg86rpIU+4XqdJkSGo6y3Kg+GmOWq1HNHOA/ydw/rzHQkRg==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.12.0.tgz", + "integrity": "sha512-Dn4vU5GlaBrIWzLpsM6xbJwKHdlpwBQ4Bd+cL9ofJP3hKT8jBXpBpribmyaqAzrajzzl2Yt8uTa9rFVLfjDAvw==", "dev": true, "requires": { - "@opentelemetry/context-base": "^0.11.0" + "@opentelemetry/context-base": "^0.12.0" } }, "@opentelemetry/context-base": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/context-base/-/context-base-0.11.0.tgz", - "integrity": "sha512-ESRk+572bftles7CVlugAj5Azrz61VO0MO0TS2pE9MLVL/zGmWuUBQryART6/nsrFqo+v9HPt37GPNcECTZR1w==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/context-base/-/context-base-0.12.0.tgz", + "integrity": "sha512-UXwSsXo3F3yZ1dIBOG9ID8v2r9e+bqLWoizCtTb8rXtwF+N5TM7hzzvQz72o3nBU+zrI/D5e+OqAYK8ZgDd3DA==", "dev": true }, "@opentelemetry/core": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-0.11.0.tgz", - "integrity": "sha512-ZEKjBXeDGBqzouz0uJmrbEKNExEsQOhsZ3tJDCLcz5dUNoVw642oIn2LYWdQK2YdIfZbEmltiF65/csGsaBtFA==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-0.12.0.tgz", + "integrity": "sha512-oLZIkmTNWTJXzo1eA4dGu/S7wOVtylsgnEsCmhSJGhrJVDXm1eW/aGuNs3DVBeuxp0ZvQLAul3/PThsC3YrnzA==", "dev": true, "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/context-base": "^0.11.0", + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/context-base": "^0.12.0", "semver": "^7.1.3" } }, "@opentelemetry/resources": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-0.11.0.tgz", - "integrity": "sha512-o7DwV1TcezqBtS5YW2AWBcn01nVpPptIbTr966PLlVBcS//w8LkjeOShiSZxQ0lmV4b2en0FiSouSDoXk/5qIQ==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-0.12.0.tgz", + "integrity": "sha512-8cYvIKB68cyupc7D6SWzkLtt13mbjgxMahL4JKCM6hWPyiGSJlPFEAey4XFXI5LLpPZRYTPHLVoLqI/xwCFZZA==", "dev": true, "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0" } }, "@opentelemetry/semantic-conventions": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-0.11.0.tgz", - "integrity": "sha512-xsthnI/J+Cx0YVDGgUzvrH0ZTtfNtl866M454NarYwDrc0JvC24sYw+XS5PJyk2KDzAHtb0vlrumUc1OAut/Fw==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-0.12.0.tgz", + "integrity": "sha512-BuCcDW0uLNYYTns0/LwXkJ8lp8aDm7kpS+WunEmPAPRSCe6ciOYRvzn5reqJfX93rf+6A3U2SgrBnCTH+0qoQQ==", "dev": true }, "@opentelemetry/tracing": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/tracing/-/tracing-0.11.0.tgz", - "integrity": "sha512-QweFmxzl32BcyzwdWCNjVXZT1WeENNS/RWETq/ohqu+fAsTcMyGcr6cOq/yDdFmtBy+bm5WVVdeByEjNS+c4/w==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/tracing/-/tracing-0.12.0.tgz", + "integrity": "sha512-2TUGhTGkhgnxTciHCNAILPSeyXageJewRqfP9wOrx65sKd/jgvNYoY8nYf4EVWVMirDOxKDsmYgUkjdQrwb2dg==", "dev": true, "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/context-base": "^0.11.0", - "@opentelemetry/core": "^0.11.0", - "@opentelemetry/resources": "^0.11.0", - "@opentelemetry/semantic-conventions": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/context-base": "^0.12.0", + "@opentelemetry/core": "^0.12.0", + "@opentelemetry/resources": "^0.12.0", + "@opentelemetry/semantic-conventions": "^0.12.0" } }, "@protobufjs/aspromise": { diff --git a/packages/opentelemetry-cloud-trace-exporter/package.json b/packages/opentelemetry-cloud-trace-exporter/package.json index c05858a3..49943c84 100644 --- a/packages/opentelemetry-cloud-trace-exporter/package.json +++ b/packages/opentelemetry-cloud-trace-exporter/package.json @@ -37,9 +37,9 @@ "registry": "https://wombat-dressing-room.appspot.com" }, "devDependencies": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/resources": "^0.11.0", - "@opentelemetry/tracing": "^0.11.0", + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/resources": "^0.12.0", + "@opentelemetry/tracing": "^0.12.0", "@types/mocha": "7.0.2", "@types/node": "12.12.51", "@types/sinon": "9.0.4", @@ -61,9 +61,9 @@ "grpc": "^1.24.3" }, "peerDependencies": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0", - "@opentelemetry/resources": "^0.11.0", - "@opentelemetry/tracing": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0", + "@opentelemetry/resources": "^0.12.0", + "@opentelemetry/tracing": "^0.12.0" } } diff --git a/packages/opentelemetry-cloud-trace-exporter/src/trace.ts b/packages/opentelemetry-cloud-trace-exporter/src/trace.ts index 591a4527..3d2d2ff1 100644 --- a/packages/opentelemetry-cloud-trace-exporter/src/trace.ts +++ b/packages/opentelemetry-cloud-trace-exporter/src/trace.ts @@ -80,7 +80,7 @@ export class TraceExporter implements SpanExporter { resultCallback(result); } - shutdown(): void {} + async shutdown(): Promise {} /** * Sends new spans to new or existing traces in the Google Cloud Trace format to the diff --git a/packages/opentelemetry-cloud-trace-exporter/test/transform.test.ts b/packages/opentelemetry-cloud-trace-exporter/test/transform.test.ts index 2b3328d8..d9bafdd2 100644 --- a/packages/opentelemetry-cloud-trace-exporter/test/transform.test.ts +++ b/packages/opentelemetry-cloud-trace-exporter/test/transform.test.ts @@ -130,6 +130,7 @@ describe('transform', () => { }); it('should drop unknown attribute types', () => { + // @ts-expect-error readableSpan.attributes.testUnknownType = { message: 'dropped' }; const result = transformer(readableSpan); assert.deepStrictEqual(result.attributes!.droppedAttributesCount, 1); @@ -172,6 +173,7 @@ describe('transform', () => { }, attributes: { testAttr: 'value', + // @ts-expect-error droppedAttr: {}, }, }); @@ -230,6 +232,7 @@ describe('transform', () => { name: 'something happened', attributes: { error: true, + // @ts-expect-error dropped: {}, }, time: [1566156729, 809], diff --git a/packages/opentelemetry-cloud-trace-propagator/package-lock.json b/packages/opentelemetry-cloud-trace-propagator/package-lock.json index b2430d79..0a2109fd 100644 --- a/packages/opentelemetry-cloud-trace-propagator/package-lock.json +++ b/packages/opentelemetry-cloud-trace-propagator/package-lock.json @@ -291,28 +291,28 @@ "dev": true }, "@opentelemetry/api": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.11.0.tgz", - "integrity": "sha512-K+1ADLMxduhsXoZ0GRfi9Pw162FvzBQLDQlHru1lg86rpIU+4XqdJkSGo6y3Kg+GmOWq1HNHOA/ydw/rzHQkRg==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.12.0.tgz", + "integrity": "sha512-Dn4vU5GlaBrIWzLpsM6xbJwKHdlpwBQ4Bd+cL9ofJP3hKT8jBXpBpribmyaqAzrajzzl2Yt8uTa9rFVLfjDAvw==", "dev": true, "requires": { - "@opentelemetry/context-base": "^0.11.0" + "@opentelemetry/context-base": "^0.12.0" } }, "@opentelemetry/context-base": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/context-base/-/context-base-0.11.0.tgz", - "integrity": "sha512-ESRk+572bftles7CVlugAj5Azrz61VO0MO0TS2pE9MLVL/zGmWuUBQryART6/nsrFqo+v9HPt37GPNcECTZR1w==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/context-base/-/context-base-0.12.0.tgz", + "integrity": "sha512-UXwSsXo3F3yZ1dIBOG9ID8v2r9e+bqLWoizCtTb8rXtwF+N5TM7hzzvQz72o3nBU+zrI/D5e+OqAYK8ZgDd3DA==", "dev": true }, "@opentelemetry/core": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-0.11.0.tgz", - "integrity": "sha512-ZEKjBXeDGBqzouz0uJmrbEKNExEsQOhsZ3tJDCLcz5dUNoVw642oIn2LYWdQK2YdIfZbEmltiF65/csGsaBtFA==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-0.12.0.tgz", + "integrity": "sha512-oLZIkmTNWTJXzo1eA4dGu/S7wOVtylsgnEsCmhSJGhrJVDXm1eW/aGuNs3DVBeuxp0ZvQLAul3/PThsC3YrnzA==", "dev": true, "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/context-base": "^0.11.0", + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/context-base": "^0.12.0", "semver": "^7.1.3" }, "dependencies": { diff --git a/packages/opentelemetry-cloud-trace-propagator/package.json b/packages/opentelemetry-cloud-trace-propagator/package.json index fc591182..11e50c6a 100644 --- a/packages/opentelemetry-cloud-trace-propagator/package.json +++ b/packages/opentelemetry-cloud-trace-propagator/package.json @@ -37,8 +37,8 @@ "registry": "https://wombat-dressing-room.appspot.com" }, "devDependencies": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0", + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0", "@types/mocha": "7.0.2", "@types/node": "14.0.14", "codecov": "3.7.1", @@ -53,7 +53,7 @@ "hex2dec": "^1.0.1" }, "peerDependencies": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0" } } diff --git a/packages/opentelemetry-cloud-trace-propagator/src/CloudPropagator.ts b/packages/opentelemetry-cloud-trace-propagator/src/CloudPropagator.ts index e38a162a..40c70933 100644 --- a/packages/opentelemetry-cloud-trace-propagator/src/CloudPropagator.ts +++ b/packages/opentelemetry-cloud-trace-propagator/src/CloudPropagator.ts @@ -18,12 +18,10 @@ import { SetterFunction, GetterFunction, TraceFlags, -} from '@opentelemetry/api'; -import { decToHex, hexToDec } from 'hex2dec'; -import { setExtractedSpanContext, getParentSpanContext, -} from '@opentelemetry/core'; +} from '@opentelemetry/api'; +import { decToHex, hexToDec } from 'hex2dec'; /** * This file implements propagation for the Stackdriver Trace v1 Trace Context diff --git a/packages/opentelemetry-cloud-trace-propagator/test/CloudPropagator.test.ts b/packages/opentelemetry-cloud-trace-propagator/test/CloudPropagator.test.ts index 0c285526..75ac711b 100644 --- a/packages/opentelemetry-cloud-trace-propagator/test/CloudPropagator.test.ts +++ b/packages/opentelemetry-cloud-trace-propagator/test/CloudPropagator.test.ts @@ -13,17 +13,15 @@ // limitations under the License. import { - Context, defaultSetter, defaultGetter, SpanContext, TraceFlags, + ROOT_CONTEXT, + setExtractedSpanContext, + getActiveSpan, } from '@opentelemetry/api'; import * as assert from 'assert'; -import { - setExtractedSpanContext, - getExtractedSpanContext, -} from '@opentelemetry/core'; import { CloudPropagator, X_CLOUD_TRACE_HEADER } from '../src/CloudPropagator'; describe('CloudPropagator', () => { @@ -43,7 +41,7 @@ describe('CloudPropagator', () => { }; cloudPropagator.inject( - setExtractedSpanContext(Context.ROOT_CONTEXT, spanContext), + setExtractedSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultSetter ); @@ -60,7 +58,7 @@ describe('CloudPropagator', () => { traceFlags: TraceFlags.NONE, }; cloudPropagator.inject( - setExtractedSpanContext(Context.ROOT_CONTEXT, spanContext), + setExtractedSpanContext(ROOT_CONTEXT, spanContext), carrier, defaultSetter ); @@ -75,9 +73,9 @@ describe('CloudPropagator', () => { it('should extract context of a sampled span from carrier', () => { carrier[X_CLOUD_TRACE_HEADER] = 'd4cda95b652f4a1592b449d5929fda1b/7929822056569588882;o=1'; - const extractedSpanContext = getExtractedSpanContext( - cloudPropagator.extract(Context.ROOT_CONTEXT, carrier, defaultGetter) - ); + const extractedSpanContext = getActiveSpan( + cloudPropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + )?.context(); assert.deepStrictEqual(extractedSpanContext, { traceId: 'd4cda95b652f4a1592b449d5929fda1b', @@ -90,9 +88,9 @@ describe('CloudPropagator', () => { it('should extract context of a unsampled span from carrier', () => { carrier[X_CLOUD_TRACE_HEADER] = 'd4cda95b652f4a1592b449d5929fda1b/7929822056569588882;o=0'; - const extractedSpanContext = getExtractedSpanContext( - cloudPropagator.extract(Context.ROOT_CONTEXT, carrier, defaultGetter) - ); + const extractedSpanContext = getActiveSpan( + cloudPropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + )?.context(); assert.deepStrictEqual(extractedSpanContext, { traceId: 'd4cda95b652f4a1592b449d5929fda1b', @@ -105,9 +103,9 @@ describe('CloudPropagator', () => { it('should handle trace_flags other than 0 and 1', () => { carrier[X_CLOUD_TRACE_HEADER] = 'd4cda95b652f4a1592b449d5929fda1b/7929822056569588882;o=123'; - const extractedSpanContext = getExtractedSpanContext( - cloudPropagator.extract(Context.ROOT_CONTEXT, carrier, defaultGetter) - ); + const extractedSpanContext = getActiveSpan( + cloudPropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + )?.context(); assert.deepStrictEqual(extractedSpanContext, { traceId: 'd4cda95b652f4a1592b449d5929fda1b', @@ -120,9 +118,9 @@ describe('CloudPropagator', () => { it('should handle missing trace_flags', () => { carrier[X_CLOUD_TRACE_HEADER] = 'b75dc0042a82efcb6b0a194911272926/1258215'; - const extractedSpanContext = getExtractedSpanContext( - cloudPropagator.extract(Context.ROOT_CONTEXT, carrier, defaultGetter) - ); + const extractedSpanContext = getActiveSpan( + cloudPropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + )?.context(); assert.deepStrictEqual( extractedSpanContext!.traceId, @@ -136,9 +134,9 @@ describe('CloudPropagator', () => { carrier[X_CLOUD_TRACE_HEADER] = [ 'd4cda95b652f4a1592b449d5929fda1b/7929822056569588882;o=1', ]; - const extractedSpanContext = getExtractedSpanContext( - cloudPropagator.extract(Context.ROOT_CONTEXT, carrier, defaultGetter) - ); + const extractedSpanContext = getActiveSpan( + cloudPropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + )?.context(); assert.deepStrictEqual(extractedSpanContext, { traceId: 'd4cda95b652f4a1592b449d5929fda1b', spanId: '6e0c63257de34c92', @@ -149,9 +147,9 @@ describe('CloudPropagator', () => { it('returns undefined if x-cloud-trace-context header is missing', () => { assert.deepStrictEqual( - getExtractedSpanContext( - cloudPropagator.extract(Context.ROOT_CONTEXT, carrier, defaultGetter) - ), + getActiveSpan( + cloudPropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + )?.context(), undefined ); }); @@ -179,9 +177,9 @@ describe('CloudPropagator', () => { for (const [testName, testData] of Object.entries(testCases)) { carrier[X_CLOUD_TRACE_HEADER] = testData; - const extractedSpanContext = getExtractedSpanContext( - cloudPropagator.extract(Context.ROOT_CONTEXT, carrier, defaultGetter) - ); + const extractedSpanContext = getActiveSpan( + cloudPropagator.extract(ROOT_CONTEXT, carrier, defaultGetter) + )?.context(); assert.deepStrictEqual(extractedSpanContext, undefined, testName); } diff --git a/samples/trace/package-lock.json b/samples/trace/package-lock.json index c5f3a0e2..a8408026 100644 --- a/samples/trace/package-lock.json +++ b/samples/trace/package-lock.json @@ -4,73 +4,73 @@ "lockfileVersion": 1, "dependencies": { "@opentelemetry/api": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.11.0.tgz", - "integrity": "sha512-K+1ADLMxduhsXoZ0GRfi9Pw162FvzBQLDQlHru1lg86rpIU+4XqdJkSGo6y3Kg+GmOWq1HNHOA/ydw/rzHQkRg==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.12.0.tgz", + "integrity": "sha512-Dn4vU5GlaBrIWzLpsM6xbJwKHdlpwBQ4Bd+cL9ofJP3hKT8jBXpBpribmyaqAzrajzzl2Yt8uTa9rFVLfjDAvw==", "requires": { - "@opentelemetry/context-base": "^0.11.0" + "@opentelemetry/context-base": "^0.12.0" } }, "@opentelemetry/context-async-hooks": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/context-async-hooks/-/context-async-hooks-0.11.0.tgz", - "integrity": "sha512-4z0X9EfvoLNA6R5yi+2taUyaSCUiyi/ht1qBYZMgpWvWwARgc5hcgGkZo7bekPk1zWfE9NFIhW6ySOXOP9CXyQ==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/context-async-hooks/-/context-async-hooks-0.12.0.tgz", + "integrity": "sha512-pQclJ/fab+vZN/Q6XPMqKjMxnO8FZQi+GCSgb3CEnY4v6Xpu8MQ9T5oUKXyTP/DRfBt63M+hoCQLIH7+7aDnvQ==", "requires": { - "@opentelemetry/context-base": "^0.11.0" + "@opentelemetry/context-base": "^0.12.0" } }, "@opentelemetry/context-base": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/context-base/-/context-base-0.11.0.tgz", - "integrity": "sha512-ESRk+572bftles7CVlugAj5Azrz61VO0MO0TS2pE9MLVL/zGmWuUBQryART6/nsrFqo+v9HPt37GPNcECTZR1w==" + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/context-base/-/context-base-0.12.0.tgz", + "integrity": "sha512-UXwSsXo3F3yZ1dIBOG9ID8v2r9e+bqLWoizCtTb8rXtwF+N5TM7hzzvQz72o3nBU+zrI/D5e+OqAYK8ZgDd3DA==" }, "@opentelemetry/core": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-0.11.0.tgz", - "integrity": "sha512-ZEKjBXeDGBqzouz0uJmrbEKNExEsQOhsZ3tJDCLcz5dUNoVw642oIn2LYWdQK2YdIfZbEmltiF65/csGsaBtFA==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/core/-/core-0.12.0.tgz", + "integrity": "sha512-oLZIkmTNWTJXzo1eA4dGu/S7wOVtylsgnEsCmhSJGhrJVDXm1eW/aGuNs3DVBeuxp0ZvQLAul3/PThsC3YrnzA==", "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/context-base": "^0.11.0", + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/context-base": "^0.12.0", "semver": "^7.1.3" } }, "@opentelemetry/node": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/node/-/node-0.11.0.tgz", - "integrity": "sha512-1SrZNbF7aBShySvsmWL+3bir6fVugjSnCyXsKMwclinhZIHd2cUfgjKdi42OCcA5G4Pp8TpO7/8ue8qI5yKX8w==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/node/-/node-0.12.0.tgz", + "integrity": "sha512-S6kl2ExkcSvMl+oVgiibmL67liTAKnVXUS9PqvpZcafhkNqMAyIq/BEKF6p/oDJO/2N+nEvXu8kmPjivdOqi9g==", "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/context-async-hooks": "^0.11.0", - "@opentelemetry/core": "^0.11.0", - "@opentelemetry/tracing": "^0.11.0", + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/context-async-hooks": "^0.12.0", + "@opentelemetry/core": "^0.12.0", + "@opentelemetry/tracing": "^0.12.0", "require-in-the-middle": "^5.0.0", "semver": "^7.1.3" } }, "@opentelemetry/resources": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-0.11.0.tgz", - "integrity": "sha512-o7DwV1TcezqBtS5YW2AWBcn01nVpPptIbTr966PLlVBcS//w8LkjeOShiSZxQ0lmV4b2en0FiSouSDoXk/5qIQ==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-0.12.0.tgz", + "integrity": "sha512-8cYvIKB68cyupc7D6SWzkLtt13mbjgxMahL4JKCM6hWPyiGSJlPFEAey4XFXI5LLpPZRYTPHLVoLqI/xwCFZZA==", "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/core": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/core": "^0.12.0" } }, "@opentelemetry/semantic-conventions": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-0.11.0.tgz", - "integrity": "sha512-xsthnI/J+Cx0YVDGgUzvrH0ZTtfNtl866M454NarYwDrc0JvC24sYw+XS5PJyk2KDzAHtb0vlrumUc1OAut/Fw==" + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-0.12.0.tgz", + "integrity": "sha512-BuCcDW0uLNYYTns0/LwXkJ8lp8aDm7kpS+WunEmPAPRSCe6ciOYRvzn5reqJfX93rf+6A3U2SgrBnCTH+0qoQQ==" }, "@opentelemetry/tracing": { - "version": "0.11.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/tracing/-/tracing-0.11.0.tgz", - "integrity": "sha512-QweFmxzl32BcyzwdWCNjVXZT1WeENNS/RWETq/ohqu+fAsTcMyGcr6cOq/yDdFmtBy+bm5WVVdeByEjNS+c4/w==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/tracing/-/tracing-0.12.0.tgz", + "integrity": "sha512-2TUGhTGkhgnxTciHCNAILPSeyXageJewRqfP9wOrx65sKd/jgvNYoY8nYf4EVWVMirDOxKDsmYgUkjdQrwb2dg==", "requires": { - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/context-base": "^0.11.0", - "@opentelemetry/core": "^0.11.0", - "@opentelemetry/resources": "^0.11.0", - "@opentelemetry/semantic-conventions": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/context-base": "^0.12.0", + "@opentelemetry/core": "^0.12.0", + "@opentelemetry/resources": "^0.12.0", + "@opentelemetry/semantic-conventions": "^0.12.0" } }, "debug": { @@ -81,6 +81,27 @@ "ms": "2.1.2" } }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "requires": { + "function-bind": "^1.1.1" + } + }, + "is-core-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.0.0.tgz", + "integrity": "sha512-jq1AH6C8MuteOoBPwkxHafmByhL9j5q4OaPGdbuD+ZtQJVzH+i6E3BJDQcBA09k57i2Hh2yQbEG8yObZ0jdlWw==", + "requires": { + "has": "^1.0.3" + } + }, "module-details-from-path": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/module-details-from-path/-/module-details-from-path-1.0.3.tgz", @@ -107,10 +128,11 @@ } }, "resolve": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", - "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.18.1.tgz", + "integrity": "sha512-lDfCPaMKfOJXjy0dPayzPdF1phampNWr3qFCjAu+rw/qbQmr5jWH5xN2hwh9QKfw9E5v4hwV7A+jrCmL8yjjqA==", "requires": { + "is-core-module": "^2.0.0", "path-parse": "^1.0.6" } }, diff --git a/samples/trace/package.json b/samples/trace/package.json index 22a7c822..bdd2cdfe 100644 --- a/samples/trace/package.json +++ b/samples/trace/package.json @@ -12,8 +12,8 @@ "repository": "GoogleCloudPlatform/opentelemetry-operations-js", "dependencies": { "@google-cloud/opentelemetry-cloud-trace-exporter": "^0.5.0", - "@opentelemetry/api": "^0.11.0", - "@opentelemetry/node": "^0.11.0", - "@opentelemetry/tracing": "^0.11.0" + "@opentelemetry/api": "^0.12.0", + "@opentelemetry/node": "^0.12.0", + "@opentelemetry/tracing": "^0.12.0" } }