Java源码示例:org.eclipse.microprofile.opentracing.Traced
示例1
@GET
@Path("/randomDelay")
@Produces(MediaType.TEXT_PLAIN)
@Traced(operationName = "TracedEndpoint#demoRandomDelay")
public String randomDelay() {
long start = System.currentTimeMillis();
// 0-5 seconds random sleep
long sleep = Math.round(Math.random() * 5000);
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
return String.format("TracedEndpoint.randomDelay[0-5000], elapsed=%d", (end - start));
}
示例2
@GET
@Path("/bonjour")
@Produces(MediaType.TEXT_PLAIN)
@Traced(operationName = "bonjour")
public String bonjour() {
return "bonjour";
}
示例3
@GET
@Path("/untraced")
@Produces(MediaType.TEXT_PLAIN)
@Traced(false)
public String untraced() {
return "No tracing";
}
示例4
@GET
@Traced
@Path(REST_EXPLICITLY_TRACED)
@Produces(MediaType.TEXT_PLAIN)
public Response explicitlyTraced() {
return Response.ok().build();
}
示例5
/**
* Test class and endpoint with Traced annotation and operation name.
*
* @return OK response
*/
@Traced(operationName = ENDPOINT_OPERATION_NAME)
@GET
@Path(REST_OPERATION_CLASS_AND_METHOD_OP_NAME)
@Produces(MediaType.TEXT_PLAIN)
public Response classAndMethodOperationName() {
return Response.ok().build();
}
示例6
/**
* Shouldn't create a span.
* @return OK response
*/
@Traced(value = false)
@GET
@Path(REST_NOT_TRACED)
@Produces(MediaType.TEXT_PLAIN)
public Response notTraced() {
return Response.ok().build();
}
示例7
/**
* Traced with an explicit operation name.
* @return OK response
*/
@Traced(operationName = REST_OPERATION_NAME)
@GET
@Path(REST_OPERATION_NAME)
@Produces(MediaType.TEXT_PLAIN)
public Response operationName() {
return Response.ok().build();
}
示例8
@GET
@Path("/operation")
@Traced(operationName = "renamedOperation")
public Response operation(@Context HttpHeaders headers) {
assertActiveSpan();
return Response.status(Response.Status.OK).build();
}
示例9
@GET
@Path("/tracedFalseIn")
@Traced(operationName = "renamedOperation", value = false)
public Response tracedFalse() {
assertNoActiveSpan();
return Response.status(Response.Status.OK).build();
}
示例10
@Traced
@GET
@Path("/enabled")
public Response helloMethod() {
assertActiveSpan();
return Response.status(Response.Status.OK).build();
}
示例11
protected Traced closestTracedAnnotation(ResourceInfo resourceInfo) {
Traced tracedAnnotation = resourceInfo.getResourceMethod().getAnnotation(Traced.class);
if (tracedAnnotation == null) {
tracedAnnotation = resourceInfo.getResourceClass().getAnnotation(Traced.class);
}
return tracedAnnotation;
}
示例12
@Traced
public String call() {
// tag::client-registration[]
Client client = ClientTracingRegistrar.configure(ClientBuilder.newBuilder()).build();
// end::client-registration[]
try {
String response = client.target("http://localhost:8080")
.path("/simple")
.request()
.get(String.class);
return "Called an external service successfully, it responded: " + response;
} finally {
client.close();
}
}
示例13
@GET
@Traced
public String getTest() {
return "TEST";
}
示例14
@Traced
public void foo() {
}
示例15
@Traced
public List<Fruit> getFruits() {
return em.createNamedQuery("Fruits.findAll", Fruit.class).getResultList();
}
示例16
/**
* Method that we expect to be Traced.
*/
@Traced
public void annotatedClassMethodExplicitlyTraced() {
System.out.println("Called annotatedClassMethodExplicitlyTraced");
}
示例17
/**
* Method that we expect to be Traced with an operation name.
*/
@Traced(operationName = "explicitOperationName3")
public void annotatedClassMethodExplicitlyTracedWithOperationName() {
System.out.println("Called annotatedClassMethodExplicitlyTracedWithOperationName");
}
示例18
/**
* Method that we expect to be Traced.
*/
@Traced
public void annotatedMethodExplicitlyTraced() {
System.out.println("Called annotatedMethodExplicitlyTraced");
}
示例19
/**
* Method that we expect to not be Traced.
*/
@Traced(value = false)
public void annotatedMethodExplicitlyNotTraced() {
System.out.println("Called annotatedMethodExplicitlyNotTraced");
}
示例20
/**
* Method that we expect to be Traced with operation name.
*/
@Traced(operationName = "explicitOperationName2")
public void annotatedMethodExplicitlyTracedWithOpName() {
System.out.println("Called annotatedMethodExplicitlyTracedWithOpName");
}
示例21
/**
* Method that we expect to not be Traced with operation name.
*/
@Traced(value = false, operationName = "disabledOperationName")
public void annotatedMethodExplicitlyNotTracedWithOpName() {
System.out.println("Called annotatedMethodExplicitlyNotTracedWithOpName");
}
示例22
/**
* Method that we expect to not be Traced.
*/
@Traced(value = false)
public void annotatedClassMethodExplicitlyNotTraced() {
System.out.println("Called annotatedClassMethodExplicitlyNotTraced");
}
示例23
/**
* Method that we expect to be Traced explicitly.
*/
@Traced(operationName = "explicitOperationName1")
public void annotatedClassMethodExplicitlyTraced() {
System.out.println("Called annotatedClassMethodExplicitlyTraced");
}
示例24
/**
* Method that we expect to not be Traced.
*/
@Traced(operationName = "disabledOperationName", value = false)
public void annotatedClassMethodExplicitlyNotTracedWithOpName() {
System.out.println("Called annotatedClassMethodExplicitlyNotTracedWithOpName");
}
示例25
/**
* Method that we expect to be Traced explicitly.
*/
@Traced(operationName = "explicitOperationName4")
public void annotatedClassMethodExplicitlyTraced() {
System.out.println("Called annotatedClassMethodExplicitlyTraced");
}
示例26
@GET
@Traced(false)
@Path(TestServerWebServices.REST_SIMPLE_TEST)
@Produces(MediaType.TEXT_PLAIN)
Response disabledTracing();
示例27
protected boolean tracingDisabled(ResourceInfo resourceInfo) {
Traced traced = closestTracedAnnotation(resourceInfo);
return traced == null ? !builder.allTraced : !traced.value();
}
示例28
protected String operationName(ResourceInfo resourceInfo) {
Traced traced = closestTracedAnnotation(resourceInfo);
return traced != null && !traced.operationName().isEmpty() ? traced.operationName() : null;
}