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

Commit 74412a3

Browse files
author
Amir Blum
committed
Merge branch 'master' of github.com:aspecto-io/opentelemetry-ext-js into request-hook-refactor
2 parents f1c3dc9 + 7ec8663 commit 74412a3

File tree

2 files changed

+50
-23
lines changed

2 files changed

+50
-23
lines changed

packages/plugin-aws-sdk/README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# OpenTelemetry aws-sdk Instrumentation for Node.js
2+
![NPM version](https://img.shields.io/npm/v/opentelemetry-plugin-aws-sdk.svg)
23

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

@@ -10,10 +11,10 @@ npm install --save opentelemetry-plugin-aws-sdk
1011

1112
## Usage
1213

13-
To load a specific plugin (**aws-sdk** in this case), specify it in the Node Tracer's configuration
14+
To load this plugin, specify it in the Node Tracer's configuration:
1415

1516
```js
16-
const { NodeTracerProvider } = require("opentelemetry-plugin-aws-sdk");
17+
const { NodeTracerProvider } = require("@opentelemetry/node");
1718

1819
const provider = new NodeTracerProvider({
1920
plugins: {
@@ -42,21 +43,40 @@ This plugin patch the internal `Request` object, which means that each sdk opera
4243
Each span will have the following attributes:
4344
| Attribute Name | Type | Description | Example |
4445
| -------------- | ---- | ----------- | ------- |
45-
| "component" | string | Always equals "aws-sdk" | "aws-sdk" |
46-
| "aws.operation" | string | The method name for the request. | for `SQS.sendMessage(...)` the operation is "sendMessage" |
47-
| "aws.signature.version" | string | Aws version of authentication signature on the request. | "v4" |
48-
| "aws.region" | string | Region name for the request | "eu-west-1" |
49-
| "aws.service.api" | string | The sdk class name for the service | "SQS" |
50-
| "aws.service.identifier" | string | Identifier for the service in the sdk | "sqs" |
51-
| "aws.service.name" | string | Abbreviation name for the service | "Amazon SQS" |
52-
| "aws.request.id" | uuid | Request unique id, as returned from aws on response | "01234567-89ab-cdef-0123-456789abcdef" |
53-
| "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" |
46+
| `component` | string | Always equals "aws-sdk" | "aws-sdk" |
47+
| `aws.operation` | string | The method name for the request. | for `SQS.sendMessage(...)` the operation is "sendMessage" |
48+
| `aws.signature.version` | string | AWS version of authentication signature on the request. | "v4" |
49+
| `aws.region` | string | Region name for the request | "eu-west-1" |
50+
| `aws.service.api` | string | The sdk class name for the service | "SQS" |
51+
| `aws.service.identifier` | string | Identifier for the service in the sdk | "sqs" |
52+
| `aws.service.name` | string | Abbreviation name for the service | "Amazon SQS" |
53+
| `aws.request.id` | uuid | Request unique id, as returned from aws on response | "01234567-89ab-cdef-0123-456789abcdef" |
54+
| `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" |
5455

5556
### Custom User Attributes
56-
The plugin user can configure a hook function which will be called before each request, with the request object and the relevant span. This hook can be used to add custom attributes to the span with any logic. For example, user can add interesting attributes from the `request.params`, and write custom logic based on the service and operation.
57+
The plugin user can configure a `preRequestHook` function which will be called before each request, with the request object and the corrosponding span.
58+
This hook can be used to add custom attributes to the span with any logic.
59+
For example, user can add interesting attributes from the `request.params`, and write custom logic based on the service and operation.
60+
Usage example:
61+
```js
62+
awsPluginConfig = {
63+
enabled: true,
64+
path: "opentelemetry-plugin-aws-sdk",
65+
preRequestHook: (span, request) => {
66+
if (span.attributes["aws.service.api"] === 's3') {
67+
span.setAttribute("s3.bucket.name", request.params["Bucket"]);
68+
}
69+
}
70+
};
71+
```
5772

5873
### Specific Service Logic
5974
AWS contains dozens of services accessible with the JS SDK. For many services, the default attributes specified above are enough, but other services have specific [trace semantic conventions](https://github.com/open-telemetry/opentelemetry-specification/tree/master/specification/trace/semantic_conventions), or need to inject/extract intra-process context, or set intra-process context correctly.
6075

76+
Specific service logic currently implemented for:
77+
* [SQS](./docs/sqs.md)
78+
79+
---
80+
6181
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.
6282

packages/plugin-aws-sdk/docs/sqs.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@
22
SQS is amazon's managed message queue. Thus, it should follow the [Open Telemetry specification for Messaging systems](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md).
33

44
## Specific trace semantic
5-
Following methods needs specific attention:
5+
The following methods are automatically enhanced:
66

77
### sendMessage / sendMessageBatch
8-
- Add [message attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#messaging-attributes) to span in addition to the default attributes. These attributes are covered by the library according to the spec.
9-
- Inject trace context as SQS MessageAttributes, so the service receiving the message can link cascading spans to the trace which created the message. This is not implemented yet.
8+
- [Message 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.
9+
- TODO: Inject trace context as SQS MessageAttributes, so the service receiving the message can link cascading spans to the trace which created the message.
1010

1111
### receiveMessage
12-
- Add [message attributes](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/messaging.md#messaging-attributes) to span in addition to the default attributes. These attributes are covered by the library according to the spec.
13-
- Create additional "processing spans" for each message received by the application. So if an application called `receiveMessage`, and got back 10 messages, 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. Those processing spans are created by the library. This behavior is partially implemented, [See discussion below](#processing-spans).
14-
- Set the inter process context correctly, so that additional spans created from message receiving and message processing will be linked to parent spans correctly. This behavior is partially implemented, [See discussion below](#processing-spans).
15-
- Extract trace context from SQS MessageAttributes, and set span's `parent` and `links` correctly according to the spec. This is not implemented yet.
12+
- [Message 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.
13+
- Additional "processing spans" are created for each message received by the application.
14+
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.
15+
Those processing spans are created by the library. This behavior is partially implemented, [See discussion below](#processing-spans).
16+
- Sets the inter process context correctly, so that additional spans created through the process will be linked to parent spans correctly.
17+
This behavior is partially implemented, [See discussion below](#processing-spans).
18+
- TODO: Extract trace context from SQS MessageAttributes, and set span's `parent` and `links` correctly according to the spec.
1619

17-
#### Processing spans
18-
According to open telemetry specification (and to reasonable expectation for trace structure), user of this library would expect to see one span for the operation of receiving messages batch from sqs, and then, for each message, a span with it's own sub-tree for the processing of this specific message.
20+
#### Processing Spans
21+
According to open telemetry specification (and to reasonable expectation for trace structure), user of this library would expect to see one span for the operation of receiving messages batch from SQS, and then, for each message, a span with it's own sub-tree for the processing of this specific message.
1922

20-
For example, if a `receiveMessages` returned 2 messages: msg1 is storing something to a DB, and msg2 is calling an external http endpoint, we should link the db span under msg1, and the http span under msg2, instead of mixing all those operations under the single `receive` span, or start a new trace for each of them.
23+
For example, if a `receiveMessages` returned 2 messages:
24+
* `msg1` resulting in storing something to a DB.
25+
* `msg2` resulting in calling an external HTTP endpoint.
26+
27+
This will result in a creating a DB span that would be linked under `msg1` process, and an HTTP span that would be under `msg2` (in opposed to mixing all those operations under the single `receive` span, or start a new trace for each of them).
2128

2229
Unfortunately, this is not so easy to implement in JS:
2330
1. The SDK is calling a single callback for the messages batch, and it's not straight forward to understand when each individual message processing starts and ends (and set the context correctly for cascading spans).
@@ -36,4 +43,4 @@ async function poll() {
3643
}
3744
```
3845

39-
Current implementation partially solves this issue by patching the `map` \ `forEach` 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` 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.

0 commit comments

Comments
 (0)