sample-apps/spark-awssdkv1/src/main/java/com/amazon/sampleapp/App.java [70:126]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
          s3.listBuckets();

          return getXrayTraceId();
        });

    /** record a start time for each request */
    before(
        (req, res) -> {
          req.attribute(REQUEST_START_TIME, System.currentTimeMillis());
        });

    after(
        (req, res) -> {
          // for below paths we don't emit metric data
          if (req.pathInfo().equals("/outgoing-http-call")) {
            String statusCode = String.valueOf(res.status());
            // calculate return time
            Long requestStartTime = req.attribute(REQUEST_START_TIME);
            metricEmitter.emitReturnTimeMetric(
                System.currentTimeMillis() - requestStartTime, req.pathInfo(), statusCode);

            // emit http request load size
            int loadSize = req.contentLength() + mimicPayloadSize();
            metricEmitter.emitBytesSentMetric(loadSize, req.pathInfo(), statusCode);
            metricEmitter.updateTotalBytesSentMetric(loadSize, req.pathInfo(), statusCode);
            // mimic a queue size reporter
            int queueSizeChange = mimicQueueSizeChange();
            metricEmitter.emitQueueSizeChangeMetric(queueSizeChange, req.pathInfo(), statusCode);
            metricEmitter.updateActualQueueSizeMetric(queueSizeChange, req.pathInfo(), statusCode);
          }
        });

    exception(
        Exception.class,
        (exception, request, response) -> {
          // Handle the exception here
          exception.printStackTrace();
        });
  }

  // get x-ray trace id
  private static String getXrayTraceId() {
    String traceId = Span.current().getSpanContext().getTraceId();
    String xrayTraceId = "1-" + traceId.substring(0, 8) + "-" + traceId.substring(8);

    return String.format("{\"traceId\": \"%s\"}", xrayTraceId);
  }

  private static int mimicPayloadSize() {
    return ThreadLocalRandom.current().nextInt(100);
  }

  private static int mimicQueueSizeChange() {
    int newQueueSize = ThreadLocalRandom.current().nextInt(100);
    int queueSizeChange = newQueueSize - mimicQueueSize;
    mimicQueueSize = newQueueSize;
    return queueSizeChange;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



sample-apps/spark/src/main/java/com/amazon/sampleapp/App.java [83:139]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
          s3.listBuckets();

          return getXrayTraceId();
        });

    /** record a start time for each request */
    before(
        (req, res) -> {
          req.attribute(REQUEST_START_TIME, System.currentTimeMillis());
        });

    after(
        (req, res) -> {
          // for below paths we don't emit metric data
          if (req.pathInfo().equals("/outgoing-http-call")) {
            String statusCode = String.valueOf(res.status());
            // calculate return time
            Long requestStartTime = req.attribute(REQUEST_START_TIME);
            metricEmitter.emitReturnTimeMetric(
                System.currentTimeMillis() - requestStartTime, req.pathInfo(), statusCode);

            // emit http request load size
            int loadSize = req.contentLength() + mimicPayloadSize();
            metricEmitter.emitBytesSentMetric(loadSize, req.pathInfo(), statusCode);
            metricEmitter.updateTotalBytesSentMetric(loadSize, req.pathInfo(), statusCode);
            // mimic a queue size reporter
            int queueSizeChange = mimicQueueSizeChange();
            metricEmitter.emitQueueSizeChangeMetric(queueSizeChange, req.pathInfo(), statusCode);
            metricEmitter.updateActualQueueSizeMetric(queueSizeChange, req.pathInfo(), statusCode);
          }
        });

    exception(
        Exception.class,
        (exception, request, response) -> {
          // Handle the exception here
          exception.printStackTrace();
        });
  }

  // get x-ray trace id
  private static String getXrayTraceId() {
    String traceId = Span.current().getSpanContext().getTraceId();
    String xrayTraceId = "1-" + traceId.substring(0, 8) + "-" + traceId.substring(8);

    return String.format("{\"traceId\": \"%s\"}", xrayTraceId);
  }

  private static int mimicPayloadSize() {
    return ThreadLocalRandom.current().nextInt(100);
  }

  private static int mimicQueueSizeChange() {
    int newQueueSize = ThreadLocalRandom.current().nextInt(100);
    int queueSizeChange = newQueueSize - mimicQueueSize;
    mimicQueueSize = newQueueSize;
    return queueSizeChange;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



