Skip to content

Tracing in Effect

Although logs and metrics are useful to understand the behavior of individual services, they are not enough to provide a complete overview of the lifetime of a request in a distributed system.

In a distributed system, a request can span multiple services and each service can make multiple requests to other services to fulfill the request. In such a scenario, we need to have a way to track the lifetime of a request across multiple services to diagnose what services are the bottlenecks and where the request is spending most of its time.

A span represents a single unit of work or operation within a request. It provides a detailed view of what happened during the execution of that specific operation.

Each span typically contains the following information:

Span ComponentDescription
NameDescribes the specific operation being tracked.
Timing DataTimestamps indicating when the operation started and its duration.
Log MessagesStructured logs capturing important events during the operation.
AttributesMetadata providing additional context about the operation.

Spans are key building blocks in tracing, helping you visualize and understand the flow of requests through various services.

A trace records the paths taken by requests (made by an application or end-user) as they propagate through multi-service architectures, like microservice and serverless applications.

Without tracing, it is challenging to pinpoint the cause of performance problems in a distributed system.

A trace is made of one or more spans. The first span represents the root span. Each root span represents a request from start to finish. The spans underneath the parent provide a more in-depth context of what occurs during a request (or what steps make up a request).

Many Observability back-ends visualize traces as waterfall diagrams that may look something like this:

Trace Waterfall Diagram

Waterfall diagrams show the parent-child relationship between a root span and its child spans. When a span encapsulates another span, this also represents a nested relationship.

You can add tracing to an effect by creating a span using the Effect.withSpan API. This helps you track specific operations within the effect.

Example (Adding a Span to an Effect)

import {
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
} from "effect"
// Define an effect that delays for 100 milliseconds
const
const program: Effect.Effect<void, never, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const void: Effect.Effect<void, never, never>
export void

@since2.0.0

void
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const delay: (duration: DurationInput) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> (+1 overload)

Returns an effect that is delayed from this effect by the specified Duration.

@since2.0.0

delay
("100 millis"))
// Instrument the effect with a span for tracing
const
const instrumented: Effect.Effect<void, never, never>
instrumented
=
const program: Effect.Effect<void, never, never>
program
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const withSpan: (name: string, options?: SpanOptions | undefined) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, ParentSpan>> (+1 overload)

Wraps the effect with a new span for tracing.

@since2.0.0

withSpan
("myspan"))

Instrumenting an effect with a span does not change its type. If you start with an Effect<A, E, R>, the result remains an Effect<A, E, R>.

To print spans for debugging or analysis, you’ll need to install the required tracing tools. Here’s how to set them up for your project.

Choose your package manager and install the necessary libraries:

Terminal window
npm install @effect/opentelemetry
npm install @opentelemetry/sdk-trace-base
# For NodeJS applications
npm install @opentelemetry/sdk-trace-node
# For browser applications
npm install @opentelemetry/sdk-trace-web
# If you also need to export metrics
npm install @opentelemetry/sdk-metrics

Once the dependencies are installed, you can set up span printing using OpenTelemetry. Here’s an example showing how to print a span for an effect.

Example (Setting Up and Printing a Span)

import {
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
} from "effect"
import {
import NodeSdk
NodeSdk
} from "@effect/opentelemetry"
import {
class ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
,
class BatchSpanProcessor
BatchSpanProcessor
} from "@opentelemetry/sdk-trace-base"
// Define an effect that delays for 100 milliseconds
const
const program: Effect.Effect<void, never, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const void: Effect.Effect<void, never, never>
export void

@since2.0.0

void
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const delay: (duration: DurationInput) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> (+1 overload)

Returns an effect that is delayed from this effect by the specified Duration.

@since2.0.0

delay
("100 millis"))
// Instrument the effect with a span for tracing
const
const instrumented: Effect.Effect<void, never, never>
instrumented
=
const program: Effect.Effect<void, never, never>
program
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const withSpan: (name: string, options?: SpanOptions | undefined) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, ParentSpan>> (+1 overload)

Wraps the effect with a new span for tracing.

@since2.0.0

withSpan
("myspan"))
// Set up tracing with the OpenTelemetry SDK
const
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
=
import NodeSdk
NodeSdk
.
const layer: (evaluate: LazyArg<NodeSdk.Configuration>) => Layer<Resource> (+1 overload)

@since1.0.0

