span

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

The package span provides common utils for working with OpenTelemetry spans.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTrace

func ExtractTrace(ctx context.Context) (traceID, spanID string, found bool)

ExtractTrace extracts the trace and span IDs from the current span in the context.

This function retrieves the trace ID and span ID from the active OpenTelemetry span associated with the provided context. If a valid trace or span ID is not present, or if the span is not currently recording, it returns false, indicating that tracing information was not found. When found, it returns the trace ID, span ID, and a boolean indicating success.

Returns:

  • traceID: A string representation of the trace ID.
  • spanID: A string representation of the span ID.
  • found: A boolean indicating whether trace and span IDs were successfully extracted.

Types

type Span

type Span struct {
	oteltrace.Span
}

Span is a wrapper around oteltrace.Span

It is used to provide a more convenient API with extra functionality

func GetSpanFromContext

func GetSpanFromContext(ctx context.Context) Span

GetSpanFromContext retrieves the current OpenTelemetry span from the context.

This allows access to tracing information within that context. If no span is associated with the context, it returns a non-recording span, which is a placeholder that performs no operations. This is useful for tracing operations where span context is required.

Returns the custom Span type.

func (*Span) EndSuccessfully

func (s *Span) EndSuccessfully()

EndSuccessfully ends the span by updating the status to Ok

func (*Span) EndWithError

func (s *Span) EndWithError(err error)

EndWithError ends the span by updating the status to Error and recording the error

Jump to

Keyboard shortcuts

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