Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for ADOT JS remote sampling #542

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/docs/getting-started/js-sdk/trace-manual-instr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,62 @@ const sdk = new opentelemetry.NodeSDK({

<SubSectionSeparator />

### Using X-Ray Remote Sampling
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).


```shell
npm install @opentelemetry/sampler-aws-xray
```

When initializing the `TracerProvider`, register the `AWSXRayRemoteSampler`. Moreover, you can configure the following attributes for the sampler.

| **Attribute** | **Type** | **Description** | **Default** |
|----------------------|----------|----------------------------------------------------------------------|-------------------------|
| `pollingIntervalMS` | number | Duration between polling the GetSamplingRules API | 5 minutes |
| `endpoint` | string | Endpoint used to communicate with the `awsproxy` collector extension | `http://localhost:2000` |


```js lineNumbers=true
const opentelemetry = require("@opentelemetry/sdk-node");
const { AWSXRayRemoteSampler } = require('@opentelemetry/sampler-aws-xray');
const { Resource } = require("@opentelemetry/resources");
const { BatchSpanProcessor} = require('@opentelemetry/sdk-trace-base');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
const { AWSXRayPropagator } = require("@opentelemetry/propagator-aws-xray");
const { AWSXRayIdGenerator } = require("@opentelemetry/id-generator-aws-xray");


// Initialize resource, trace exporter, span processor, and ID generator
const _resource = Resource.default().merge(new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "remote-sampler-app",
}));
const _traceExporter = new OTLPTraceExporter();
const _spanProcessor = new BatchSpanProcessor(_traceExporter);
const _tracerConfig = {
idGenerator: new AWSXRayIdGenerator(),
}

const sdk = new opentelemetry.NodeSDK({
textMapPropagator: new AWSXRayPropagator(),
instrumentations: [
new HttpInstrumentation(),
new AwsInstrumentation({
suppressInternalInstrumentation: true
}),
],
resource: _resource,
spanProcessor: _spanProcessor,
traceExporter: _traceExporter,
// add remote sampler
sampler: new AWSXRayRemoteSampler(),
});

sdk.configureTracerProvider(_tracerConfig, _spanProcessor);
```

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.

## Custom Instrumentation

### Creating Custom Spans
Expand Down
1 change: 1 addition & 0 deletions src/docs/getting-started/remote-sampling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Note that in order to use X-Ray remote sampling, your application's tracer must
* [ADOT Java agent](https://aws-otel.github.io/docs/getting-started/java-sdk/trace-auto-instr#using-x-ray-remote-sampling)
* [ADOT Java SDK](https://aws-otel.github.io/docs/getting-started/java-sdk/trace-manual-instr#using-x-ray-remote-sampling)
* [ADOT Go SDK](https://aws-otel.github.io/docs/getting-started/go-sdk/trace-manual-instr#using-x-ray-remote-sampling)
* [ADOT JS SDK](https://aws-otel.github.io/docs/getting-started/js-sdk/trace-manual-instr#using-x-ray-remote-sampling)

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

Expand Down