layer
(() => ({
Configuration.resource?: {
readonly serviceName: string;
readonly serviceVersion?: string;
readonly attributes?: ResourceAttributes;
} | undefined
resource
: {
serviceName: string
serviceName
: "example" },
// Export span data to the console
Configuration.spanProcessor?: SpanProcessor | readonly SpanProcessor[] | undefined
spanProcessor
: new
new BatchSpanProcessor<BufferConfig>(_exporter: SpanExporter, config?: BufferConfig | undefined): BatchSpanProcessor
BatchSpanProcessor
(new
new ConsoleSpanExporter(): ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
())
}))
// Run the effect, providing the tracing layer
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runPromise: <void, never>(effect: Effect.Effect<void, never, never>, options?: {
readonly signal?: AbortSignal;
} | undefined) => Promise<void>

Executes an effect and returns a Promise that resolves with the result.

Use runPromise when working with asynchronous effects and you need to integrate with code that uses Promises. If the effect fails, the returned Promise will be rejected with the error.

@example

import { Effect } from "effect"

// Execute an effect and handle the result with a Promise Effect.runPromise(Effect.succeed(1)).then(console.log) // Output: 1

// Execute a failing effect and handle the rejection Effect.runPromise(Effect.fail("my error")).catch((error) => { console.error("Effect failed with error:", error) })

@since2.0.0

runPromise
(
const instrumented: Effect.Effect<void, never, never>
instrumented
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <Resource, never, never>(layer: Layer<Resource, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Resource>> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder R0

@since2.0.0

provide
(
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
)))
/*
Example Output:
{
traceId: 'd0f730abfc366205806469596092b239',
parentId: undefined,
traceState: undefined,
name: 'myspan',
id: 'ab4e42592e7f1f7c',
kind: 0,
timestamp: 1697040012664380.5,
duration: 2895.769,
attributes: {},
status: { code: 1 },
events: [],
links: []
}
*/

The output provides detailed information about the span:

FieldDescription
traceIdA unique identifier for the entire trace, helping trace requests or operations as they move through an application.
parentIdIdentifies the parent span of the current span, marked as undefined in the output when there is no parent span, making it a root span.
nameDescribes the name of the span, indicating the operation being tracked (e.g., “myspan”).
idA unique identifier for the current span, distinguishing it from other spans within a trace.
timestampA timestamp representing when the span started, measured in microseconds since the Unix epoch.
durationSpecifies the duration of the span, representing the time taken to complete the operation (e.g., 2895.769 microseconds).
attributesSpans may contain attributes, which are key-value pairs providing additional context or information about the operation. In this output, it’s an empty object, indicating no specific attributes in this span.
statusThe status field provides information about the span’s status. In this case, it has a code of 1, which typically indicates an OK status (whereas a code of 2 signifies an ERROR status)
eventsSpans can include events, which are records of specific moments during the span’s lifecycle. In this output, it’s an empty array, suggesting no specific events recorded.
linksLinks can be used to associate this span with other spans in different traces. In the output, it’s an empty array, indicating no specific links for this span.

Here’s how a span looks when the effect encounters an error:

Example (Span for an Effect that Fails)

import {
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
} from "effect"
import {
import NodeSdk
NodeSdk
} from "@effect/opentelemetry"
import {
class ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
,
class BatchSpanProcessor
BatchSpanProcessor
} from "@opentelemetry/sdk-trace-base"
const
const program: Effect.Effect<never, string, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const fail: <string>(error: string) => Effect.Effect<never, string, never>

Creates an Effect that represents a recoverable error.

This Effect does not succeed but instead fails with the provided error. The failure can be of any type, and will propagate through the effect pipeline unless handled.

Use this function when you want to explicitly signal an error in an Effect computation. The failed effect can later be handled with functions like

catchAll

or

catchTag

.

@example

import { Effect } from "effect"

// Example of creating a failed effect const failedEffect = Effect.fail("Something went wrong")

// Handle the failure failedEffect.pipe( Effect.catchAll((error) => Effect.succeed(Recovered from: ${error})), Effect.runPromise ).then(console.log) // Output: "Recovered from: Something went wrong"

@since2.0.0

fail
("Oh no!").
Pipeable.pipe<Effect.Effect<never, string, never>, Effect.Effect<never, string, never>, Effect.Effect<never, string, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<never, string, never>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const delay: (duration: DurationInput) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> (+1 overload)

Returns an effect that is delayed from this effect by the specified Duration.

@since2.0.0

delay
("100 millis"),
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const withSpan: (name: string, options?: SpanOptions | undefined) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, ParentSpan>> (+1 overload)

Wraps the effect with a new span for tracing.

@since2.0.0

