Help us shape the future of Go! Take the 2026 Go Developer Survey

tracing

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 30 Imported by: 1

Documentation

Overview

Package tracing provides execution trace support for Genkit operations.

Tracing is pluggable: RunInNewSpan dispatches to instrumentation providers, with OpenTelemetry as the default. Traces capture the execution path, inputs, outputs, and timing of operations, enabling observability and debugging through the Genkit Developer UI and external telemetry systems.

Automatic Tracing

Actions and flows defined with Genkit are automatically traced. Each action execution creates a span with input/output data, timing, and any errors. Use [core.Run] within flows to create traced sub-steps:

flow := core.NewFlow("myFlow",
	func(ctx context.Context, input string) (string, error) {
		// This creates a traced step named "processData"
		result, err := core.Run(ctx, "processData", func() (string, error) {
			return process(input), nil
		})
		return result, err
	},
)
// In a real scenario, 'r' would be the registry from your Genkit instance.
flow.Register(r)

OpenTelemetry Integration

Genkit does not configure OpenTelemetry or install a global TracerProvider. To export traces to an external system, set up OpenTelemetry in your application, for example:

otel.SetTracerProvider(sdktrace.NewTracerProvider(
	sdktrace.WithBatcher(exporter),
))

Use the contrib autoexport package if you want the standard OTEL_* environment variables (OTEL_TRACES_EXPORTER, OTEL_EXPORTER_OTLP_ENDPOINT, ...) honored, or use the Google Cloud / Firebase plugins, which configure OpenTelemetry for you.

Genkit reads whatever provider you register (otel.GetTracerProvider) to create its spans; when nothing is configured, the OpenTelemetry spans are no-ops and nothing is exported. Genkit still assigns local trace and span ids, so SpanTraceInfo and log correlation keep working. To keep Genkit spans on a dedicated provider instead of the global one:

tracing.SetInstrumentation(&tracing.OTelInstrumentation{TracerProvider: tp})

Custom Instrumentation

SetInstrumentation replaces the OpenTelemetry default with one or more Instrumentation providers. A provider starts a backend span in Instrumentation.StartSpan and finalizes it in Span.End; Genkit runs the operation itself, so a provider cannot skip or alter it. List OTelInstrumentation alongside your own provider to keep OpenTelemetry:

tracing.SetInstrumentation(&tracing.OTelInstrumentation{}, myProvider)

Annotate the running span from any provider-agnostic code with SetSpanMetadata.

Dev UI Integration

When the GENKIT_ENV environment variable is set to "dev", traces are sent to the Genkit Developer UI's telemetry server directly, without an OpenTelemetry SDK on that path. The Dev UI provides:

  • Visual trace exploration with timing breakdown
  • Input/output inspection for each action
  • Error highlighting and stack traces
  • Performance analysis across flow executions

Set GENKIT_TELEMETRY_SERVER to configure a custom telemetry endpoint; genkit.Init reads it once at startup in the dev environment.

Span Metadata

Create spans with rich metadata for better observability:

metadata := &tracing.SpanMetadata{
	Name:    "processDocument",
	Type:    "action",
	Subtype: "retriever",
}

output, err := tracing.RunInNewSpan(ctx, metadata, input,
	func(ctx context.Context, in Input) (Output, error) {
		// Operation runs within the traced span
		return process(in), nil
	},
)

Trace Information

Extract trace context for correlation with external systems:

info := tracing.SpanTraceInfo(ctx)
log.Printf("TraceID: %s, SpanID: %s", info.TraceID, info.SpanID)

This package is primarily intended for Genkit internals and advanced plugin development. Most application developers will interact with tracing through the automatic instrumentation provided by the genkit package.

For more information on observability, see https://genkit.dev/docs/observability

Package gtime provides time functionality for Go Genkit.

The tracing package provides support for execution traces.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableLogExport added in v1.12.0

func EnableLogExport(url string)

EnableLogExport starts forwarding log records to the telemetry server at url, correlating each record with the active span at the time of logging. It is called during dev-mode initialization, either with the value of GENKIT_TELEMETRY_SERVER or with the URL the Genkit CLI supplies when it notifies the reflection server. Calling it again replaces the destination; an empty url is ignored. Setting GENKIT_OTEL_ENABLE_LOGS=false disables export entirely.

Records reach the telemetry server only if a handler created by LogExportHandler is registered, which genkit.Init does in dev mode.

func LogExportHandler added in v1.12.0

func LogExportHandler() slog.Handler

