在x射线控制台aws中找不到跟踪

kzipqqlq  于 2021-07-15  发布在  Java
关注(0)|答案(1)|浏览(376)

我尝试了多种方法,但似乎没有任何效果
这是我所做的,
创建了一个cloud9示例,启动了一个maven应用程序,添加了aws sdk java、x-ray core、x-ray instrumentor、x-ray sdk依赖项,创建了dynamodb客户端,运行了应用程序,插入了数据,但找不到错误子段。手动添加段,错误消失但没有痕迹。
创建spring启动应用程序,添加相同的依赖项,添加xray servlet过滤器,添加begin segment,begin subsegment,没有错误但没有痕迹。
我有更多的方法,但这些似乎是非常接近。我也没有安装任何代理或守护程序。谁能告诉我哪里出错了吗?
我正在尝试创建一个简单的java应用程序,甚至是一个页面来在dynamodb中插入数据并获取它的踪迹。

nxagd54h

nxagd54h1#

我没有在java共享节点js示例方面的工作经验,希望对您有所帮助。测试结果如下:https://github.com/aws-samples/aws-xray-sdk-node-sample

const AWSXRay = require('aws-xray-sdk');
const XRayExpress = AWSXRay.express;
const express = require('express');

// Capture all AWS clients we create
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
AWS.config.update({region: process.env.DEFAULT_AWS_REGION || 'us-west-2'});

// Capture all outgoing https requests
AWSXRay.captureHTTPsGlobal(require('https'));
const https = require('https');

// Capture MySQL queries
const mysql = AWSXRay.captureMySQL(require('mysql'));

const app = express();
const port = 3000;

app.use(XRayExpress.openSegment('SampleSite'));

app.get('/', (req, res) => {
  const seg = AWSXRay.getSegment();
  const sub = seg.addNewSubsegment('customSubsegment');
  setTimeout(() => {
    sub.close();
    res.sendFile(`${process.cwd()}/index.html`);
  }, 500);
});

app.get('/aws-sdk/', (req, res) => {
  const ddb = new AWS.DynamoDB();
  const ddbPromise = ddb.listTables().promise();

  ddbPromise.then(function(data) {
    res.send(`ListTables result:\n ${JSON.stringify(data)}`);
  }).catch(function(err) {
    res.send(`Encountered error while calling ListTables: ${err}`);
  });
});

app.get('/http-request/', (req, res) => {
  const endpoint = 'https://amazon.com/';
  https.get(endpoint, (response) => {
    response.on('data', () => {});

    response.on('error', (err) => {
      res.send(`Encountered error while making HTTPS request: ${err}`);
    });

    response.on('end', () => {
      res.send(`Successfully reached ${endpoint}.`);
    });
  });
});

app.get('/mysql/', (req, res) => {
  const mysqlConfig = require('./mysql-config.json');
  const config = mysqlConfig.config;
  const table = mysqlConfig.table;

  if (!config.user || !config.database || !config.password || !config.host || !table) {
    res.send('Please correctly populate mysql-config.json');
    return;
  }

  const connection = mysql.createConnection(config);
  connection.query(`SELECT * FROM ${table}`, (err, results, fields) => {
    if (err) {
      res.send(`Encountered error while querying ${table}: ${err}`);
      return;
    }
    res.send(`Retrieved the following results from ${table}:\n${results}`);
  });

  connection.end();
});

app.use(XRayExpress.closeSegment());

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

相关问题