withSpan
("myspan")
)
const
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
=
import NodeSdk
NodeSdk
.
const layer: (evaluate: LazyArg<NodeSdk.Configuration>) => Layer<Resource> (+1 overload)

@since1.0.0

layer
(() => ({
Configuration.resource?: {
readonly serviceName: string;
readonly serviceVersion?: string;
readonly attributes?: ResourceAttributes;
} | undefined
resource
: {
serviceName: string
serviceName
: "example" },
Configuration.spanProcessor?: SpanProcessor | readonly SpanProcessor[] | undefined
spanProcessor
: new
new BatchSpanProcessor<BufferConfig>(_exporter: SpanExporter, config?: BufferConfig | undefined): BatchSpanProcessor
BatchSpanProcessor
(new
new ConsoleSpanExporter(): ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
())
}))
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runPromiseExit: <never, string>(effect: Effect.Effect<never, string, never>, options?: {
readonly signal?: AbortSignal;
} | undefined) => Promise<Exit<never, string>>

Executes an effect and returns a Promise that resolves with an Exit describing the result.

Use runPromiseExit when you need detailed information about the outcome of the effect, including success or failure, and you want to work with Promises.

@example

import { Effect } from "effect"

// Execute a successful effect and get the Exit result as a Promise Effect.runPromiseExit(Effect.succeed(1)).then(console.log) // Output: // { // _id: "Exit", // _tag: "Success", // value: 1 // }

// Execute a failing effect and get the Exit result as a Promise Effect.runPromiseExit(Effect.fail("my error")).then(console.log) // Output: // { // _id: "Exit", // _tag: "Failure", // cause: { // _id: "Cause", // _tag: "Fail", // failure: "my error" // } // }

@since2.0.0

