-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracing support improvements #1819
Changes from 10 commits
97561e8
6e15b18
47d1002
acc4296
ff21f0a
16fdb02
74028eb
1a44c22
a69f5be
172cf89
aa24cb9
b9744df
412552f
9f1d16f
2e02ef9
c6dc546
355c613
8fb166f
1078bf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ public WorkflowOutput execute(WorkflowInput input) { | |
Workflow.getInfo().getRunId(), | ||
rootSpanContext) | ||
.start(); | ||
try (Scope scope = tracer.scopeManager().activate(workflowRunSpan)) { | ||
try (Scope ignored = tracer.scopeManager().activate(workflowRunSpan)) { | ||
return super.execute(input); | ||
} catch (Throwable t) { | ||
if (t instanceof DestroyWorkflowThreadError) { | ||
|
@@ -82,4 +82,81 @@ public WorkflowOutput execute(WorkflowInput input) { | |
workflowRunSpan.finish(); | ||
} | ||
} | ||
|
||
@Override | ||
public void handleSignal(SignalInput input) { | ||
Tracer tracer = options.getTracer(); | ||
SpanContext rootSpanContext = | ||
contextAccessor.readSpanContextFromHeader(input.getHeader(), tracer); | ||
Span workflowSignalSpan = | ||
spanFactory | ||
.createWorkflowSignalSpan( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't read this closely, but what many of our other SDKs do is make this span a child-of the original inbound workflow-level span and a follows-from the inbound signal-level span. Is that what's happening here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you elaborate more on this (a link, doc or something related to other SDKs)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you view this |
||
tracer, | ||
input.getSignalName(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend, to match other SDKs, that workflow inbound signal, query, and update span names be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
Workflow.getInfo().getWorkflowId(), | ||
Workflow.getInfo().getRunId(), | ||
rootSpanContext) | ||
.start(); | ||
try (Scope ignored = tracer.scopeManager().activate(workflowSignalSpan)) { | ||
super.handleSignal(input); | ||
} catch (Throwable t) { | ||
if (t instanceof DestroyWorkflowThreadError) { | ||
spanFactory.logEviction(workflowSignalSpan); | ||
} else { | ||
spanFactory.logFail(workflowSignalSpan, t); | ||
} | ||
throw t; | ||
} finally { | ||
workflowSignalSpan.finish(); | ||
} | ||
} | ||
|
||
@Override | ||
public QueryOutput handleQuery(QueryInput input) { | ||
Tracer tracer = options.getTracer(); | ||
SpanContext rootSpanContext = | ||
contextAccessor.readSpanContextFromHeader(input.getHeader(), tracer); | ||
Span workflowQuerySpan = | ||
spanFactory.createWorkflowQuerySpan(tracer, input.getQueryName(), rootSpanContext).start(); | ||
try (Scope ignored = tracer.scopeManager().activate(workflowQuerySpan)) { | ||
return super.handleQuery(input); | ||
} catch (Throwable t) { | ||
if (t instanceof DestroyWorkflowThreadError) { | ||
spanFactory.logEviction(workflowQuerySpan); | ||
} else { | ||
spanFactory.logFail(workflowQuerySpan, t); | ||
} | ||
throw t; | ||
} finally { | ||
workflowQuerySpan.finish(); | ||
} | ||
} | ||
|
||
@Override | ||
public UpdateOutput executeUpdate(UpdateInput input) { | ||
Tracer tracer = options.getTracer(); | ||
SpanContext rootSpanContext = | ||
contextAccessor.readSpanContextFromHeader(input.getHeader(), tracer); | ||
Span workflowSignalSpan = | ||
spanFactory | ||
.createWorkflowStartUpdateSpan( | ||
tracer, | ||
input.getUpdateName(), | ||
Workflow.getInfo().getWorkflowId(), | ||
Workflow.getInfo().getRunId(), | ||
rootSpanContext) | ||
.start(); | ||
try (Scope ignored = tracer.scopeManager().activate(workflowSignalSpan)) { | ||
return super.executeUpdate(input); | ||
} catch (Throwable t) { | ||
if (t instanceof DestroyWorkflowThreadError) { | ||
spanFactory.logEviction(workflowSignalSpan); | ||
} else { | ||
spanFactory.logFail(workflowSignalSpan, t); | ||
} | ||
throw t; | ||
} finally { | ||
workflowSignalSpan.finish(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -77,6 +77,46 @@ public Tracer.SpanBuilder createChildWorkflowStartSpan( | |||||
return createSpan(context, tracer, null, References.CHILD_OF); | ||||||
} | ||||||
|
||||||
public Tracer.SpanBuilder createExternalWorkflowSignalSpan( | ||||||
Tracer tracer, String signalName, String workflowId, String runId) { | ||||||
SpanCreationContext context = | ||||||
SpanCreationContext.newBuilder() | ||||||
.setSpanOperationType(SpanOperationType.SIGNAL_EXTERNAL_WORKFLOW) | ||||||
.setActionName(signalName) | ||||||
.setWorkflowId(workflowId) | ||||||
.setRunId(runId) | ||||||
.build(); | ||||||
return createSpan(context, tracer, null, References.CHILD_OF); | ||||||
} | ||||||
|
||||||
public Tracer.SpanBuilder createWorkflowSignalSpan( | ||||||
Tracer tracer, String signalName, String workflowId, String runId) { | ||||||
SpanCreationContext context = | ||||||
SpanCreationContext.newBuilder() | ||||||
.setSpanOperationType(SpanOperationType.SIGNAL_WORKFLOW) | ||||||
.setActionName(signalName) | ||||||
.setWorkflowId(workflowId) | ||||||
.setRunId(runId) | ||||||
.build(); | ||||||
return createSpan(context, tracer, null, References.FOLLOWS_FROM); | ||||||
} | ||||||
|
||||||
public Tracer.SpanBuilder createWorkflowSignalSpan( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Can you change the names for handle-based spans instead of overloads where the caller can't know they are creating different operation types just by calling different overloads? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
Tracer tracer, | ||||||
String signalName, | ||||||
String workflowId, | ||||||
String runId, | ||||||
SpanContext workflowSignalSpanContext) { | ||||||
SpanCreationContext context = | ||||||
SpanCreationContext.newBuilder() | ||||||
.setSpanOperationType(SpanOperationType.HANDLE_SIGNAL) | ||||||
.setActionName(signalName) | ||||||
.setWorkflowId(workflowId) | ||||||
.setRunId(runId) | ||||||
.build(); | ||||||
return createSpan(context, tracer, workflowSignalSpanContext, References.FOLLOWS_FROM); | ||||||
} | ||||||
|
||||||
public Tracer.SpanBuilder createContinueAsNewWorkflowStartSpan( | ||||||
Tracer tracer, String continueAsNewWorkflowType, String workflowId, String parentRunId) { | ||||||
SpanCreationContext context = | ||||||
|
@@ -133,6 +173,56 @@ public Tracer.SpanBuilder createActivityRunSpan( | |||||
return createSpan(context, tracer, activityStartSpanContext, References.FOLLOWS_FROM); | ||||||
} | ||||||
|
||||||
public Tracer.SpanBuilder createWorkflowStartUpdateSpan( | ||||||
Tracer tracer, String updateName, String workflowId, String runId) { | ||||||
SpanCreationContext context = | ||||||
SpanCreationContext.newBuilder() | ||||||
.setSpanOperationType(SpanOperationType.UPDATE_WORKFLOW) | ||||||
.setActionName(updateName) | ||||||
.setWorkflowId(workflowId) | ||||||
.setRunId(runId) | ||||||
.build(); | ||||||
return createSpan(context, tracer, null, References.FOLLOWS_FROM); | ||||||
} | ||||||
|
||||||
public Tracer.SpanBuilder createWorkflowStartUpdateSpan( | ||||||
Tracer tracer, | ||||||
String updateName, | ||||||
String workflowId, | ||||||
String runId, | ||||||
SpanContext workflowSignalSpanContext) { | ||||||
SpanCreationContext context = | ||||||
SpanCreationContext.newBuilder() | ||||||
.setSpanOperationType(SpanOperationType.HANDLE_UPDATE) | ||||||
.setActionName(updateName) | ||||||
.setWorkflowId(workflowId) | ||||||
.setRunId(runId) | ||||||
.build(); | ||||||
return createSpan(context, tracer, workflowSignalSpanContext, References.FOLLOWS_FROM); | ||||||
} | ||||||
|
||||||
public Tracer.SpanBuilder createWorkflowQuerySpan( | ||||||
Tracer tracer, String updateName, String workflowId, String runId) { | ||||||
SpanCreationContext context = | ||||||
SpanCreationContext.newBuilder() | ||||||
.setSpanOperationType(SpanOperationType.QUERY_WORKFLOW) | ||||||
.setActionName(updateName) | ||||||
.setWorkflowId(workflowId) | ||||||
.setRunId(runId) | ||||||
.build(); | ||||||
return createSpan(context, tracer, null, References.FOLLOWS_FROM); | ||||||
} | ||||||
|
||||||
public Tracer.SpanBuilder createWorkflowQuerySpan( | ||||||
Tracer tracer, String queryName, SpanContext workflowSignalSpanContext) { | ||||||
SpanCreationContext context = | ||||||
SpanCreationContext.newBuilder() | ||||||
.setSpanOperationType(SpanOperationType.HANDLE_QUERY) | ||||||
.setActionName(queryName) | ||||||
.build(); | ||||||
return createSpan(context, tracer, workflowSignalSpanContext, References.FOLLOWS_FROM); | ||||||
} | ||||||
|
||||||
@SuppressWarnings("deprecation") | ||||||
public void logFail(Span toSpan, Throwable failReason) { | ||||||
toSpan.setTag(StandardTagNames.FAILED, true); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our other SDKs, query spans also have workflow ID and run ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that
handleQuery
is not executed within a workflow thread, leading to non-deterministic errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm, are you saying change this to the above errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you are not setting the workflow ID and run ID on
HANDLE_QUERY
. You should set those the same way you do forHANDLE_SIGNAL
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that a span without these tags is ok, but I'll let y'all decide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the options are either no span or a span without those tags. I have no preference.
Regardless of which we go with we will need to open an issue to address this when we fix
getInfo
in query handlers , but I don't think that should block this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concur, will let you make the call on tagless span vs no span. I don't have a super-strong opinion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it would be better to have a tagless span since the span itself is useful for tracing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me