/** * Generates child TraceParent by retrieving values from ThreadLocal. * @return Outbound Traceparent */ public static String generateChildDependencyTraceparent() { try { RequestTelemetryContext context = ThreadContext.getRequestTelemetryContext(); //check if context is null, no incoming request is present. // This is likely worker role scenario, where a worker is trying // to create a new outbound call, so generate a new traceparent. if (context == null) { return new Traceparent().toString(); } RequestTelemetry requestTelemetry = context.getHttpRequestTelemetry(); String traceId = requestTelemetry.getContext().getOperation().getId(); Traceparent tp = new Traceparent(0, traceId, null, context.getTraceflag()); // We need to propagate full blown traceparent header. return tp.toString(); } catch (Exception ex) { InternalLogger.INSTANCE.error("Failed to generate child ID. Exception information: %s", ex.toString()); InternalLogger.INSTANCE.trace("Stack trace generated is %s", ExceptionUtils.getStackTrace(ex)); } return null; }
/** * Generates child TraceParent by retrieving values from ThreadLocal. * @return Outbound Traceparent */ public static String generateChildDependencyTraceparent() { try { RequestTelemetryContext context = ThreadContext.getRequestTelemetryContext(); //check if context is null, no incoming request is present. // This is likely worker role scenario, where a worker is trying // to create a new outbound call, so generate a new traceparent. if (context == null) { return new Traceparent().toString(); } RequestTelemetry requestTelemetry = context.getHttpRequestTelemetry(); String traceId = requestTelemetry.getContext().getOperation().getId(); Traceparent tp = new Traceparent(0, traceId, null, context.getTraceflag()); // We need to propagate full blown traceparent header. return tp.toString(); } catch (Exception ex) { InternalLogger.INSTANCE.error("Failed to generate child ID. Exception information: %s", ex.toString()); InternalLogger.INSTANCE.trace("Stack trace generated is %s", ExceptionUtils.getStackTrace(ex)); } return null; }