Skip to content

Commit

Permalink
add name to no-op spans (#2386)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Mar 22, 2024
1 parent 2f488c4 commit 970f55f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/effect/src/internal/core-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ export const makeSpan = (
core.sync(() => {
const enabled = FiberRefs.getOrDefault(fiberRefs, core.currentTracerEnabled)
if (enabled === false) {
return core.noopSpan
return core.noopSpan(name)
}

const context = FiberRefs.getOrDefault(fiberRefs, core.currentContext)
Expand Down
12 changes: 9 additions & 3 deletions packages/effect/src/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3091,8 +3091,7 @@ export const currentSpanFromFiber = <A, E>(fiber: Fiber.RuntimeFiber<A, E>): Opt
return span !== undefined && span._tag === "Span" ? Option.some(span) : Option.none()
}

/** @internal */
export const noopSpan: Tracer.Span = globalValue("effect/Tracer/noopSpan", () => ({
const NoopSpanProto: Tracer.Span = {
_tag: "Span",
spanId: "noop",
traceId: "noop",
Expand All @@ -3111,4 +3110,11 @@ export const noopSpan: Tracer.Span = globalValue("effect/Tracer/noopSpan", () =>
attribute() {},
event() {},
end() {}
}))
}

/** @internal */
export const noopSpan = (name: string): Tracer.Span => {
const span = Object.create(NoopSpanProto)
span.name = name
return span
}
3 changes: 2 additions & 1 deletion packages/effect/test/Tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ describe("Tracer", () => {
Effect.withTracerEnabled(true)
)

assert.deepEqual(span.name, "noop")
assert.deepEqual(span.name, "A")
assert.deepEqual(span.spanId, "noop")
assert.deepEqual(spanB.name, "B")
}))
})

0 comments on commit 970f55f

Please # to comment.