Skip to content
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

add unique identifier to Tracer.ParentSpan tag #2459

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-frogs-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add unique identifier to Tracer.ParentSpan tag
4 changes: 2 additions & 2 deletions packages/effect/src/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ export const withSpan: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
} | undefined
Expand All @@ -2120,7 +2120,7 @@ export const withSpan: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
} | undefined
Expand Down
24 changes: 12 additions & 12 deletions packages/effect/src/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5109,7 +5109,7 @@ export const currentSpan: Effect<Tracer.Span, Cause.NoSuchElementException> = ef
* @since 2.0.0
* @category tracing
*/
export const currentParentSpan: Effect<Tracer.ParentSpan, Cause.NoSuchElementException> = effect.currentParentSpan
export const currentParentSpan: Effect<Tracer.AnySpan, Cause.NoSuchElementException> = effect.currentParentSpan

/**
* @since 2.0.0
Expand All @@ -5131,12 +5131,12 @@ export const spanLinks: Effect<Chunk.Chunk<Tracer.SpanLink>> = effect.spanLinks
*/
export const linkSpans: {
(
span: Tracer.ParentSpan,
span: Tracer.AnySpan,
attributes?: Record<string, unknown>
): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
<A, E, R>(
self: Effect<A, E, R>,
span: Tracer.ParentSpan,
span: Tracer.AnySpan,
attributes?: Record<string, unknown>
): Effect<A, E, R>
} = effect.linkSpans
Expand All @@ -5152,7 +5152,7 @@ export const makeSpan: (
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}
Expand All @@ -5173,7 +5173,7 @@ export const makeSpanScoped: (
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}
Expand All @@ -5196,7 +5196,7 @@ export const useSpan: {
options: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
},
Expand All @@ -5216,7 +5216,7 @@ export const withSpan: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
} | undefined
Expand All @@ -5227,7 +5227,7 @@ export const withSpan: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
} | undefined
Expand All @@ -5248,7 +5248,7 @@ export const withSpanScoped: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}
Expand All @@ -5259,7 +5259,7 @@ export const withSpanScoped: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}
Expand All @@ -5273,8 +5273,8 @@ export const withSpanScoped: {
* @category tracing
*/
export const withParentSpan: {
(span: Tracer.ParentSpan): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Tracer.ParentSpan>>
<A, E, R>(self: Effect<A, E, R>, span: Tracer.ParentSpan): Effect<A, E, Exclude<R, Tracer.ParentSpan>>
(span: Tracer.AnySpan): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, Exclude<R, Tracer.ParentSpan>>
<A, E, R>(self: Effect<A, E, R>, span: Tracer.AnySpan): Effect<A, E, Exclude<R, Tracer.ParentSpan>>
} = effect.withParentSpan

// -------------------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions packages/effect/src/Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ export const setConfigProvider: (configProvider: ConfigProvider) => Layer<never>
* @since 2.0.0
* @category tracing
*/
export const parentSpan: (span: Tracer.ParentSpan) => Layer<Tracer.ParentSpan> = circularLayer.parentSpan
export const parentSpan: (span: Tracer.AnySpan) => Layer<Tracer.ParentSpan> = circularLayer.parentSpan

/**
* @since 2.0.0
Expand Down Expand Up @@ -962,7 +962,7 @@ export const span: (
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
readonly onEnd?:
Expand Down Expand Up @@ -1018,7 +1018,7 @@ export const withSpan: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
readonly onEnd?:
Expand All @@ -1032,7 +1032,7 @@ export const withSpan: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
readonly onEnd?:
Expand All @@ -1047,8 +1047,8 @@ export const withSpan: {
* @category tracing
*/
export const withParentSpan: {
(span: Tracer.ParentSpan): <A, E, R>(self: Layer<A, E, R>) => Layer<A, E, Exclude<R, Tracer.ParentSpan>>
<A, E, R>(self: Layer<A, E, R>, span: Tracer.ParentSpan): Layer<A, E, Exclude<R, Tracer.ParentSpan>>
(span: Tracer.AnySpan): <A, E, R>(self: Layer<A, E, R>) => Layer<A, E, Exclude<R, Tracer.ParentSpan>>
<A, E, R>(self: Layer<A, E, R>, span: Tracer.AnySpan): Layer<A, E, Exclude<R, Tracer.ParentSpan>>
} = internal.withParentSpan

// -----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4025,7 +4025,7 @@ export const withSpan: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
} | undefined
Expand All @@ -4036,7 +4036,7 @@ export const withSpan: {
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
} | undefined
Expand Down
18 changes: 13 additions & 5 deletions packages/effect/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Tracer {
readonly [TracerTypeId]: TracerTypeId
span(
name: string,
parent: Option.Option<ParentSpan>,
parent: Option.Option<AnySpan>,
context: Context.Context<never>,
links: ReadonlyArray<SpanLink>,
startTime: bigint
Expand All @@ -52,13 +52,21 @@ export type SpanStatus = {
* @since 2.0.0
* @category models
*/
export type ParentSpan = Span | ExternalSpan
export type AnySpan = Span | ExternalSpan

/**
* @since 2.0.0
* @category tags
*/
export const ParentSpan: Context.Tag<ParentSpan, ParentSpan> = internal.spanTag
export interface ParentSpan {
readonly _: unique symbol
}

/**
* @since 2.0.0
* @category tags
*/
export const ParentSpan: Context.Tag<ParentSpan, AnySpan> = internal.spanTag

/**
* @since 2.0.0
Expand All @@ -81,7 +89,7 @@ export interface Span {
readonly name: string
readonly spanId: string
readonly traceId: string
readonly parent: Option.Option<ParentSpan>
readonly parent: Option.Option<AnySpan>
readonly context: Context.Context<never>
readonly status: SpanStatus
readonly attributes: ReadonlyMap<string, unknown>
Expand All @@ -98,7 +106,7 @@ export interface Span {
*/
export interface SpanLink {
readonly _tag: "SpanLink"
readonly span: ParentSpan
readonly span: AnySpan
readonly attributes: Readonly<Record<string, unknown>>
}

Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/internal/cause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { pipeArguments } from "../Pipeable.js"
import { hasProperty, isFunction } from "../Predicate.js"
import type { Predicate, Refinement } from "../Predicate.js"
import * as ReadonlyArray from "../ReadonlyArray.js"
import type { ParentSpan, Span } from "../Tracer.js"
import type { AnySpan, Span } from "../Tracer.js"
import * as OpCodes from "./opCodes/cause.js"

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -989,7 +989,7 @@ export const pretty = <E>(cause: Cause.Cause<E>): string => {
message += `\r\n${filterStack(e.stack)}`
}
if (e.span) {
let current: Span | ParentSpan | undefined = e.span
let current: Span | AnySpan | undefined = e.span
let i = 0
while (current && current._tag === "Span" && i < 10) {
message += `\r\n at ${current.name}`
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/internal/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2316,7 +2316,7 @@ export const withSpan = dual<
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}
Expand All @@ -2329,7 +2329,7 @@ export const withSpan = dual<
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}
Expand Down
22 changes: 11 additions & 11 deletions packages/effect/src/internal/core-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1992,15 +1992,15 @@ export const annotateSpans = dual<
)

/** @internal */
export const currentParentSpan: Effect.Effect<Tracer.ParentSpan, Cause.NoSuchElementException> = serviceOptional(
export const currentParentSpan: Effect.Effect<Tracer.AnySpan, Cause.NoSuchElementException> = serviceOptional(
internalTracer.spanTag
)

/** @internal */
export const currentSpan: Effect.Effect<Tracer.Span, Cause.NoSuchElementException> = core.flatMap(
core.context<never>(),
(context) => {
const span = context.unsafeMap.get(internalTracer.spanTag.key) as Tracer.ParentSpan | undefined
const span = context.unsafeMap.get(internalTracer.spanTag.key) as Tracer.AnySpan | undefined
return span !== undefined && span._tag === "Span"
? core.succeed(span)
: core.fail(new core.NoSuchElementException())
Expand All @@ -2017,12 +2017,12 @@ export const currentTimeNanosTracing = core.fiberRefGetWith(
/* @internal */
export const linkSpans = dual<
(
span: Tracer.ParentSpan,
span: Tracer.AnySpan,
attributes?: Record<string, unknown>
) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
<A, E, R>(
self: Effect.Effect<A, E, R>,
span: Tracer.ParentSpan,
span: Tracer.AnySpan,
attributes?: Record<string, unknown>
) => Effect.Effect<A, E, R>
>(
Expand All @@ -2047,7 +2047,7 @@ export const makeSpan = (
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}
Expand Down Expand Up @@ -2115,7 +2115,7 @@ export const useSpan: {
<A, E, R>(name: string, options: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}, evaluate: (span: Tracer.Span) => Effect.Effect<A, E, R>): Effect.Effect<A, E, R>
Expand All @@ -2129,7 +2129,7 @@ export const useSpan: {
const options: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
} | undefined = args.length === 1 ? undefined : args[0]
Expand All @@ -2151,24 +2151,24 @@ export const useSpan: {
/** @internal */
export const withParentSpan = dual<
(
span: Tracer.ParentSpan
span: Tracer.AnySpan
) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>,
<A, E, R>(self: Effect.Effect<A, E, R>, span: Tracer.ParentSpan) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>
<A, E, R>(self: Effect.Effect<A, E, R>, span: Tracer.AnySpan) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>
>(2, (self, span) => provideService(self, internalTracer.spanTag, span))

/** @internal */
export const withSpan = dual<
(name: string, options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>,
<A, E, R>(self: Effect.Effect<A, E, R>, name: string, options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan>>
Expand Down
2 changes: 1 addition & 1 deletion packages/effect/src/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ export const mapInputContext = dual<
/** @internal */
export const currentSpanFromFiber = <A, E>(fiber: Fiber.RuntimeFiber<A, E>): Option.Option<Tracer.Span> => {
const span = fiber.getFiberRef(currentContext).unsafeMap.get(internalTracer.spanTag.key) as
| Tracer.ParentSpan
| Tracer.AnySpan
| undefined
return span !== undefined && span._tag === "Span" ? Option.some(span) : Option.none()
}
Expand Down
6 changes: 3 additions & 3 deletions packages/effect/src/internal/fiberRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3538,7 +3538,7 @@ export const makeSpanScoped = (
options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}
Expand All @@ -3563,14 +3563,14 @@ export const withSpanScoped = dual<
(name: string, options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan> | Scope.Scope>,
<A, E, R>(self: Effect.Effect<A, E, R>, name: string, options?: {
readonly attributes?: Record<string, unknown> | undefined
readonly links?: ReadonlyArray<Tracer.SpanLink> | undefined
readonly parent?: Tracer.ParentSpan | undefined
readonly parent?: Tracer.AnySpan | undefined
readonly root?: boolean | undefined
readonly context?: Context.Context<never> | undefined
}) => Effect.Effect<A, E, Exclude<R, Tracer.ParentSpan> | Scope.Scope>
Expand Down
Loading