runPromiseExit
(
const program: Effect.Effect<never, string, never>
program
.
Pipeable.pipe<Effect.Effect<never, string, never>, Effect.Effect<never, string, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<never, string, never>) => Effect.Effect<never, string, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <Resource, never, never>(layer: Layer<Resource, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Resource>> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder R0

@since2.0.0

provide
(
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
))).
Promise<Exit<never, string>>.then<void, never>(onfulfilled?: ((value: Exit<never, string>) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

Attaches callbacks for the resolution and/or rejection of the Promise.

@paramonfulfilled The callback to execute when the Promise is resolved.

@paramonrejected The callback to execute when the Promise is rejected.

@returnsA Promise for the completion of which ever callback is executed.

then
(
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
)
/*
Example Output:
{
traceId: '760510a3f9a0881a09de990c87ec1cef',
parentId: undefined,
traceState: undefined,
name: 'myspan',
id: 'a528e38e82e848a5',
kind: 0,
timestamp: 1697091363002970.5,
duration: 110371.664,
attributes: {},
status: { code: 2, message: 'Error: Oh no!' },
events: [],
links: []
}
{
_id: 'Exit',
_tag: 'Failure',
cause: { _id: 'Cause', _tag: 'Fail', failure: 'Oh no!' }
}
*/

In this example, the span’s status code is 2, indicating an error. The message in the status provides more details about the failure.

You can provide extra information to a span by utilizing the Effect.annotateCurrentSpan function. This function allows you to attach key-value pairs, offering more context about the execution of the span.

Example (Annotating a Span)

import {
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
} from "effect"
import {
import NodeSdk
NodeSdk
} from "@effect/opentelemetry"
import {
class ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
,
class BatchSpanProcessor
BatchSpanProcessor
} from "@opentelemetry/sdk-trace-base"
const
const program: Effect.Effect<void, never, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const void: Effect.Effect<void, never, never>
export void

@since2.0.0

void
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>, cd: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const delay: (duration: DurationInput) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> (+1 overload)

Returns an effect that is delayed from this effect by the specified Duration.

@since2.0.0

delay
("100 millis"),
// Annotate the span with a key-value pair
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const tap: <void, Effect.Effect<void, never, never>>(f: (a: void) => Effect.Effect<void, never, never>) => <E, R>(self: Effect.Effect<void, E, R>) => Effect.Effect<...> (+7 overloads)

@since2.0.0

tap
(() =>
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const annotateCurrentSpan: (key: string, value: unknown) => Effect.Effect<void> (+1 overload)

Adds an annotation to the current span if available

@since2.0.0

annotateCurrentSpan
("key", "value")),
// Wrap the effect in a span named 'myspan'
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const withSpan: (name: string, options?: SpanOptions | undefined) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, ParentSpan>> (+1 overload)

Wraps the effect with a new span for tracing.

@since2.0.0

withSpan
("myspan")
)
// Set up tracing with the OpenTelemetry SDK
const
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
=
import NodeSdk
NodeSdk
.
const layer: (evaluate: LazyArg<NodeSdk.Configuration>) => Layer<Resource> (+1 overload)

@since1.0.0

layer
(() => ({
Configuration.resource?: {
readonly serviceName: string;
readonly serviceVersion?: string;
readonly attributes?: ResourceAttributes;
} | undefined
resource
: {
serviceName: string
serviceName
: "example" },
Configuration.spanProcessor?: SpanProcessor | readonly SpanProcessor[] | undefined
spanProcessor
: new
new BatchSpanProcessor<BufferConfig>(_exporter: SpanExporter, config?: BufferConfig | undefined): BatchSpanProcessor
BatchSpanProcessor
(new
new ConsoleSpanExporter(): ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
())
}))
// Run the effect, providing the tracing layer
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runPromise: <void, never>(effect: Effect.Effect<void, never, never>, options?: {
readonly signal?: AbortSignal;
} | undefined) => Promise<void>

Executes an effect and returns a Promise that resolves with the result.

Use runPromise when working with asynchronous effects and you need to integrate with code that uses Promises. If the effect fails, the returned Promise will be rejected with the error.

@example

import { Effect } from "effect"

// Execute an effect and handle the result with a Promise Effect.runPromise(Effect.succeed(1)).then(console.log) // Output: 1

// Execute a failing effect and handle the rejection Effect.runPromise(Effect.fail("my error")).catch((error) => { console.error("Effect failed with error:", error) })

@since2.0.0

runPromise
(
const program: Effect.Effect<void, never, never>
program
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <Resource, never, never>(layer: Layer<Resource, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Resource>> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder R0

@since2.0.0

provide
(
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
)))
/*
Example Output:
{
traceId: '869c9d74d9db14a4ba4393ca8e0f61db',
parentId: undefined,
traceState: undefined,
name: 'myspan',
id: '31eb49570d197f8d',
kind: 0,
timestamp: 1697045981663321.5,
duration: 109563.353,
attributes: { key: 'value' },
status: { code: 1 },
events: [],
links: []
}
*/

In the context of tracing, logs are converted into “Span Events.” These events offer structured insights into your application’s activities and provide a timeline of when specific operations occurred.

import {
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
} from "effect"
import {
import NodeSdk
NodeSdk
} from "@effect/opentelemetry"
import {
class ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
,
class BatchSpanProcessor
BatchSpanProcessor
} from "@opentelemetry/sdk-trace-base"
// Define a program that logs a message and delays for 100 milliseconds
const
const program: Effect.Effect<void, never, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const log: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>

Logs one or more messages or error causes at the current log level, which is INFO by default. This function allows logging multiple items at once and can include detailed error information using Cause instances.

To adjust the log level, use the Logger.withMinimumLogLevel function.

@example

import { Cause, Effect } from "effect"

const program = Effect.log( "message1", "message2", Cause.die("Oh no!"), Cause.die("Oh uh!") )

// Effect.runFork(program) // Output: // timestamp=... level=INFO fiber=#0 message=message1 message=message2 cause="Error: Oh no! // Error: Oh uh!"

@since2.0.0

log
("Hello").
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const delay: (duration: DurationInput) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> (+1 overload)

Returns an effect that is delayed from this effect by the specified Duration.

@since2.0.0

delay
("100 millis"),
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const withSpan: (name: string, options?: SpanOptions | undefined) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, ParentSpan>> (+1 overload)

Wraps the effect with a new span for tracing.

@since2.0.0

withSpan
("myspan")
)
// Set up tracing with the OpenTelemetry SDK
const
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
=
import NodeSdk
NodeSdk
.
const layer: (evaluate: LazyArg<NodeSdk.Configuration>) => Layer<Resource> (+1 overload)

@since1.0.0

layer
(() => ({
Configuration.resource?: {
readonly serviceName: string;
readonly serviceVersion?: string;
readonly attributes?: ResourceAttributes;
} | undefined
resource
: {
serviceName: string
serviceName
: "example" },
Configuration.spanProcessor?: SpanProcessor | readonly SpanProcessor[] | undefined
spanProcessor
: new
new BatchSpanProcessor<BufferConfig>(_exporter: SpanExporter, config?: BufferConfig | undefined): BatchSpanProcessor
BatchSpanProcessor
(new
new ConsoleSpanExporter(): ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
())
}))
// Run the effect, providing the tracing layer
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runPromise: <void, never>(effect: Effect.Effect<void, never, never>, options?: {
readonly signal?: AbortSignal;
} | undefined) => Promise<void>

