Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 628ddf3

Browse files
author
Amir Blum
authored
chore: upgrade to otel v0.15.0 (#58)
1 parent 527e266 commit 628ddf3

File tree

21 files changed

+69
-79
lines changed

21 files changed

+69
-79
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@
1414

1515
js extensions for the [open-telemetry](https://opentelemetry.io/) project, from [Aspecto](https://www.aspecto.io/) with :heart:
1616

17+
**Compatible with [otel v0.15.0](https://github.com/open-telemetry/opentelemetry-js/releases/tag/v0.15.0)**
1718
## Plugins
1819
- [opentelemetry-plugin-kafkajs](./packages/plugin-kafkajs) - auto instrumentation for [`kafkajs`](https://kafka.js.org) [![NPM version](https://img.shields.io/npm/v/opentelemetry-plugin-kafkajs.svg)](https://www.npmjs.com/package/opentelemetry-plugin-kafkajs)
1920
- [opentelemetry-plugin-aws-sdk](./packages/plugin-aws-sdk) - auto instrumentation for [`aws-sdk`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/) [![NPM version](https://img.shields.io/npm/v/opentelemetry-plugin-aws-sdk.svg)](https://www.npmjs.com/package/opentelemetry-plugin-aws-sdk)
2021
- [opentelemetry-plugin-typeorm](./packages/plugin-typeorm) - auto instrumentation for [`TypeORM`](https://typeorm.io/) [![NPM version](https://img.shields.io/npm/v/opentelemetry-plugin-typeorm.svg)](https://www.npmjs.com/package/opentelemetry-plugin-typeorm)
2122
- [opentelemetry-plugin-sequelize](./packages/plugin-sequelize) - auto instrumentation for [`Sequelize`](https://sequelize.org/)
2223
[![NPM version](https://img.shields.io/npm/v/opentelemetry-plugin-sequelize.svg)](https://www.npmjs.com/package/opentelemetry-plugin-sequelize)
24+
25+
## Compatibility with opentelemetry versions
26+
**Tested and verified against otel v0.15.0**
27+
- Versions 0.2.x of the plugins are compatible with otel version v0.15.0
28+
- Versions 0.1.x of the plugins are compatible with otel version v0.14.0
29+
- Versions 0.0.x of the plugins are compatible with otel version v0.12.0

packages/plugin-aws-sdk/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
"url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues"
3333
},
3434
"devDependencies": {
35-
"@opentelemetry/api": "^0.14.0",
36-
"@opentelemetry/node": "^0.14.0",
37-
"@opentelemetry/tracing": "^0.14.0",
35+
"@opentelemetry/api": "^0.15.0",
36+
"@opentelemetry/node": "^0.15.0",
37+
"@opentelemetry/tracing": "^0.15.0",
3838
"@types/jest": "^26.0.15",
3939
"@types/shimmer": "^1.0.1",
4040
"aws-sdk": "^2.780.0",
@@ -43,9 +43,9 @@
4343
"typescript": "^4.0.5"
4444
},
4545
"dependencies": {
46-
"@opentelemetry/api": "^0.14.0",
47-
"@opentelemetry/core": "^0.14.0",
48-
"@opentelemetry/semantic-conventions": "^0.14.0",
46+
"@opentelemetry/api": "^0.15.0",
47+
"@opentelemetry/core": "^0.15.0",
48+
"@opentelemetry/semantic-conventions": "^0.15.0",
4949
"opentelemetry-propagation-utils": "^0.1.2",
5050
"shimmer": "^1.2.1"
5151
},

packages/plugin-aws-sdk/src/aws-sdk.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
callback | 1 | 2
1010
*/
1111
import { BasePlugin } from '@opentelemetry/core';
12-
import { Span, StatusCode, Attributes, SpanKind, context, suppressInstrumentation } from '@opentelemetry/api';
12+
import { Span, StatusCode, Attributes, SpanKind, context, setSpan, suppressInstrumentation } from '@opentelemetry/api';
1313
import * as shimmer from 'shimmer';
1414
import AWS from 'aws-sdk';
1515
import { AttributeNames } from './enums';
@@ -48,8 +48,8 @@ class AwsPlugin extends BasePlugin<typeof AWS> {
4848

4949
const origThen = target.then;
5050
target.then = function (onFulfilled, onRejected) {
51-
const newOnFulfilled = thisPlugin._tracer.bind(onFulfilled, span);
52-
const newOnRejected = thisPlugin._tracer.bind(onRejected, span);
51+
const newOnFulfilled = context.bind(onFulfilled, setSpan(context.active(), span));
52+
const newOnRejected = context.bind(onRejected, setSpan(context.active(), span));
5353
return origThen.call(this, newOnFulfilled, newOnRejected);
5454
};
5555

@@ -140,8 +140,8 @@ class AwsPlugin extends BasePlugin<typeof AWS> {
140140
thisPlugin._callUserPreRequestHook(span, awsRequest);
141141
thisPlugin._registerCompletedEvent(span, awsRequest);
142142

143-
const callbackWithContext = thisPlugin._tracer.bind(callback, span);
144-
return thisPlugin._tracer.withSpan(span, () => {
143+
const callbackWithContext = context.bind(callback, setSpan(context.active(), span));
144+
return context.with(setSpan(context.active(), span), () => {
145145
thisPlugin.servicesExtensions.requestPostSpanHook(awsRequest);
146146
return thisPlugin._callOriginalFunction(() => original.call(awsRequest, callbackWithContext));
147147
});
@@ -170,7 +170,7 @@ class AwsPlugin extends BasePlugin<typeof AWS> {
170170
thisPlugin._callUserPreRequestHook(span, awsRequest);
171171
thisPlugin._registerCompletedEvent(span, awsRequest);
172172

173-
const origPromise: Promise<any> = thisPlugin._tracer.withSpan(span, () => {
173+
const origPromise: Promise<any> = context.with(setSpan(context.active(), span), () => {
174174
thisPlugin.servicesExtensions.requestPostSpanHook(awsRequest);
175175
return thisPlugin._callOriginalFunction(() => original.call(awsRequest, arguments));
176176
});

packages/plugin-aws-sdk/src/services/sqs.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import {
66
Logger,
77
TextMapGetter,
88
TextMapSetter,
9-
setActiveSpan,
9+
setSpan,
1010
context,
1111
ROOT_CONTEXT,
1212
} from '@opentelemetry/api';
1313
import { pubsubPropagation } from 'opentelemetry-propagation-utils';
1414
import { RequestMetadata, ServiceExtension } from './ServiceExtension';
1515
import * as AWS from 'aws-sdk';
16-
import { TRACE_PARENT_HEADER, TRACE_STATE_HEADER } from '@opentelemetry/core';
1716
import {
1817
MessageBodyAttributeMap,
1918
SendMessageRequest,
@@ -91,10 +90,7 @@ export class SqsServiceExtension implements ServiceExtension {
9190
spanAttributes[SqsAttributeNames.MESSAGING_OPERATION] = 'receive';
9291

9392
const params: Record<string, any> = (request as any).params;
94-
const attributesNames = params.MessageAttributeNames || [];
95-
attributesNames.push(TRACE_PARENT_HEADER);
96-
attributesNames.push(TRACE_STATE_HEADER);
97-
params.MessageAttributeNames = attributesNames;
93+
params.MessageAttributeNames = (params.MessageAttributeNames ?? []).concat(propagation.fields());
9894
}
9995
break;
10096

@@ -144,7 +140,7 @@ export class SqsServiceExtension implements ServiceExtension {
144140

145141
pubsubPropagation.patchMessagesArrayToStartProcessSpans<AWS.SQS.Message>({
146142
messages,
147-
parentContext: setActiveSpan(context.active(), span),
143+
parentContext: setSpan(context.active(), span),
148144
tracer: this.tracer,
149145
messageToSpanDetails: (message: AWS.SQS.Message) => ({
150146
name: queueName,

packages/plugin-aws-sdk/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface AwsSdkPluginConfig extends PluginConfig {
2424
/** hook for adding custom attribute when an sqs process span is started */
2525
sqsProcessHook?: AwsSdkSqsProcessCustomAttributeFunction;
2626

27-
/**
27+
/**
2828
* Most aws operation use http request under the hood.
2929
* if http instrumentation is enabled, each aws operation will also create
3030
* an http/s child describing the communication with amazon servers.

packages/plugin-aws-sdk/test/aws-sdk.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { plugin } from '../src';
22
import AWS from 'aws-sdk';
33
import { InMemorySpanExporter, SimpleSpanProcessor, ReadableSpan, Span } from '@opentelemetry/tracing';
4-
import { context, StatusCode } from '@opentelemetry/api';
5-
import { NoopLogger } from '@opentelemetry/core';
4+
import { context, StatusCode, NoopLogger } from '@opentelemetry/api';
65
import { NodeTracerProvider } from '@opentelemetry/node';
76
import { ContextManager } from '@opentelemetry/context-base';
87
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
@@ -319,7 +318,6 @@ describe('plugin-aws-sdk', () => {
319318
await s3.createBucket({ Bucket: 'aws-test-bucket' }).promise();
320319
const awsSpans = getAwsSpans();
321320
expect(awsSpans.length).toBe(1);
322-
})
323-
321+
});
324322
});
325323
});

packages/plugin-aws-sdk/test/dynamodb.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { plugin } from '../src';
22
import AWS, { AWSError } from 'aws-sdk';
3-
import { NoopLogger } from '@opentelemetry/core';
43
import { NodeTracerProvider } from '@opentelemetry/node';
54
import { ContextManager } from '@opentelemetry/context-base';
6-
import { context } from '@opentelemetry/api';
5+
import { context, NoopLogger } from '@opentelemetry/api';
76
import { InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
87
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
98
import { mockAwsSend } from './testing-utils';

packages/plugin-aws-sdk/test/sqs.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { plugin } from '../src';
22
import AWS, { AWSError } from 'aws-sdk';
3-
import { NoopLogger } from '@opentelemetry/core';
43
import { NodeTracerProvider } from '@opentelemetry/node';
54
import { ContextManager } from '@opentelemetry/context-base';
6-
import { context, SpanKind, StatusCode } from '@opentelemetry/api';
5+
import { context, SpanKind, StatusCode, NoopLogger } from '@opentelemetry/api';
76
import { InMemorySpanExporter, SimpleSpanProcessor, ReadableSpan, Span } from '@opentelemetry/tracing';
87
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
98
import { mockAwsSend } from './testing-utils';

packages/plugin-aws-sdk/test/testing-utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { isInstrumentationSuppressed, context } from '@opentelemetry/api';
22
import AWS from 'aws-sdk';
33

4-
export const mockAwsSend = (sendResult: any, data: any = undefined, expectedInstrumentationSuppressed: boolean = false) => {
4+
export const mockAwsSend = (
5+
sendResult: any,
6+
data: any = undefined,
7+
expectedInstrumentationSuppressed: boolean = false
8+
) => {
59
AWS.Request.prototype.send = function (cb?: (error, response) => void) {
610
expect(isInstrumentationSuppressed(context.active())).toStrictEqual(expectedInstrumentationSuppressed);
711
if (cb) {

packages/plugin-kafkajs/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues"
3333
},
3434
"devDependencies": {
35-
"@opentelemetry/node": "^0.14.0",
36-
"@opentelemetry/tracing": "^0.14.0",
35+
"@opentelemetry/node": "^0.15.0",
36+
"@opentelemetry/tracing": "^0.15.0",
3737
"@types/jest": "^25.2.3",
3838
"@types/shimmer": "^1.0.1",
3939
"jest": "^26.0.1",
@@ -42,9 +42,9 @@
4242
"typescript": "^3.9.5"
4343
},
4444
"dependencies": {
45-
"@opentelemetry/api": "^0.14.0",
46-
"@opentelemetry/core": "^0.14.0",
47-
"@opentelemetry/semantic-conventions": "^0.14.0",
45+
"@opentelemetry/api": "^0.15.0",
46+
"@opentelemetry/core": "^0.15.0",
47+
"@opentelemetry/semantic-conventions": "^0.15.0",
4848
"shimmer": "^1.2.1"
4949
},
5050
"jest": {

0 commit comments

Comments
 (0)