UNPKG

skywalking-backend-js

Version:

The NodeJS agent for Apache SkyWalking

78 lines 3.44 kB
"use strict"; /*! * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var ContextManager_1 = tslib_1.__importDefault(require("../trace/context/ContextManager")); var Component_1 = require("../trace/Component"); var Tag_1 = tslib_1.__importDefault(require("../Tag")); var Tracing_pb_1 = require("../proto/language-agent/Tracing_pb"); var SDK2_1 = require("../aws/SDK2"); var AWS2DynamoDBPlugin = /** @class */ (function () { function AWS2DynamoDBPlugin() { this.module = 'aws-sdk'; this.versions = '2.*'; } AWS2DynamoDBPlugin.prototype.install = function (installer) { var AWS = SDK2_1.getAWS(installer); var DocumentClient = AWS.DynamoDB.DocumentClient; function instrument(name) { var _func = DocumentClient.prototype[name]; DocumentClient.prototype[name] = function (params, callback) { var span = ContextManager_1.default.current.newExitSpan("AWS/DynamoDB/" + name, Component_1.Component.AWS_DYNAMODB, Component_1.Component.HTTP); span.component = Component_1.Component.AWS_DYNAMODB; span.layer = Tracing_pb_1.SpanLayer.DATABASE; // span.peer = `${this.service.endpoint.host ?? '<unknown>'}:${this.service.endpoint.port ?? '<unknown>'}`; span.tag(Tag_1.default.dbType('DynamoDB')); span.tag(Tag_1.default.dbStatement(name)); return SDK2_1.execute(span, this, _func, params, callback); }; } instrument('batchGet'); instrument('batchWrite'); instrument('delete'); instrument('get'); instrument('put'); instrument('query'); instrument('scan'); instrument('update'); instrument('transactGet'); instrument('transactWrite'); }; return AWS2DynamoDBPlugin; }()); // noinspection JSUnusedGlobalSymbols exports.default = new AWS2DynamoDBPlugin(); // // Example code for test maybe: // const AWS = require("aws-sdk"); // AWS.config.update({region: 'your-region'}); // const dynamo = new AWS.DynamoDB.DocumentClient(); // function callback(err, data) { // console.log('... callback err:', err); // console.log('... callback data:', data); // } // const data = {TableName: "table-name", Item: {id: 1, name: 'Bob'}}; // dynamo.put(data, callback); // // OR: // dynamo.put(data).send(callback); // // OR: // dynamo.put(data).promise() // .then(r => { console.log('... promise res:', r); }) // .catch(e => { console.log('... promise err:', e); }); //# sourceMappingURL=AWS2DynamoDBPlugin.js.map