Executes an effect and returns a Promise that resolves with the result.

Use runPromise when working with asynchronous effects and you need to integrate with code that uses Promises. If the effect fails, the returned Promise will be rejected with the error.

@example

import { Effect } from "effect"

// Execute an effect and handle the result with a Promise Effect.runPromise(Effect.succeed(1)).then(console.log) // Output: 1

// Execute a failing effect and handle the rejection Effect.runPromise(Effect.fail("my error")).catch((error) => { console.error("Effect failed with error:", error) })

@since2.0.0

runPromise
(
const program: Effect.Effect<void, never, never>
program
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <Resource, never, never>(layer: Layer<Resource, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Resource>> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder R0

@since2.0.0

provide
(
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
)))
/*
Example Output:
{
traceId: 'ad708d58c15f9e5c7b5cca2eeb6838a2',
parentId: undefined,
traceState: undefined,
name: 'myspan',
id: '4353fd47423e786a',
kind: 0,
timestamp: 1697043230170724.2,
duration: 112052.514,
attributes: {},
status: { code: 1 },
events: [
{
name: 'Hello',
attributes: { 'effect.fiberId': '#0', 'effect.logLevel': 'INFO' }, // Log attributes
time: [ 1697043230, 280923805 ], // Event timestamp
droppedAttributesCount: 0
}
],
links: []
}
*/

Each span can include events, which capture specific moments during the execution of a span. In this example, a log message "Hello" is recorded as an event within the span. Key details of the event include:

FieldDescription
nameThe name of the event, which corresponds to the logged message (e.g., 'Hello').
attributesKey-value pairs that provide additional context about the event, such as fiberId and log level.
timeThe timestamp of when the event occurred, shown in a high-precision format.
droppedAttributesCountIndicates how many attributes were discarded, if any. In this case, no attributes were dropped.

Spans can be nested to represent a hierarchy of operations. This allows you to track how different parts of your application relate to one another during execution. The following example demonstrates how to create and manage nested spans.

Example (Nesting Spans in a Trace)

import {
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
} from "effect"
import {
import NodeSdk
NodeSdk
} from "@effect/opentelemetry"
import {
class ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
,
class BatchSpanProcessor
BatchSpanProcessor
} from "@opentelemetry/sdk-trace-base"
const
const child: Effect.Effect<void, never, never>
child
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const void: Effect.Effect<void, never, never>
export void

@since2.0.0

void
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const delay: (duration: DurationInput) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> (+1 overload)

Returns an effect that is delayed from this effect by the specified Duration.

@since2.0.0

delay
("100 millis"),
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const withSpan: (name: string, options?: SpanOptions | undefined) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, ParentSpan>> (+1 overload)

Wraps the effect with a new span for tracing.

@since2.0.0

withSpan
("child")
)
const
const parent: Effect.Effect<void, never, never>
parent
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const gen: <YieldWrap<Effect.Effect<void, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<YieldWrap<Effect.Effect<void, never, never>>, void, never>) => Effect.Effect<...> (+1 overload)

@since2.0.0

gen
(function* () {
yield*
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const sleep: (duration: DurationInput) => Effect.Effect<void>

Returns an effect that suspends for the specified duration. This method is asynchronous, and does not actually block the fiber executing the effect.

@since2.0.0

sleep
("20 millis")
yield*
const child: Effect.Effect<void, never, never>
child
yield*
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const sleep: (duration: DurationInput) => Effect.Effect<void>

Returns an effect that suspends for the specified duration. This method is asynchronous, and does not actually block the fiber executing the effect.

@since2.0.0

sleep
("10 millis")
}).
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const withSpan: (name: string, options?: SpanOptions | undefined) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, ParentSpan>> (+1 overload)

Wraps the effect with a new span for tracing.

@since2.0.0

withSpan
("parent"))
// Set up tracing with the OpenTelemetry SDK
const
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
=
import NodeSdk
NodeSdk
.
const layer: (evaluate: LazyArg<NodeSdk.Configuration>) => Layer<Resource> (+1 overload)

@since1.0.0

