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

Commit 692f0df

Browse files
author
Nir Hadassi
authored
feat: migration to new instrumentation class (#61)
1 parent 4393fff commit 692f0df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+840
-691
lines changed

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
js extensions for the [open-telemetry](https://opentelemetry.io/) project, from [Aspecto](https://www.aspecto.io/) with :heart:
1616

1717
**Compatible with [otel v0.15.0](https://github.com/open-telemetry/opentelemetry-js/releases/tag/v0.15.0)**
18-
## Plugins
19-
- [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)
20-
- [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)
21-
- [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)
22-
- [opentelemetry-plugin-sequelize](./packages/plugin-sequelize) - auto instrumentation for [`Sequelize`](https://sequelize.org/)
23-
[![NPM version](https://img.shields.io/npm/v/opentelemetry-plugin-sequelize.svg)](https://www.npmjs.com/package/opentelemetry-plugin-sequelize)
18+
## Instrumentations
19+
- [opentelemetry-instrumentation-kafkajs](./packages/instrumentation-kafkajs) - auto instrumentation for [`kafkajs`](https://kafka.js.org) [![NPM version](https://img.shields.io/npm/v/opentelemetry-instrumentation-kafkajs.svg)](https://www.npmjs.com/package/opentelemetry-instrumentation-kafkajs)
20+
- [opentelemetry-instrumentation-aws-sdk](./packages/instrumentation-aws-sdk) - auto instrumentation for [`aws-sdk`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/) [![NPM version](https://img.shields.io/npm/v/opentelemetry-instrumentation-aws-sdk.svg)](https://www.npmjs.com/package/opentelemetry-instrumentation-aws-sdk)
21+
- [opentelemetry-instrumentation-typeorm](./packages/instrumentation-typeorm) - auto instrumentation for [`TypeORM`](https://typeorm.io/) [![NPM version](https://img.shields.io/npm/v/opentelemetry-instrumentation-typeorm.svg)](https://www.npmjs.com/package/opentelemetry-instrumentation-typeorm)
22+
- [opentelemetry-instrumentation-sequelize](./packages/instrumentation-sequelize) - auto instrumentation for [`Sequelize`](https://sequelize.org/)
23+
[![NPM version](https://img.shields.io/npm/v/opentelemetry-instrumentation-sequelize.svg)](https://www.npmjs.com/package/opentelemetry-instrumentation-sequelize)
2424

2525
## Compatibility with opentelemetry versions
26+
### Instrumentations in this repo are using opentelemetry [Instrumentation API](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation).
27+
For documentation using with the old [plugin](https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-core/src/trace/Plugin.ts) api, please go [here](https://github.com/aspecto-io/opentelemetry-ext-js/tree/4393fff108c477d05ecd02dd7d9552ea1d482853).
28+
2629
**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
30+
- Versions 0.0.x of the instrumentations are compatible with otel version v0.15.0

packages/plugin-aws-sdk/README.md renamed to packages/instrumentation-aws-sdk/README.md

+27-22
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
11
# OpenTelemetry aws-sdk Instrumentation for Node.js
2-
[![NPM version](https://img.shields.io/npm/v/opentelemetry-plugin-aws-sdk.svg)](https://www.npmjs.com/package/opentelemetry-plugin-aws-sdk)
2+
[![NPM version](https://img.shields.io/npm/v/opentelemetry-instrumentation-aws-sdk.svg)](https://www.npmjs.com/package/opentelemetry-instrumentation-aws-sdk)
33

44
This module provides automatic instrumentation for [`aws-sdk`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/).
55

66
## Installation
77

88
```
9-
npm install --save opentelemetry-plugin-aws-sdk
9+
npm install --save opentelemetry-instrumentation-aws-sdk
1010
```
1111

1212
## Usage
13-
14-
To load this plugin, specify it in the Node Tracer's configuration:
13+
For further automatic instrumentation instruction see the [@opentelemetry/instrumentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation) package.
1514

1615
```js
17-
const { NodeTracerProvider } = require("@opentelemetry/node");
16+
const { NodeTracerProvider } = require('@opentelemetry/node');
17+
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
18+
const { AwsInstrumentation } = require('opentelemetry-instrumentation-aws-sdk');
1819

19-
const provider = new NodeTracerProvider({
20+
const traceProvider = new NodeTracerProvider({
21+
// be sure to disable old plugin
2022
plugins: {
21-
"aws-sdk": {
22-
enabled: true,
23-
// You may use a package name or absolute path to the file.
24-
path: "opentelemetry-plugin-aws-sdk",
25-
},
26-
},
23+
'aws-sdk': { enabled: false, path: 'opentelemetry-plugin-aws-sdk' }
24+
}
25+
});
26+
27+
registerInstrumentations({
28+
traceProvider,
29+
instrumentations: [
30+
new AwsInstrumentation({
31+
// see under for available configuration
32+
})
33+
]
2734
});
2835
```
2936

30-
### aws-sdk Plugin Options
37+
### aws-sdk Instrumentation Options
3138

32-
aws-sdk plugin has few options available to choose from. You can set the following:
39+
aws-sdk instrumentation has few options available to choose from. You can set the following:
3340

3441
| Options | Type | Description |
3542
| -------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------- |
3643
| `preRequestHook` | `AwsSdkRequestCustomAttributeFunction` | Hook called before request send, which allow to add custom attributes to span. |
3744
| `responseHook` | `AwsSdkResponseCustomAttributeFunction` | Hook for adding custom attributes when response is received from aws. |
3845
| `sqsProcessHook` | `AwsSdkSqsProcessCustomAttributeFunction` | Hook called after starting sqs `process` span (for each sqs received message), which allow to add custom attributes to it. |
39-
| `suppressInternalInstrumentation` | boolean | Most aws operation use http request under the hood. If http instrumentation is enabled, each aws operation will also create an http/s child describing the communication with amazon servers. Setting the suppressInternalInstrumentation` config value to `true` will cause the plugin to suppress instrumentation of underlying operations, effectively causing those http spans to be non-recordable. |
46+
| `suppressInternalInstrumentation` | boolean | Most aws operation use http request under the hood. If http instrumentation is enabled, each aws operation will also create an http/s child describing the communication with amazon servers. Setting the suppressInternalInstrumentation` config value to `true` will cause the instrumentation to suppress instrumentation of underlying operations, effectively causing those http spans to be non-recordable. |
4047

4148

4249

4350
## Span Attributes
44-
This plugin patch the internal `Request` object, which means that each sdk operation will create a single span with attributes from 3 sources:
51+
This instrumentation patch the internal `Request` object, which means that each sdk operation will create a single span with attributes from 3 sources:
4552

4653
### Default attributes
4754
Each span will have the following attributes:
@@ -58,14 +65,12 @@ Each span will have the following attributes:
5865
| `aws.error` | string | information about a service or networking error, as returned from AWS | "UriParameterError: Expected uri parameter to have length >= 1, but found "" for params.Bucket" |
5966

6067
### Custom User Attributes
61-
The plugin user can configure a `preRequestHook` function which will be called before each request, with the request object and the corrosponding span.
68+
The instrumentation user can configure a `preRequestHook` function which will be called before each request, with the request object and the corresponding span.
6269
This hook can be used to add custom attributes to the span with any logic.
6370
For example, user can add interesting attributes from the `request.params`, and write custom logic based on the service and operation.
6471
Usage example:
6572
```js
66-
awsPluginConfig = {
67-
enabled: true,
68-
path: "opentelemetry-plugin-aws-sdk",
73+
awsInstrumentationConfig = {
6974
preRequestHook: (span, request) => {
7075
if (span.attributes["aws.service.api"] === 's3') {
7176
span.setAttribute("s3.bucket.name", request.params["Bucket"]);
@@ -82,10 +87,10 @@ Specific service logic currently implemented for:
8287

8388
---
8489

85-
This plugin is a work in progress. We implemented some of the specific trace semantics for some of the services, and strive to support more services and extend the already supported services in the future. You can [Open an Issue](https://github.com/aspecto-io/opentelemetry-ext-js/issues), or [Submit a Pull Request](https://github.com/aspecto-io/opentelemetry-ext-js/pulls) if you want to contribute.
90+
This instrumentation is a work in progress. We implemented some of the specific trace semantics for some of the services, and strive to support more services and extend the already supported services in the future. You can [Open an Issue](https://github.com/aspecto-io/opentelemetry-ext-js/issues), or [Submit a Pull Request](https://github.com/aspecto-io/opentelemetry-ext-js/pulls) if you want to contribute.
8691

8792
## Potential Side Effects
88-
The plugin is doing best effort to support the trace specification of open telemetry. For SQS, it involves defining new attributes on the `Messages` array, as well as on the manipulated types generated from this array (to set correct trace context for a single SQS message operation). Those properties are defined as [non-enumerable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties) properties, so they have minimum side effect on the app. They will, however, show when using the `Object.getOwnPropertyDescriptors` and `Reflect.ownKeys` functions on SQS `Messages` array and for each `Message` in the array.
93+
The instrumentation is doing best effort to support the trace specification of open telemetry. For SQS, it involves defining new attributes on the `Messages` array, as well as on the manipulated types generated from this array (to set correct trace context for a single SQS message operation). Those properties are defined as [non-enumerable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties) properties, so they have minimum side effect on the app. They will, however, show when using the `Object.getOwnPropertyDescriptors` and `Reflect.ownKeys` functions on SQS `Messages` array and for each `Message` in the array.
8994

9095
---
9196

packages/plugin-aws-sdk/docs/sqs.md renamed to packages/instrumentation-aws-sdk/docs/sqs.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ SQS is amazon's managed message queue. Thus, it should follow the [Open Telemetr
55
The following methods are automatically enhanced:
66

77
### sendMessage / sendMessageBatch
8-
- [Messaging Attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#messaging-attributes) are added by this plugin according to the spec.
8+
- [Messaging Attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#messaging-attributes) are added by this instrumentation according to the spec.
99
- Open Telemetry trace context is injected as SQS MessageAttributes, so the service receiving the message can link cascading spans to the trace which created the message.
1010

1111
### receiveMessage
12-
- [Messaging Attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#messaging-attributes) are added by this plugin according to the spec.
12+
- [Messaging Attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#messaging-attributes) are added by this instrumentation according to the spec.
1313
- Additional "processing spans" are created for each message received by the application.
1414
If an application invoked `receiveMessage`, and received a 10 messages batch, a single `messaging.operation` = `receive` span will be created for the `receiveMessage` operation, and 10 `messaging.operation` = `process` spans will be created, one for each message.
1515
Those processing spans are created by the library. This behavior is partially implemented, [See discussion below](#processing-spans).
@@ -43,13 +43,11 @@ async function poll() {
4343
}
4444
```
4545

46-
Current implementation partially solves this issue by patching the `map` \ `forEach` \ `Filter` functions on the `Messages` array of `receiveMessage` result. This handles issues like the one above, but will not handle situations where the processing is done in other patterns (multiple map\forEach calls, index access to the array, other array operations, etc). This is currently an open issue in the plugin.
46+
Current implementation partially solves this issue by patching the `map` \ `forEach` \ `Filter` functions on the `Messages` array of `receiveMessage` result. This handles issues like the one above, but will not handle situations where the processing is done in other patterns (multiple map\forEach calls, index access to the array, other array operations, etc). This is currently an open issue in the instrumentation.
4747

48-
User can add custom attributes to the `process` span, by setting a function to `sqsProcessHook` in plugin config. For example:
48+
User can add custom attributes to the `process` span, by setting a function to `sqsProcessHook` in instrumentation config. For example:
4949
```js
50-
awsPluginConfig = {
51-
enabled: true,
52-
path: "opentelemetry-plugin-aws-sdk",
50+
awsInstrumentationConfig = {
5351
sqsProcessHook: (span, message) => {
5452
span.setAttribute("sqs.receipt_handle", message.params?.ReceiptHandle);
5553
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "opentelemetry-plugin-aws-sdk",
3-
"version": "0.2.1",
2+
"name": "opentelemetry-instrumentation-aws-sdk",
3+
"version": "0.0.0",
44
"description": "open telemetry instrumentation for the `aws-sdk` package",
55
"keywords": [
66
"aws",
@@ -23,42 +23,36 @@
2323
"scripts": {
2424
"build": "tsc",
2525
"prepare": "yarn run build",
26-
"test": "jest",
26+
"test": "mocha",
2727
"watch": "tsc -w",
2828
"version:update": "node ../../scripts/version-update.js",
2929
"version": "yarn run version:update"
3030
},
3131
"bugs": {
3232
"url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues"
3333
},
34+
"dependencies": {
35+
"@opentelemetry/api": "^0.15.0",
36+
"@opentelemetry/instrumentation": "^0.15.0",
37+
"@opentelemetry/semantic-conventions": "^0.15.0",
38+
"opentelemetry-propagation-utils": "^0.2.1"
39+
},
3440
"devDependencies": {
3541
"@opentelemetry/api": "^0.15.0",
3642
"@opentelemetry/node": "^0.15.0",
3743
"@opentelemetry/tracing": "^0.15.0",
38-
"@types/jest": "^26.0.15",
39-
"@types/shimmer": "^1.0.1",
44+
"@types/mocha": "^8.2.0",
4045
"aws-sdk": "^2.780.0",
41-
"jest": "^26.6.1",
42-
"ts-jest": "^26.4.3",
46+
"expect": "^26.6.2",
47+
"mocha": "^8.3.0",
48+
"ts-node": "^9.1.1",
4349
"typescript": "^4.0.5"
4450
},
45-
"dependencies": {
46-
"@opentelemetry/api": "^0.15.0",
47-
"@opentelemetry/core": "^0.15.0",
48-
"@opentelemetry/semantic-conventions": "^0.15.0",
49-
"opentelemetry-propagation-utils": "^0.2.1",
50-
"shimmer": "^1.2.1"
51-
},
52-
"jest": {
53-
"preset": "ts-jest",
54-
"globals": {
55-
"ts-jest": {
56-
"tsconfig": "./tsconfig.json"
57-
}
58-
},
59-
"testMatch": [
60-
"**/test/**/*.spec.+(ts|tsx)"
51+
"mocha": {
52+
"extension": [
53+
"ts"
6154
],
62-
"testEnvironment": "node"
55+
"spec": "test/**/*.spec.ts",
56+
"require": "ts-node/register"
6357
}
6458
}

0 commit comments

Comments
 (0)