Skip to content

Commit

Permalink
Updates isRoot logic to no longer assume root when calling newTrace. (#…
Browse files Browse the repository at this point in the history
…892)

* Updates isRoot logic to no longer assume root when calling newTrace. This can be called multiple times when running child flows.
  • Loading branch information
bryanatkinson authored Sep 13, 2024
1 parent 75f3014 commit d47084c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions js/core/src/tracing/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export async function newTrace<T>(
},
fn: (metadata: SpanMetadata, rootSpan: ApiSpan) => Promise<T>
) {
// This is the root node only if we haven't previously started a trace.
const isRoot = traceMetadataAls.getStore() ? false : true;
const traceMetadata = traceMetadataAls.getStore() || {
paths: new Set<PathMetadata>(),
timestamp: performance.now(),
Expand All @@ -55,7 +57,7 @@ export async function newTrace<T>(
{
metadata: {
name: opts.name,
isRoot: true,
isRoot,
},
labels: opts.labels,
links: opts.links,
Expand Down Expand Up @@ -83,7 +85,7 @@ export async function runInNewSpan<T>(
const isInRoot = parentStep?.isRoot === true;
return await tracer.startActiveSpan(
opts.metadata.name,
{ links: opts.links },
{ links: opts.links, root: opts.metadata.isRoot },
async (otSpan) => {
if (opts.labels) otSpan.setAttributes(opts.labels);
try {
Expand Down

0 comments on commit d47084c

Please sign in to comment.