layer
(() => ({
Configuration.resource?: {
readonly serviceName: string;
readonly serviceVersion?: string;
readonly attributes?: ResourceAttributes;
} | undefined
resource
: {
serviceName: string
serviceName
: "example" },
Configuration.spanProcessor?: SpanProcessor | readonly SpanProcessor[] | undefined
spanProcessor
: new
new BatchSpanProcessor<BufferConfig>(_exporter: SpanExporter, config?: BufferConfig | undefined): BatchSpanProcessor
BatchSpanProcessor
(new
new ConsoleSpanExporter(): ConsoleSpanExporter

This is implementation of

SpanExporter

that prints spans to the console. This class can be used for diagnostic purposes.

NOTE: This

SpanExporter

is intended for diagnostics use only, output rendered to the console may change at any time.

ConsoleSpanExporter
())
}))
// Run the effect, providing the tracing layer
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runPromise: <void, never>(effect: Effect.Effect<void, never, never>, options?: {
readonly signal?: AbortSignal;
} | undefined) => Promise<void>

Executes an effect and returns a Promise that resolves with the result.

Use runPromise when working with asynchronous effects and you need to integrate with code that uses Promises. If the effect fails, the returned Promise will be rejected with the error.

@example

import { Effect } from "effect"

// Execute an effect and handle the result with a Promise Effect.runPromise(Effect.succeed(1)).then(console.log) // Output: 1

// Execute a failing effect and handle the rejection Effect.runPromise(Effect.fail("my error")).catch((error) => { console.error("Effect failed with error:", error) })

@since2.0.0

