This sample shows how to use @opentelemetry/instrumentation-aws-sdk to instrument listTables call on DynamoDB client in AWS SDK for JavaScript.
The example exports spans data to Console
. You can also export it to Jaeger
by setting JAEGER_ENABLED
environment variable.
Complete the following tasks:
- Install Node.js by following these steps:
- Install nvm.
- Use node v22.x.x by running
nvm use
ornvm use 22
in a terminal window. - Verify that node is installed by running
node -v
in a terminal window and confirm that it shows the latest version ofv22
, such asv22.10.0
).
- Run
npm install
to install the dependencies. - If you don't have an AWS account, create one.
- If you're an Amazon employee, see the internal wiki for creating an AWS account.
- Install the AWS CLI.
- Verify that the AWS CLI is installed by running
aws
in a terminal window.
- Verify that the AWS CLI is installed by running
- Set up AWS Shared Credential File.
- Your
~/.aws/credentials
(%UserProfile%\.aws\credentials
on Windows) should look like the following:[default] aws_access_key_id = <ACCESS_KEY> aws_secret_access_key = <SECRET_ACCESS_KEY>
- Your
~/.aws/config
(%UserProfile%\.aws\config
on Windows) should look like the following:[default] region = us-west-2
- Your
- (Optional) Setup Jaeger Tracing: needs to be running on
localhost
port16686
.
The test code from this package uses AwsInstrumentation
from @opentelemetry/instrumentation-aws-sdk
to instrument listTables call on DynamoDB client.
Refer to the npm package for custom instrumentation options which can be passed.
node --run instrument
$ node --run instrument
{
resource: {
attributes: {
'service.name': 'test-aws-sdk',
'telemetry.sdk.language': 'nodejs',
'telemetry.sdk.name': 'opentelemetry',
'telemetry.sdk.version': '1.26.0'
}
},
instrumentationScope: {
name: '@opentelemetry/instrumentation-aws-sdk',
version: '0.44.0',
schemaUrl: undefined
},
traceId: 'ff028d034969fc05c6e47ee1eaf2faca',
parentId: undefined,
traceState: undefined,
name: 'DynamoDB.ListTables',
id: 'ca2f4591b4b974d9',
kind: 2,
timestamp: 1729188000802000,
duration: 116957.333,
attributes: {
'rpc.system': 'aws-api',
'rpc.method': 'ListTables',
'rpc.service': 'DynamoDB',
'db.system': 'dynamodb',
'db.operation': 'ListTables',
'aws.region': 'us-west-2',
'aws.request.id': 'NI9DR2PE921C79HS5U5QSOHM2VVV4KQNSO5AEMVJF66Q9ASUAAJG',
'http.status_code': 200,
'aws.dynamodb.table_count': 20
},
status: { code: 0 },
events: [],
links: []
}
For JS SDK v2, pleas refer to the v2 branch.