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

Commit 161ad51

Browse files
author
Amir Blum
authored
Merge pull request #13 from aspecto-io/aws-readme
docs(plugin-aws-sdk): add documentation for attributes and sqs
2 parents 0166cd4 + c6b29bf commit 161ad51

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

packages/plugin-aws-sdk/README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,31 @@ aws-sdk plugin has few options available to choose from. You can set the followi
3232

3333
| Options | Type | Description |
3434
| -------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------- |
35-
| `preRequestHook` | `AwsSdkRequestCustomAttributeFunction` | Hook called before request send, which allow to add custom attributes to span. |
35+
| `preRequestHook` | `AwsSdkRequestCustomAttributeFunction` | Hook called before request send, which allow to add custom attributes to span. |
36+
37+
38+
## Span Attributes
39+
This plugin patch the internal `Request` object, which means that each sdk operation will create a single span with attributes from 3 sources:
40+
41+
### Default attributes
42+
Each span will have the following attributes:
43+
| Attribute Name | Type | Description | Example |
44+
| -------------- | ---- | ----------- | ------- |
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" |
54+
55+
### 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+
58+
### Specific Service Logic
59+
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.
60+
61+
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.
62+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SQS
2+
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).
3+
4+
## Specific trace semantic
5+
Following methods needs specific attention:
6+
7+
### 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.
10+
11+
### 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.
16+
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.
19+
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.
21+
22+
Unfortunately, this is not so easy to implement in JS:
23+
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).
24+
2. If async/await is used, context can be lost when returning data from async functions, for example:
25+
```js
26+
async function asyncRecv() {
27+
const data = await sqs.receiveMessage(recvParams).promise();
28+
// context of receiveMessage is set here
29+
return data;
30+
}
31+
32+
async function poll() {
33+
const result = await asyncRecv();
34+
// context is lost when asyncRecv returns. following spans are created with root context.
35+
await Promise.all(result.Messages.map((message) => this.processMessage(message)));
36+
}
37+
```
38+
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.

0 commit comments

Comments
 (0)