runPromise
(
const parent: Effect.Effect<void, never, never>
parent
.
Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
pipe
(
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const provide: <Resource, never, never>(layer: Layer<Resource, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Resource>> (+9 overloads)

Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder R0

@since2.0.0

provide
(
const NodeSdkLive: Layer<Resource, never, never>
NodeSdkLive
)))
/*
Example Output:
{
traceId: '92fe81f1454d9c099198568cf867dc59',
parentId: 'b953d6c7d37ad93d', // This indicates the span is a child of 'parent'
traceState: undefined,
name: 'child',
id: '2fd19c8c23ebc7e8', // Unique ID for the child span
kind: 0,
timestamp: 1697043815321888.2,
duration: 106536.264,
attributes: {},
status: { code: 1 },
events: [],
links: []
}
{
traceId: '92fe81f1454d9c099198568cf867dc59',
parentId: undefined, // Indicates this is the root span
traceState: undefined,
name: 'parent',
id: 'b953d6c7d37ad93d', // Unique ID for the parent span
kind: 0,
timestamp: 1697043815292133.2,
duration: 149724.295,
attributes: {},
status: { code: 1 },
events: [],
links: []
}
*/

The parent-child relationship is evident in the span output, where the parentId of the child span matches the id of the parent span. This structure helps track how operations are related within a single trace.

In this tutorial, we’ll guide you through simulating and visualizing traces using a sample instrumented Node.js application. We will use Docker, Prometheus, Grafana, and Tempo to create, collect, and visualize traces.

Let’s understand the tools we’ll be using in simple terms:

  • Docker: Docker allows us to run applications in containers. Think of a container as a lightweight and isolated environment where your application can run consistently, regardless of the host system. It’s a bit like a virtual machine but more efficient.

  • Prometheus: Prometheus is a monitoring and alerting toolkit. It collects metrics and data about your applications and stores them for further analysis. This helps in identifying performance issues and understanding the behavior of your applications.

  • Grafana: Grafana is a visualization and analytics platform. It helps in creating beautiful and interactive dashboards to visualize your application’s data. You can use it to graphically represent metrics collected by Prometheus.

  • Tempo: Tempo is a distributed tracing system that allows you to trace the journey of a request as it flows through your application. It provides insights into how requests are processed and helps in debugging and optimizing your applications.

To get Docker, follow these steps:

  1. Visit the Docker website at https://www.docker.com/.

  2. Download Docker Desktop for your operating system (Windows or macOS) and install it.

  3. After installation, open Docker Desktop, and it will run in the background.

Now, let’s simulate traces using a sample Node.js application. We’ll provide you with the code and guide you on setting up the necessary components.

  1. Download Docker Files. Download the required Docker files: docker.zip

  2. Set Up docker. Unzip the downloaded file, navigate to the /docker/local directory in your terminal or command prompt and run the following command to start the necessary services:

    Terminal window
    docker-compose up
  3. Simulate Traces. Run the following example code in your Node.js environment. This code simulates a set of tasks and generates traces.

    Before proceeding, you’ll need to install additional libraries in addition to the latest version of effect. Here are the required libraries:

    Terminal window
    npm install @effect/opentelemetry
    npm install @opentelemetry/exporter-trace-otlp-http
    npm install @opentelemetry/sdk-trace-base
    npm install @opentelemetry/sdk-trace-web
    npm install @opentelemetry/sdk-trace-node
    import {
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    } from "effect"
    import {
    import NodeSdk
    NodeSdk
    } from "@effect/opentelemetry"
    import {
    class BatchSpanProcessor
    BatchSpanProcessor
    } from "@opentelemetry/sdk-trace-base"
    import {
    class OTLPTraceExporter

    Collector Trace Exporter for Node

    OTLPTraceExporter
    } from "@opentelemetry/exporter-trace-otlp-http"
    // Function to simulate a task with possible subtasks
    const
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    = (
    name: string
    name
    : string,
    delay: number
    delay
    : number,
    children: readonly Effect.Effect<void, never, never>[]
    children
    :
    interface ReadonlyArray<T>
    ReadonlyArray
    <
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    interface Effect<out A, out E = never, out R = never>

    The Effect interface defines a value that lazily describes a workflow or job. The workflow requires some context R, and may fail with an error of type E, or succeed with a value of type A.

    Effect values model resourceful interaction with the outside world, including synchronous, asynchronous, concurrent, and parallel interaction. They use a fiber-based concurrency model, with built-in support for scheduling, fine-grained interruption, structured concurrency, and high scalability.

    To run an Effect value, you need a Runtime, which is a type that is capable of executing Effect values.

    @since2.0.0

    @since2.0.0

    Effect
    <void>> = []
    ) =>
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const gen: <YieldWrap<Effect.Effect<void, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<YieldWrap<Effect.Effect<void, never, never>>, void, never>) => Effect.Effect<...> (+1 overload)

    @since2.0.0

    gen
    (function* () {
    yield*
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const log: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>

    Logs one or more messages or error causes at the current log level, which is INFO by default. This function allows logging multiple items at once and can include detailed error information using Cause instances.

    To adjust the log level, use the Logger.withMinimumLogLevel function.

    @example

    import { Cause, Effect } from "effect"

    const program = Effect.log( "message1", "message2", Cause.die("Oh no!"), Cause.die("Oh uh!") )

    // Effect.runFork(program) // Output: // timestamp=... level=INFO fiber=#0 message=message1 message=message2 cause="Error: Oh no! // Error: Oh uh!"

    @since2.0.0

    log
    (
    name: string
    name
    )
    yield*
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const sleep: (duration: DurationInput) => Effect.Effect<void>

    Returns an effect that suspends for the specified duration. This method is asynchronous, and does not actually block the fiber executing the effect.

    @since2.0.0

    sleep
    (`${
    delay: number
    delay
    } millis`)
    for (const
    const child: Effect.Effect<void, never, never>
    child
    of
    children: readonly Effect.Effect<void, never, never>[]
    children
    ) {
    yield*
    const child: Effect.Effect<void, never, never>
    child
    }
    yield*
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const sleep: (duration: DurationInput) => Effect.Effect<void>

    Returns an effect that suspends for the specified duration. This method is asynchronous, and does not actually block the fiber executing the effect.

    @since2.0.0

    sleep
    (`${
    delay: number
    delay
    } millis`)
    }).
    Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<void, never, never>): Effect.Effect<...> (+21 overloads)
    pipe
    (
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const withSpan: (name: string, options?: SpanOptions | undefined) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, ParentSpan>> (+1 overload)

    Wraps the effect with a new span for tracing.

    @since2.0.0

    withSpan
    (
    name: string
    name
    ))
    const
    const poll: Effect.Effect<void, never, never>
    poll
    =
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("/poll", 1)
    // Create a program with tasks and subtasks
    const
    const program: Effect.Effect<void, never, never>
    program
    =
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("client", 2, [
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("/api", 3, [
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("/authN", 4, [
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("/authZ", 5)]),
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("/payment Gateway", 6, [
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("DB", 7),
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("Ext. Merchant", 8)
    ]),
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("/dispatch", 9, [
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("/dispatch/search", 10),
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const all: <readonly [Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Effect.Effect<void, never, never>], {
    concurrency: "inherit";
    }>(arg: readonly [Effect.Effect<void, never, never>, Effect.Effect<...>, Effect.Effect<...>], options?: {
    concurrency: "inherit";
    } | undefined) => Effect.Effect<...>

    Runs all the provided effects in sequence respecting the structure provided in input.

    Supports multiple arguments, a single argument tuple / array or record / struct.

    @since2.0.0

    all
    ([
    const poll: Effect.Effect<void, never, never>
    poll
    ,
    const poll: Effect.Effect<void, never, never>
    poll
    ,
    const poll: Effect.Effect<void, never, never>
    poll
    ], {
    concurrency: "inherit"
    concurrency
    : "inherit" }),
    const task: (name: string, delay: number, children?: ReadonlyArray<Effect.Effect<void>>) => Effect.Effect<void, never, never>
    task
    ("/pollDriver/{id}", 11)
    ])
    ])
    ])
    const
    const NodeSdkLive: Layer<Resource, never, never>
    NodeSdkLive
    =
    import NodeSdk
    NodeSdk
    .
    const layer: (evaluate: LazyArg<NodeSdk.Configuration>) => Layer<Resource> (+1 overload)

    @since1.0.0

    layer
    (() => ({
    Configuration.resource?: {
    readonly serviceName: string;
    readonly serviceVersion?: string;
    readonly attributes?: ResourceAttributes;
    } | undefined
    resource
    : {
    serviceName: string
    serviceName
    : "example" },
    Configuration.spanProcessor?: SpanProcessor | readonly SpanProcessor[] | undefined
    spanProcessor
    : new
    new BatchSpanProcessor<BufferConfig>(_exporter: SpanExporter, config?: BufferConfig | undefined): BatchSpanProcessor
    BatchSpanProcessor
    (new
    new OTLPTraceExporter(config?: OTLPExporterNodeConfigBase): OTLPTraceExporter

    Collector Trace Exporter for Node

    OTLPTraceExporter
    ())
    }))
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const runPromise: <void, never>(effect: Effect.Effect<void, never, never>, options?: {
    readonly signal?: AbortSignal;
    } | undefined) => Promise<void>

    Executes an effect and returns a Promise that resolves with the result.

    Use runPromise when working with asynchronous effects and you need to integrate with code that uses Promises. If the effect fails, the returned Promise will be rejected with the error.

    @example

    import { Effect } from "effect"

    // Execute an effect and handle the result with a Promise Effect.runPromise(Effect.succeed(1)).then(console.log) // Output: 1

    // Execute a failing effect and handle the rejection Effect.runPromise(Effect.fail("my error")).catch((error) => { console.error("Effect failed with error:", error) })

    @since2.0.0

    runPromise
    (
    const program: Effect.Effect<void, never, never>
    program
    .
    Pipeable.pipe<Effect.Effect<void, never, never>, Effect.Effect<void, never, never>, Effect.Effect<void, never, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<void, never, never>) => Effect.Effect<...>, bc: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
    pipe
    (
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const provide: <Resource, never, never>(layer: Layer<Resource, never, never>) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Resource>> (+9 overloads)

    Splits the context into two parts, providing one part using the specified layer/context/runtime and leaving the remainder R0

    @since2.0.0

    provide
    (
    const NodeSdkLive: Layer<Resource, never, never>
    NodeSdkLive
    ),
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const catchAllCause: <never, void, never, never>(f: (cause: Cause<never>) => Effect.Effect<void, never, never>) => <A, R>(self: Effect.Effect<A, never, R>) => Effect.Effect<void | A, never, R> (+1 overload)

    Recovers from both recoverable and unrecoverable errors.

    See sandbox, mapErrorCause for other functions that can recover from defects.

    @since2.0.0

    catchAllCause
    (
    import Effect

    @since2.0.0

    @since2.0.0

    @since2.0.0

    Effect
    .
    const logError: (...message: ReadonlyArray<any>) => Effect.Effect<void, never, never>

    Logs the specified message or cause at the Error log level.

    @since2.0.0

    logError
    )
    )
    )
    /*
    Output:
    timestamp=... level=INFO fiber=#0 message=client
    timestamp=... level=INFO fiber=#0 message=/api
    timestamp=... level=INFO fiber=#0 message=/authN
    timestamp=... level=INFO fiber=#0 message=/authZ
    timestamp=... level=INFO fiber=#0 message="/payment Gateway"
    timestamp=... level=INFO fiber=#0 message=DB
    timestamp=... level=INFO fiber=#0 message="Ext. Merchant"
    timestamp=... level=INFO fiber=#0 message=/dispatch
    timestamp=... level=INFO fiber=#0 message=/dispatch/search
    timestamp=... level=INFO fiber=#3 message=/poll
    timestamp=... level=INFO fiber=#4 message=/poll
    timestamp=... level=INFO fiber=#5 message=/poll
    timestamp=... level=INFO fiber=#0 message=/pollDriver/{id}
    */
  4. Visualize Traces. Now, open your web browser and go to http://localhost:3000/explore. You will see a generated Trace ID on the web page. Click on it to see the details of the trace.

    Traces in Grafana Tempo