Search in sources :

Example 1 with TracingWorkflow

use of io.temporal.samples.tracing.workflow.TracingWorkflow in project samples-java by temporalio.

the class Starter method main.

public static void main(String[] args) {
    String type = "OpenTelemetry";
    if (args.length == 1) {
        type = args[0];
    }
    // Set the OpenTracing client interceptor
    WorkflowClientOptions clientOptions = WorkflowClientOptions.newBuilder().setInterceptors(new OpenTracingClientInterceptor(JaegerUtils.getJaegerOptions(type))).build();
    WorkflowClient client = WorkflowClient.newInstance(service, clientOptions);
    WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setWorkflowId("tracingWorkflow").setTaskQueue(TASK_QUEUE_NAME).build();
    // Create typed workflow stub
    TracingWorkflow workflow = client.newWorkflowStub(TracingWorkflow.class, workflowOptions);
    // Convert to untyped and start it with signalWithStart
    WorkflowStub untyped = WorkflowStub.fromTyped(workflow);
    untyped.signalWithStart("setLanguage", new Object[] { "Spanish" }, new Object[] { "John" });
    String greeting = untyped.getResult(String.class);
    System.out.println("Greeting: " + greeting);
    System.exit(0);
}
Also used : WorkflowClientOptions(io.temporal.client.WorkflowClientOptions) WorkflowStub(io.temporal.client.WorkflowStub) TracingWorkflow(io.temporal.samples.tracing.workflow.TracingWorkflow) WorkflowClient(io.temporal.client.WorkflowClient) WorkflowOptions(io.temporal.client.WorkflowOptions) OpenTracingClientInterceptor(io.temporal.opentracing.OpenTracingClientInterceptor)

Example 2 with TracingWorkflow

use of io.temporal.samples.tracing.workflow.TracingWorkflow in project samples-java by temporalio.

the class TracingTest method testReportSpans.

@Test
public void testReportSpans() {
    WorkflowClient client = testWorkflowRule.getWorkflowClient();
    WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).build();
    TracingWorkflow workflow = client.newWorkflowStub(TracingWorkflow.class, workflowOptions);
    // Convert to untyped and start it with signalWithStart
    WorkflowStub untyped = WorkflowStub.fromTyped(workflow);
    untyped.signalWithStart("setLanguage", new Object[] { "Spanish" }, new Object[] { "John" });
    String greeting = untyped.getResult(String.class);
    assertEquals("Hola John", greeting);
    List<JaegerSpan> reportedSpans = reporter.getSpans();
    assertNotNull(reportedSpans);
    assertTrue(reportedSpans.size() == 6);
}
Also used : WorkflowStub(io.temporal.client.WorkflowStub) TracingWorkflow(io.temporal.samples.tracing.workflow.TracingWorkflow) JaegerSpan(io.jaegertracing.internal.JaegerSpan) WorkflowClient(io.temporal.client.WorkflowClient) WorkflowOptions(io.temporal.client.WorkflowOptions) Test(org.junit.Test)

Aggregations

WorkflowClient (io.temporal.client.WorkflowClient)2 WorkflowOptions (io.temporal.client.WorkflowOptions)2 WorkflowStub (io.temporal.client.WorkflowStub)2 TracingWorkflow (io.temporal.samples.tracing.workflow.TracingWorkflow)2 JaegerSpan (io.jaegertracing.internal.JaegerSpan)1 WorkflowClientOptions (io.temporal.client.WorkflowClientOptions)1 OpenTracingClientInterceptor (io.temporal.opentracing.OpenTracingClientInterceptor)1 Test (org.junit.Test)1