LogExportHandler returns a slog.Handler that forwards every record at slog.LevelDebug or above to the telemetry server configured with EnableLogExport. Until then the handler reports itself disabled and adds no overhead. The handler never blocks: records beyond the export queue's capacity are dropped.

func NewHTTPTelemetryClient added in v0.1.3

func NewHTTPTelemetryClient(url string) *httpTelemetryClient

NewHTTPTelemetryClient creates a new telemetry client that sends traces to a telemetry server at the given URL.

func RunInNewSpan

func RunInNewSpan[I, O any](
	ctx context.Context,
	metadata *SpanMetadata,
	input I,
	f func(context.Context, I) (O, error),
) (O, error)

RunInNewSpan runs f on input in a new span with the provided metadata. The metadata contains all span configuration including name, type, labels, etc. If a telemetry callback was set on the context via WithTelemetryCallback, it will be called with the trace ID and span ID as soon as the span is created.

func SetInstrumentation added in v1.14.0

func SetInstrumentation(providers ...Instrumentation)

SetInstrumentation sets the providers every Genkit span is reported to, in order, replacing the implicit default (OTelInstrumentation over the global OpenTelemetry TracerProvider). Calling it with no providers restores the default. Nil providers are ignored.

To add a provider while keeping OpenTelemetry, list both:

tracing.SetInstrumentation(&tracing.OTelInstrumentation{}, myProvider)

Configuration is process-wide, like otel.SetTracerProvider: Genkit actions can run without a Genkit instance and are instrumented too. In the dev environment the Developer UI's provider is always kept at the front of the chain, whatever is set here.

Example
package main

import (
	"context"
	"errors"
	"fmt"

	"github.com/firebase/genkit/go/core/tracing"
)

// PrintingInstrumentation prints each span as it starts and ends.
type PrintingInstrumentation struct{}

func (PrintingInstrumentation) StartSpan(ctx context.Context, info *tracing.SpanInfo) (context.Context, tracing.Span) {
	fmt.Printf("-> %s (%s) at %s\n", info.Name(), info.Type(), info.Path())
	return ctx, printingSpan{name: info.Name()}
}

// printingSpan mints no ids, so it reports empty ones; Genkit then mints local
// ids for correlation.
type printingSpan struct{ name string }

func (printingSpan) TraceInfo() tracing.TraceInfo  { return tracing.TraceInfo{} }
func (printingSpan) SetMetadata(map[string]string) {}

func (s printingSpan) End(res *tracing.SpanResult) {
	if err := res.Err(); err != nil {
		fmt.Printf("!! %s: %v\n", s.name, err)
		return
	}
	fmt.Printf("<- %s: %v\n", s.name, res.Output())
}

func main() {
	// Replace the OpenTelemetry default. To keep it, list it too:
	// tracing.SetInstrumentation(&tracing.OTelInstrumentation{}, PrintingInstrumentation{})
	tracing.SetInstrumentation(PrintingInstrumentation{})
	defer tracing.SetInstrumentation() // restore the default

	ctx := context.Background()
	_, _ = tracing.RunInNewSpan(ctx, &tracing.SpanMetadata{Name: "greet", Type: "flow"}, "world",
		func(ctx context.Context, name string) (string, error) {
			_, _ = tracing.RunInNewSpan(ctx, &tracing.SpanMetadata{Name: "lookup", Type: "flowStep"}, name,
				func(context.Context, string) (string, error) { return "", errors.New("not found") })
			return "hello " + name, nil
		})
}
Output:
-> greet (flow) at /{greet,t:flow}
-> lookup (flowStep) at /{greet,t:flow}/{lookup,t:flowStep}
!! lookup: not found
<- greet: hello world

func SetSpanMetadata added in v1.14.0

func SetSpanMetadata(ctx context.Context, md map[string]string)

SetSpanMetadata records custom metadata on the current span, fanning out to every active instrumentation provider. Each entry is stored as a genkit:metadata:<key> span attribute. It is a no-op when called outside a span. This is the backend-independent way to annotate the running span; it replaces writing to an OpenTelemetry span directly.

func SpanPath

func SpanPath(ctx context.Context) string

SpanPath returns the path as recorded in the current span metadata.

func TelemetryLabelsFromContext added in v1.11.0

func TelemetryLabelsFromContext(ctx context.Context) map[string]string

TelemetryLabelsFromContext retrieves the telemetry labels from context, or nil if not set.

func Tracer deprecated added in v0.7.0

func Tracer() trace.Tracer

