Skip to content

Commit c13c856

Browse files
committed
Add documentation for ADOT JS remote sampling
1 parent 5c65e02 commit c13c856

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/docs/getting-started/js-sdk/trace-manual-instr.mdx

+56
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,62 @@ const sdk = new opentelemetry.NodeSDK({
229229

230230
<SubSectionSeparator />
231231

232+
### Using X-Ray Remote Sampling
233+
The `@opentelemetry/sampler-aws-xray` package provides `Sampler` implementation for use with [X-Ray remote sampling](https://docs.aws.amazon.com/xray/latest/devguide/xray-console-sampling.html).
234+
235+
236+
```shell
237+
npm install @opentelemetry/sampler-aws-xray
238+
```
239+
240+
When initializing the `TracerProvider`, register the `AWSXRayRemoteSampler`. Moreover, you can configure the following attributes for the sampler.
241+
242+
| **Attribute** | **Type** | **Description** | **Default** |
243+
|-------------------|----------|----------------------------------------------------------------------|-------------------------|
244+
| `pollingInterval` | TimeSpan | Duration between polling the GetSamplingRules API | 5 minutes |
245+
| `endpoint` | string | Endpoint used to communicate with the `awsproxy` collector extension | `http://localhost:2000` |
246+
247+
248+
```js lineNumbers=true
249+
const { AWSXRayRemoteSampler } = require('@opentelemetry/sampler-aws-xray');
250+
const opentelemetry = require("@opentelemetry/sdk-node");
251+
const { Resource } = require("@opentelemetry/resources");
252+
const { BatchSpanProcessor} = require('@opentelemetry/sdk-trace-base');
253+
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
254+
const { AWSXRayPropagator } = require("@opentelemetry/propagator-aws-xray");
255+
const { AWSXRayIdGenerator } = require("@opentelemetry/id-generator-aws-xray");
256+
257+
258+
// Initialize resource, trace exporter, span processor, and ID generator
259+
const _resource = Resource.default().merge(new Resource({
260+
[SemanticResourceAttributes.SERVICE_NAME]: "remote-sampler-app",
261+
}));
262+
const _traceExporter = new OTLPTraceExporter();
263+
const _spanProcessor = new BatchSpanProcessor(_traceExporter);
264+
const _tracerConfig = {
265+
idGenerator: new AWSXRayIdGenerator(),
266+
}
267+
268+
const sdk = new opentelemetry.NodeSDK({
269+
textMapPropagator: new AWSXRayPropagator(),
270+
instrumentations: [
271+
new HttpInstrumentation(),
272+
new AwsInstrumentation({
273+
suppressInternalInstrumentation: true
274+
}),
275+
],
276+
resource: _resource,
277+
spanProcessor: _spanProcessor,
278+
traceExporter: _traceExporter,
279+
// add remote sampler
280+
sampler: new AWSXRayRemoteSampler(),
281+
});
282+
283+
sdk.configureTracerProvider(_tracerConfig, _spanProcessor);
284+
```
285+
286+
Please note that you will also need to [configure the OpenTelemetry collector](/docs/getting-started/remote-sampling) to allow the application to fetch sampling configuration for AWS X-Ray service.
287+
232288
## Custom Instrumentation
233289

234290
### Creating Custom Spans

src/docs/getting-started/remote-sampling.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Note that in order to use X-Ray remote sampling, your application's tracer must
1414
* [ADOT Java agent](https://aws-otel.github.io/docs/getting-started/java-sdk/trace-auto-instr#using-x-ray-remote-sampling)
1515
* [ADOT Java SDK](https://aws-otel.github.io/docs/getting-started/java-sdk/trace-manual-instr#using-x-ray-remote-sampling)
1616
* [ADOT Go SDK](https://aws-otel.github.io/docs/getting-started/go-sdk/trace-manual-instr#using-x-ray-remote-sampling)
17+
* [ADOT JS SDK](https://aws-otel.github.io/docs/getting-started/js-sdk/trace-manual-instr#using-x-ray-remote-sampling)
1718

1819
Enable the extension by adding this snippet to your collector configuration.
1920

0 commit comments

Comments
 (0)