如何实现从功能应用程序到Spring Boot应用程序的分布式跟踪?

时间:2019-12-12 15:05:22

标签: java azure azure-application-insights distributed-tracing

我正在尝试实现从Azure函数应用到Spring Boot应用的分布式跟踪。我已经在功能应用程序中编写了以下代码:

 @FunctionName("functiontest")
public HttpResponseMessage carrierMaster(@HttpTrigger(name = "req", methods = {HttpMethod.GET},
        authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
                                         final ExecutionContext context) throws Exception {

    //String body = request.getBody().orElse(request.getQueryParameters().get("body"));
    //System.out.println("data is " +body);
    //test

    RequestTelemetryContext context1 = ThreadContext.getRequestTelemetryContext();
    RequestTelemetry requestTelemetry = context1.getHttpRequestTelemetry();

    String dependencyId = TelemetryCorrelationUtils.generateChildDependencyId();
    RemoteDependencyTelemetry dependencyTelemetry = new RemoteDependencyTelemetry("Send Data");

    dependencyTelemetry.setId(dependencyId);
    dependencyTelemetry.getContext().getOperation().setId(requestTelemetry.getContext().getOperation().getId());

    dependencyTelemetry.getContext().getOperation().setParentId(requestTelemetry.getId());

    Duration duration = new Duration(0,0,0,0,10); // set the duration 10 millisec as an example.
    dependencyTelemetry.setDuration(duration);

    TelemetryConfiguration configuration = TelemetryConfiguration.getActive();
    TelemetryClient telemetryClient = new TelemetryClient();
    telemetryClient.trackDependency(dependencyTelemetry);


    return request.createResponseBuilder(HttpStatus.OK).body("hello world")
            .build();
}

我有以下问题:

  1. 如何在Spring Boot应用程序中获取父ID和依赖ID?
  2. 如何在Spring Boot应用程序中设置依赖项ID或父ID?

有人可以帮我吗?

0 个答案:

没有答案