【问题标题】:Trace not found in X-Ray Console AWS在 X-Ray 控制台 AWS 中找不到跟踪
【发布时间】:2021-06-21 00:55:56
【问题描述】:

我尝试了多种方法,但似乎没有任何效果

这就是我所做的,

  1. 创建了 Cloud9 实例,启动了 maven 应用程序,添加了 aws sdk java、x-ray core、x-ray instrumentor、x-ray sdk 依赖项,创建了 DynamoDB 客户端运行了应用程序,插入了数据但未找到错误子段。手动添加的段,错误消失但没有任何痕迹。
  2. 创建 Spring Boot 应用,添加相同的依赖项,添加 Xray servlet 过滤器,添加开始段,开始子段,没有错误但没有痕迹。

我也有更多方法,但这些方法似乎非常接近。我也没有安装任何代理或守护进程。谁能告诉我哪里出错了?

我正在尝试创建一个简单的 java 应用程序,甚至是一个页面来在 DynamoDB 中插入数据并获取跟踪信息。

【问题讨论】:

    标签: java spring amazon-web-services maven aws-xray


    【解决方案1】:

    我没有在此处进行 Java 共享的经验 Node 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}!`));
    

    【讨论】:

      猜你喜欢
      • 2021-05-18
      • 2020-07-08
      • 1970-01-01
      • 2023-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多