春天休息模板与aws x射线

时间:2018-01-15 10:47:56

标签: spring amazon-web-services aws-lambda aws-api-gateway aws-xray

我想跟踪使用aws x-ray部署为aws lambdas的spring微服务之间的调用。

设置如下:

  1. 微服务A,api端点部署为aws lambda

  2. 微服务B,api端点部署为aws lambda,通过https调用微服务A

  3. 两个微服务都包含xray的aws依赖关系:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.amazonaws</groupId>
                <artifactId>aws-xray-recorder-sdk-bom</artifactId>
                <version>1.2.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-xray-recorder-sdk-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-xray-recorder-sdk-apache-http</artifactId>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-xray-recorder-sdk-aws-sdk</artifactId>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-xray-recorder-sdk-aws-sdk-instrumentor</artifactId>
        </dependency>
    </dependencies>
    

    对于这两种微服务,已通过无服务器应用程序模型sam.yaml文件启用了跟踪:

    Resources:
      FunctionA:
        Type: AWS::Serverless::Function
        Properties:
          Handler: example.HandlerA::handleRequest
          Runtime: java8
          CodeUri: target/foo.jar
          MemorySize: 512
          Tracing: Active
          Policies:
            - AWSLambdaBasicExecutionRole
            - AWSXrayWriteOnlyAccess 
          Timeout: 20
          Events:
            GetResource:
              Type: Api
              Properties:
                Path: /{proxy+}
                Method: any
    

    虽然我可以在X射线网络界面中看到针对服务A和B的各个调用的跟踪,但是在A上调用B不会显示为复合跟踪。

    有什么想法吗?可能我需要实例化一个servlet过滤器。仅包含依赖关系是不够的,对吗?

1 个答案:

答案 0 :(得分:3)

此时,Amazon API网关为not propagating x-amzn-trace-id headers

听起来好像您的AWS Lambda函数可能部署在API网关端点之后。由于API Gateway与AWS X-Ray的集成存在此限制,因此今天无法将此操作作为一个连续跟踪进行跟踪。

在单个连续跟踪中跟踪此操作的一种方法是让微服务B直接使用AWS Lambda Invoke API调用微服务A.此API确实尊重x-amzn-trace-id标头(会自动添加到Invoke请求中,因为您已在项目中包含aws-xray-recorder-sdk-aws-sdk-instrumentor工件。