Tracer returns a tracer from the global tracer provider.

Deprecated: Genkit no longer manages the global TracerProvider. Get a tracer from your own OpenTelemetry setup (otel.GetTracerProvider().Tracer(...)). Removed in the next major version.

func TracerProvider deprecated added in v0.7.0

func TracerProvider() *sdktrace.TracerProvider

TracerProvider returns the global tracer provider, creating it if needed.

Deprecated: Genkit no longer owns the global OpenTelemetry TracerProvider. Configure OpenTelemetry yourself (otel.SetTracerProvider with your own exporters, or the contrib autoexport package to honor OTEL_* env vars), or use the Google Cloud / Firebase plugins. Retained for backwards compatibility and removed in the next major version.

func WithInstrumentation added in v1.14.0

func WithInstrumentation(ctx context.Context, providers ...Instrumentation) context.Context

WithInstrumentation returns ctx carrying providers in addition to any it already carries. Every span started under the returned context is reported to them, after the process-wide providers (see SetInstrumentation): they start after those and end before them, the most recently added first. A scoped provider cannot be removed, so an enclosing one sees every span started under it, nested runs and subagents included. Nil providers are ignored.

SetInstrumentation configures telemetry for the process. WithInstrumentation is for code that reacts to what runs under one context, such as middleware that counts the model calls of its run, and adds its provider itself, so it needs no setup by the application.

func WithTelemetryCallback added in v1.3.0

func WithTelemetryCallback(ctx context.Context, cb func(traceID, spanID string)) context.Context

WithTelemetryCallback returns a context with the telemetry callback attached. Used by the reflection server to pass callbacks to actions.

func WithTelemetryLabels added in v1.11.0

func WithTelemetryLabels(ctx context.Context, labels map[string]string) context.Context

WithTelemetryLabels returns a context with the telemetry labels attached. Used by the reflection server to pass labels to actions.

func WriteTelemetryBatch deprecated added in v0.7.0

func WriteTelemetryBatch(client TelemetryClient) (shutdown func(context.Context) error)

WriteTelemetryBatch adds a telemetry server to the global tracer provider. Traces are batched before being sent for processing. Use this for a gtrace.Store with a potentially expensive Save method, such as one that makes an RPC.

Callers must invoke the returned function at the end of the program to flush the final batch and perform other cleanup.

Deprecated: registers a span processor on the Genkit-managed global TracerProvider. Use NewDirectTelemetryInstrumentation as shown on WriteTelemetryImmediate; it saves each span as it ends, without batching, so wrap client in your own batching if Save is expensive. Removed in the next major version.

func WriteTelemetryImmediate deprecated added in v0.7.0

func WriteTelemetryImmediate(client TelemetryClient)

WriteTelemetryImmediate adds a telemetry server to the global tracer provider. Traces are saved immediately as they are finished. Use this for a gtrace.Store with a fast Save method, such as one that writes to a file.

Deprecated: registers a span processor on the Genkit-managed global TracerProvider. To keep sending Genkit spans to client, export them directly, listing OTelInstrumentation too if you also export through OpenTelemetry:

tracing.SetInstrumentation(&tracing.OTelInstrumentation{},
	tracing.NewDirectTelemetryInstrumentation(client))

Removed in the next major version.

func WriteTelemetryRealtime deprecated added in v1.10.0

func WriteTelemetryRealtime(client TelemetryClient)

WriteTelemetryRealtime adds a telemetry server to the global tracer provider that writes each span both when it starts and when it ends, so a still-running trace appears in the dev UI immediately rather than only once its root span closes. This matters for agents, whose root span stays open for the lifetime of a bidirectional connection. Use this for a fast Save method (such as one that writes to a file or a local server); for an end-only export use WriteTelemetryImmediate.

Deprecated: registers a span processor on the Genkit-managed global TracerProvider. Use NewDirectTelemetryInstrumentation as shown on WriteTelemetryImmediate; it also saves each span when it starts while GENKIT_ENABLE_REALTIME_TELEMETRY=true (set by `genkit start`). Removed in the next major version.

Types

type Annotation

type Annotation struct {
	Attributes  map[string]any `json:"attributes,omitempty"`
	Description string         `json:"description,omitempty"`
}

type BoolValue

type BoolValue struct {
	Value bool `json:"value"`
}

type Data

type Data struct {
	TraceID     string               `json:"traceId"`
	DisplayName string               `json:"displayName,omitempty"`
	StartTime   Milliseconds         `json:"startTime,omitempty"`
	EndTime     Milliseconds         `json:"endTime,omitempty"`
	Spans       map[string]*SpanData `json:"spans"`
}

