首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在X射线控制台AWS中找不到跟踪

在X射线控制台AWS中找不到跟踪
EN

Stack Overflow用户
提问于 2021-03-24 10:17:59
回答 1查看 436关注 0票数 0

我尝试过多种方法,但似乎没有什么效果。

以下是我所做的,

  1. 创建了Cloud9实例,启动了maven应用程序,添加了aws、x射线核心、x射线仪器仪表、x射线sdk依赖项,创建了运行DynamoDB客户端的应用程序,插入了数据但没有找到错误子段。手动添加段,错误消失但没有跟踪。
  2. 创建Spring,添加了相同的依赖项,添加了Xray servlet过滤器,添加了begin段,begin子段,没有错误但没有跟踪。

我也有更多的方法,但这些似乎非常接近。此外,我还没有安装任何代理或守护进程。有人能看出我哪里出了问题吗?

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

EN

回答 1

Stack Overflow用户

发布于 2021-03-24 12:43:20

我没有在这里进行java共享的经验,Node示例希望这会有所帮助。测试过这个:https://github.com/aws-samples/aws-xray-sdk-node-sample

代码语言:javascript
复制
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}!`));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66778931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档