Data is information about a trace.

DisplayName, StartTime, and EndTime are derived from the trace's root (parentless) span, so a batch that carries only child spans leaves them at their zero values. They are omitempty for that reason: the telemetry server only overwrites a stored trace's metadata when the incoming value is defined (see the merge in genkit-tools' file trace store), so emitting a zero here would clobber the real title/times a prior root-span save established. This matters once spans are exported as they start (live traces), where child spans can reach the server before the root span closes.

type DirectTelemetryInstrumentation added in v1.14.0

type DirectTelemetryInstrumentation struct {
	// contains filtered or unexported fields
}

DirectTelemetryInstrumentation feeds the Developer UI directly, with no OpenTelemetry SDK. It mints its own ids, tracks parentage via context, and POSTs each span to ${server}/api/traces through a TelemetryClient, in the same SpanData/Data shape the telemetry server ingests from the OTel exporter. When realtime export is active (GENKIT_ENABLE_REALTIME_TELEMETRY) it also saves each span as it starts, so still-running traces appear in the Dev UI.

In dev it is prepended to the chain when a telemetry server is configured. One built with a nil client mints ids but exports nothing.

func NewDirectTelemetryInstrumentation added in v1.14.0

func NewDirectTelemetryInstrumentation(client TelemetryClient) *DirectTelemetryInstrumentation

NewDirectTelemetryInstrumentation returns a provider that saves Genkit spans to client directly, with no OpenTelemetry SDK involved. Install it with SetInstrumentation to send traces to a custom TelemetryClient (it replaces the deprecated WriteTelemetry* functions) or to capture them in memory in tests. Each span is saved when it ends, and also when it starts while GENKIT_ENABLE_REALTIME_TELEMETRY=true. The Developer UI wiring builds its own instance internally.

func (*DirectTelemetryInstrumentation) StartSpan added in v1.14.0

StartSpan mints ids (continuing the parent's trace) and, when realtime export is active, exports the span as in progress so a long-lived root span shows up in the Dev UI before it closes.

type Instrumentation added in v1.14.0

type Instrumentation interface {
	// StartSpan opens a backend span and returns the context children should
	// observe (e.g. carrying the backend's parent span) along with its handle.
	StartSpan(ctx context.Context, info *SpanInfo) (context.Context, Span)
}

Instrumentation is a pluggable span-creation provider. For every Genkit span the dispatcher calls StartSpan on each configured provider in order, runs the span's function once under the returned context, then ends each Span. A provider cannot skip, repeat, or alter the run.

type InstrumentationScope added in v0.5.3

type InstrumentationScope struct {
	Name      string `json:"name"`
	Version   string `json:"version"`
	SchemaURL string `json:"schemaUrl,omitempty"`
}

InstrumentationScope is a copy of go.opentelemetry.io/otel/sdk/instrumentation.Library, with added struct tags to match the javascript JSON field names.

type Link struct {
	SpanContext            SpanContext    `json:"context"`
	Attributes             map[string]any `json:"attributes,omitempty"`
	DroppedAttributesCount int            `json:"droppedAttributesCount"`
}

A Link describes the relationship between two Spans.

type Milliseconds

type Milliseconds float64

Milliseconds represents a time as the number of milliseconds since the Unix epoch.

func ToMilliseconds

func ToMilliseconds(t time.Time) Milliseconds

ToMilliseconds converts a time.Time to a Milliseconds.

func (Milliseconds) Time

func (m Milliseconds) Time() time.Time

Time converts a Milliseconds to a time.Time.

type OTelInstrumentation added in v1.14.0

type OTelInstrumentation struct {
	// TracerProvider creates the spans. Nil means the global provider,
	// resolved per span so a provider registered after this value was built
	// is still picked up. Set it to keep Genkit spans on a dedicated provider
	// (a different sampler or exporter) without touching the global.
	TracerProvider trace.TracerProvider
	// contains filtered or unexported fields
}

OTelInstrumentation encodes each Genkit span as an OpenTelemetry span with the genkit:* attributes. It is the implicit default (see SetInstrumentation). It installs no TracerProvider itself: with TracerProvider unset it reads the global one (otel.SetTracerProvider, set by a user's OTel setup or the Google Cloud / Firebase plugins). When nothing is configured, OTel's no-op provider yields all-zero, invalid ids, which TraceInfo reports as empty. It also puts the OTel span in the context, so direct trace.SpanFromContext writes land on it.

Back-compat default; removed as the default in the next major to reach the shared "not instrumented by default" goal.

func (*OTelInstrumentation) StartSpan added in v1.14.0

func (o *OTelInstrumentation) StartSpan(ctx context.Context, info *SpanInfo) (context.Context, Span)

StartSpan opens an OTel span seeded with the start-known genkit attributes.

type Span added in v1.14.0

type Span interface {
	// TraceInfo returns the provider's ids, or empty strings if it tracks none.
	TraceInfo() TraceInfo
	// SetMetadata records mid-run custom metadata on the span. It may be
	// called from goroutines other than the one running the span.
	SetMetadata(md map[string]string)
	// End finalizes the span with the run's result. Called exactly once, on
	// the goroutine that started the span, in reverse start order across
	// providers; also called when the run panics.
	End(res *SpanResult)
}

Span is the backend-independent handle a provider returns for the span it started. The dispatcher reads TraceInfo to resolve the span's ids, fans SetMetadata out for mid-run custom metadata, and calls End exactly once.

type SpanContext

type SpanContext struct {
	TraceID    string `json:"traceId,omitempty"`
	SpanID     string `json:"spanId"`
	IsRemote   bool   `json:"isRemote"`
	TraceFlags int    `json:"traceFlags"`
}

A SpanContext contains identifying trace information about a Span.

type SpanData

type SpanData struct {
	SpanID               string               `json:"spanId"`
	TraceID              string               `json:"traceId,omitempty"`
	ParentSpanID         string               `json:"parentSpanId,omitempty"`
	StartTime            Milliseconds         `json:"startTime"`
	EndTime              Milliseconds         `json:"endTime"`
	Attributes           map[string]any       `json:"attributes"`
	DisplayName          string               `json:"displayName"`
	Links                []*Link              `json:"links,omitempty"`
	InstrumentationScope InstrumentationScope `json:"instrumentationLibrary"` // TODO: update json tag when JS runtime gets updated
	SpanKind             string               `json:"spanKind"`               // trace.SpanKind as a string
	// This bool is in a separate struct, to match the js (and presumably the OTel) formats.
	SameProcessAsParentSpan BoolValue  `json:"sameProcessAsParentSpan"`
	Status                  Status     `json:"status"`
	TimeEvents              TimeEvents `json:"timeEvents"`
}

SpanData is information about a trace span. Most of this information comes from OpenTelemetry. See https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace#ReadOnlySpan. SpanData can be passed to json.Marshal, whereas most of the OpenTelemetry types make no claims about JSON serializability.

type SpanInfo added in v1.14.0

type SpanInfo struct {
	// contains filtered or unexported fields
}

SpanInfo is the backend-independent view of a span the dispatcher hands to each Instrumentation provider. Everything it exposes is known when the span starts and is read-only: maps are returned as copies. The run's outcome arrives separately, as the SpanResult passed to Span.End.

func (*SpanInfo) Init added in v1.14.0

func (i *SpanInfo) Init() any

Init is the initialization data the action was invoked with (recorded as genkit:init), or nil. Kept apart from Input so per-call input and session initialization stay distinguishable.

func (*SpanInfo) Input added in v1.14.0

func (i *SpanInfo) Input() any

Input is the raw input the action was invoked with.

func (*SpanInfo) IsRoot added in v1.14.0

func (i *SpanInfo) IsRoot() bool

IsRoot reports whether this span is the root of a Genkit trace.

func (*SpanInfo) Labels added in v1.14.0

func (i *SpanInfo) Labels() map[string]string

Labels returns a copy of the span's telemetry labels (set directly as span attributes, with no prefix), or nil if there are none.

func (*SpanInfo) Metadata added in v1.14.0

func (i *SpanInfo) Metadata() map[string]string

Metadata returns a copy of the span's custom metadata (recorded as genkit:metadata:<key> attributes), or nil if there is none. Metadata added mid-run arrives through Span.SetMetadata instead.

func (*SpanInfo) Name added in v1.14.0

func (i *SpanInfo) Name() string

Name is the span name. For a model span it is the fully qualified model name (e.g. "googleai/gemini-flash-latest").

func (*SpanInfo) Path added in v1.14.0

func (i *SpanInfo) Path() string

Path is the type-annotated span path, e.g. "/{chatFlow,t:flow}/{googleai/gemini-flash-latest,t:action,s:model}".

func (*SpanInfo) Subtype added in v1.14.0

func (i *SpanInfo) Subtype() string

Subtype is the finer categorization ("model", "tool", "flow", ...), or "".

func (*SpanInfo) Type added in v1.14.0

func (i *SpanInfo) Type() string

Type is the Genkit span type ("action", "flowStep", "util", ...).

type SpanMetadata added in v1.0.0

type SpanMetadata struct {
	// Name is the span name
	Name string
	// IsRoot indicates if this is a root span
	IsRoot bool
	// Type represents the kind of span (e.g., "action", "flowStep")
	Type string
	// Subtype provides more specific categorization (e.g., "tool", "flow", "model")
	Subtype string
	// TelemetryLabels are arbitrary key-value pairs set directly as span attributes
	TelemetryLabels map[string]string
	// Metadata are genkit-specific metadata with automatic "genkit:metadata:" prefix
	Metadata map[string]string
	// Init is the initialization data supplied to the action, recorded as the
	// "genkit:init" span attribute when non-nil. It is kept separate from the
	// span input so tooling can distinguish per-call input from session
	// initialization data.
	Init any
}

SpanMetadata contains metadata information for creating properly annotated spans

type SpanResult added in v1.14.0

type SpanResult struct {
	// contains filtered or unexported fields
}

SpanResult is how a span's run ended. The dispatcher builds one per span and passes the same value to every provider's Span.End; it is read-only.

func (*SpanResult) Err added in v1.14.0

func (r *SpanResult) Err() error

Err is the run's error, or nil on success. A panic in the run is reported here as an error (the panic itself keeps propagating after spans end).

func (*SpanResult) IsFailureSource added in v1.14.0

func (r *SpanResult) IsFailureSource() bool

IsFailureSource reports whether this span is where a failure originated, as opposed to an enclosing span that only propagated a child's error or panic. Always false on success. Backends that count failures should count only these spans, so one failure is not counted once per enclosing span.

func (*SpanResult) Output added in v1.14.0

func (r *SpanResult) Output() any

Output is the run's output. It can be non-nil alongside a non-nil Err: a failed run may still return a partial result (e.g. the generate loop returns the conversation it completed with its error).

type Status

type Status struct {
	// Code is the OTLP status code: 0 = Unset, 1 = Ok, 2 = Error.
	// It is not a [go.opentelemetry.io/otel/codes.Code], whose Ok and Error
	// values are reversed.
	Code        uint32 `json:"code"`
	Description string `json:"message,omitempty"`
}

Status is the JSON form of go.opentelemetry.io/otel/sdk/trace.Status, with struct tags that match the javascript JSON field names.

type TelemetryClient added in v0.1.3

type TelemetryClient interface {
	Save(ctx context.Context, trace *Data) error
}

type TestOnlyTelemetryClient added in v0.1.3

type TestOnlyTelemetryClient struct {
	Traces map[string]*Data
	// contains filtered or unexported fields
}

TestOnlyTelemetryClient is a test-only implementation of TelemetryClient that stores traces in memory. It is safe for concurrent use: the Direct instrumentation exports start-of-span saves from a goroutine, and actions (e.g. bidi) run spans concurrently.

func NewTestOnlyTelemetryClient added in v0.1.3

func NewTestOnlyTelemetryClient() *TestOnlyTelemetryClient

NewTestOnlyTelemetryClient creates a new in-memory telemetry client for testing.

func (*TestOnlyTelemetryClient) Save added in v0.1.3

func (c *TestOnlyTelemetryClient) Save(ctx context.Context, trace *Data) error

Save saves the data to an in-memory store.

func (*TestOnlyTelemetryClient) Spans added in v1.14.0

func (c *TestOnlyTelemetryClient) Spans() []*SpanData

Spans returns a snapshot slice of every span stored so far, safe to read while spans are still being exported from other goroutines.

type TimeEvent

type TimeEvent struct {
	Time       Milliseconds `json:"time,omitempty"`
	Annotation Annotation   `json:"annotation"`
}

type TimeEvents

type TimeEvents struct {
	TimeEvent []TimeEvent `json:"timeEvent,omitempty"`
}

type TraceInfo added in v1.0.3

type TraceInfo struct {
	TraceID string
	SpanID  string
}

func SpanTraceInfo added in v1.0.3

func SpanTraceInfo(ctx context.Context) TraceInfo

SpanTraceInfo returns the trace info recorded in the current span metadata, or the zero TraceInfo when called outside any span (e.g. a log emitted before a flow starts).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL