trace

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 19 Imported by: 10

README

Trace - Severity-based Distributed Tracing Library

Go Version OpenTelemetry License Go Report Card Jaeger Compatible OTLP Support

中文版文件 (Chinese Documentation) 推薦閱讀中文版,包含更詳細的使用說明和最佳實踐範例

github.com/Bofry/trace is a structured, severity-based distributed tracing library built on OpenTelemetry. It enhances standard OpenTelemetry spans with severity levels (DEBUG through EMERG) and provides fluent APIs for structured logging and cross-service trace propagation with Jaeger integration.

Key Features

  • 8-Level Severity System: Following syslog standard (DEBUG to EMERG)
  • Fluent API: Intuitive method chaining for span operations
  • Cross-Service Tracing: Complete distributed tracing context propagation
  • Deferred Event System: Efficient event batching with flush-on-end
  • No-op Detection: Automatic performance optimization for disabled tracing

Installation

go get github.com/Bofry/trace

Quick Start

package main

import (
    "context"
    "github.com/Bofry/trace"
    "log"
    "time"
)

func main() {
    // Create TracerProvider (OTLP - Recommended)
    tp, err := trace.OTLPProvider("http://localhost:4318",
        trace.ServiceName("my-service"),
        trace.Environment("production"),
        trace.Pid(),
    )
    if err != nil {
        log.Fatal(err)
    }

    // Set as global provider
    trace.SetTracerProvider(tp)

    // Create tracer and span
    tracer := trace.Tracer("main")
    span := tracer.Open(context.Background(), "main-operation")
    defer span.End()

    // Use severity-based logging
    span.Info("Operation started")
    span.Debug("Debug info: %s", "some debug data")

    // Record structured data
    span.Argv(map[string]any{"user_id": 123, "action": "create"})
    span.Reply(trace.PASS, "Operation completed")

    // Graceful shutdown
    defer func(ctx context.Context) {
        ctx, cancel := context.WithTimeout(ctx, time.Second*5)
        defer cancel()
        tp.Shutdown(ctx)
    }(context.Background())
}

Architecture Overview

graph TB
    A[SeverityTracerProvider] --> B[SeverityTracer]
    B --> C[SeveritySpan]
    C --> D[SpanEvent]

    A --> E[OpenTelemetry TracerProvider]
    B --> F[OpenTelemetry Tracer]
    C --> G[OpenTelemetry Span]

    style A fill:#e1f5fe
    style C fill:#f3e5f5

Severity Levels

Level Value Name Usage
DEBUG 0 debug Debug information
INFO 1 info General information
NOTICE 2 notice Important information
WARN 3 warn Warning messages
ERR 4 err Error messages
CRIT 5 crit Critical errors
ALERT 6 alert Immediate attention needed
EMERG 7 emerg System unusable

Span Management Patterns

Provider Initialization
// Modern OTLP approach (recommended)
tp, err := trace.OTLPProvider("http://localhost:4318",
    trace.ServiceName("my-service"),
    trace.Environment("production"),
)

// Legacy Jaeger compatibility (auto-converts to OTLP)
tp, err := trace.JaegerCompatibleProvider("http://localhost:14268/api/traces",
    trace.ServiceName("my-service"),
)
Span Creation Methods
// Root span - creates new trace
rootSpan := tracer.Open(ctx, "root-operation")

// Child span - inherits current context
childSpan := tracer.Start(parentSpan.Context(), "child-operation")

// Linked span - related but not parent-child
linkedSpan := tracer.Link(ctx, parentSpan.Link(), "linked-operation")

// Extracted span - from cross-service context
extractedSpan := tracer.Extract(ctx, carrier, "extracted-operation")

Cross-Service Tracing

sequenceDiagram
    participant A as Service A
    participant B as Service B
    participant J as Jaeger

    A->>A: Create Span
    A->>A: span.Inject(carrier)
    A->>B: HTTP Request + Headers
    B->>B: tracer.Extract(carrier)
    B->>B: Create Child Span
    B->>J: Send Traces
    A->>J: Send Traces
    J->>J: Correlate Traces
Context Propagation Example
// Service A - Inject context
carrier := make(propagation.MapCarrier)
span.Inject(nil, carrier)

// Pass through HTTP headers
for key, value := range carrier {
    req.Header.Set(key, value)
}

// Service B - Extract context
carrier := make(propagation.MapCarrier)
for key, values := range req.Header {
    if len(values) > 0 {
        carrier.Set(key, values[0])
    }
}

extractedSpan := tracer.Extract(ctx, carrier, "downstream-operation")

Testing Setup

Jaeger with Docker
docker run -d --name jaeger \
  -p 16686:16686 \
  -p 14268:14268 \
  -p 4317:4317 \
  -p 4318:4318 \
  jaegertracing/all-in-one:latest
Test Configuration
# Copy test environment file
cp trace_test.env.sample trace_test.env

# Edit with your Jaeger endpoints
# JAEGER_TRACE_URL=http://127.0.0.1:14268/api/traces
# JAEGER_QUERY_URL=http://127.0.0.1:16686/api/traces
Development Workflow
# Standard development sequence
go mod tidy           # Clean up dependencies
go fmt ./...          # Format all code
go vet ./...          # Static analysis
go test ./...         # Run all tests

# Additional testing
go test -cover ./...  # Coverage analysis
go test -race ./...   # Race condition detection

Performance Considerations

  • No-op Detection: Automatically optimizes performance when tracing is disabled
  • Event Batching: Deferred event processing with flush-on-end
  • Atomic Operations: Thread-safe global state management
  • Lazy Evaluation: Attributes constructed only when needed

Test Coverage & Performance Analysis

Test Statistics
  • Test Coverage: 90.7% (89/89 tests passing)
  • Total Test Files: 5 comprehensive test suites
  • Benchmark Tests: 20 performance benchmarks
Performance Benchmarks
Core Operations (ops/sec)
BenchmarkSeveritySpan_Debug         42,077,848     28.44 ns/op     72 B/op    2 allocs/op
BenchmarkSeveritySpan_Info          43,334,922     27.89 ns/op     72 B/op    2 allocs/op
BenchmarkSeveritySpan_Warning       44,706,405     27.77 ns/op     72 B/op    2 allocs/op
BenchmarkSeveritySpan_NoopSpan      41,718,452     27.13 ns/op     72 B/op    2 allocs/op
Additional Operations
BenchmarkExpandObject_String        72,578,631     16.97 ns/op     64 B/op    1 allocs/op
BenchmarkExpandObject_Map            3,132,738     384.5 ns/op    640 B/op   15 allocs/op
BenchmarkSpanFromContext           450,409,731      2.676 ns/op     0 B/op    0 allocs/op
BenchmarkSpanEvent_Creation        100,000,000     10.62 ns/op      8 B/op    0 allocs/op
BenchmarkNoopEvent_Operations      665,452,064      1.811 ns/op     0 B/op    0 allocs/op
Memory Efficiency
  • Recording Span: ~28ns per operation, 72 bytes allocated
  • Context Operations: ~3ns per operation, zero allocations
  • Event Creation: ~11ns per operation, minimal allocations
  • No-op Operations: ~2ns per operation, zero allocations

API Reference

Core Types
  • SeverityTracerProvider: Enhanced tracer provider
  • SeverityTracer: Creates severity-enabled spans
  • SeveritySpan: Span with severity logging methods
  • SpanEvent: Deferred event system
  • Severity: 8-level severity enum
Provider Creation
  • OTLPProvider(endpoint, attrs...): RECOMMENDED - OTLP HTTP provider
  • OTLPGRPCProvider(endpoint, attrs...): OTLP gRPC provider
  • JaegerCompatibleProvider(url, attrs...): Legacy Jaeger compatibility layer (auto-converts endpoints to OTLP)
Span Methods
  • Severity Logging: Debug(), Info(), Notice(), Warning(), Crit(), Alert(), Emerg()
  • Data Recording: Argv(), Reply(), Tags(), Err()
  • Context Operations: Inject(), Link(), Context()

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License.


Note: This library uses modern OTLP protocol as the primary transport. For Jaeger compatibility, use JaegerCompatibleProvider which automatically converts Jaeger endpoints to OTLP (port 14268→4318, 14250→4317).

完整中文文件請參閱 README_ZH.md

Documentation

Overview

Example
package main

import (
	"context"
	"log"
	"time"

	"github.com/Bofry/trace"
)

func main() {
	tp, err := trace.OTLPProvider("http://localhost:4318",
		trace.ServiceName("trace-demo"),
		trace.Environment("go-test"),
		trace.Pid(),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Register our TracerProvider as the global so any imported
	// instrumentation in the future will default to using it.
	trace.SetTracerProvider(tp)

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// Cleanly shutdown and flush telemetry when the application exits.
	defer func(ctx context.Context) {
		// Do not make the application hang when it is shutdown.
		ctx, cancel = context.WithTimeout(ctx, time.Second*5)
		defer cancel()
		if err := tp.Shutdown(ctx); err != nil {
			log.Fatal(err)
		}
	}(ctx)

	tr := tp.Tracer("example-main")

	sp := tr.Open(ctx, "example()")
	defer sp.End()

	sp.Info("example starting")
}

Index

Examples

Constants

View Source
const (
	// SpanKindUnspecified is an unspecified SpanKind and is not a valid
	// SpanKind. SpanKindUnspecified should be replaced with SpanKindInternal
	// if it is received.
	SpanKindUnspecified = trace.SpanKindUnspecified
	// SpanKindInternal is a SpanKind for a Span that represents an internal
	// operation within an application.
	SpanKindInternal = trace.SpanKindInternal
	// SpanKindServer is a SpanKind for a Span that represents the operation
	// of handling a request from a client.
	SpanKindServer = trace.SpanKindServer
	// SpanKindClient is a SpanKind for a Span that represents the operation
	// of client making a request to a server.
	SpanKindClient = trace.SpanKindClient
	// SpanKindProducer is a SpanKind for a Span that represents the operation
	// of a producer sending a message to a message broker. Unlike
	// SpanKindClient and SpanKindServer, there is often no direct
	// relationship between this kind of Span and a SpanKindConsumer kind. A
	// SpanKindProducer Span will end once the message is accepted by the
	// message broker which might not overlap with the processing of that
	// message.
	SpanKindProducer = trace.SpanKindProducer
	// SpanKindConsumer is a SpanKind for a Span that represents the operation
	// of a consumer receiving a message from a message broker. Like
	// SpanKindProducer Spans, there is often no direct relationship between
	// this Span and the Span that produced the message.
	SpanKindConsumer = trace.SpanKindConsumer
)
View Source
const (

	// FlagsSampled is a bitmask with the sampled bit set. A SpanContext
	// with the sampling bit set means the span is sampled.
	FlagsSampled = trace.FlagsSampled
)

Variables

This section is empty.

Functions

func ContextWithSpan

func ContextWithSpan(parent context.Context, span *SeveritySpan) context.Context

func GetTextMapPropagator

func GetTextMapPropagator() propagation.TextMapPropagator

func IsNoopSeveritySpan

func IsNoopSeveritySpan(span *SeveritySpan) bool

func IsOtelNoopSpan

func IsOtelNoopSpan(span trace.Span) bool

func SetSpanExtractor

func SetSpanExtractor(extractor SpanExtractor)

func SetSpanInjector

func SetSpanInjector(injector SpanInjector)

func SetTextMapPropagator

func SetTextMapPropagator(propagator propagation.TextMapPropagator)

func SetTracerProvider

func SetTracerProvider(tp *SeverityTracerProvider)

func SpanToContext

func SpanToContext(ctx context.Context, span *SeveritySpan) context.Context

func WithInstrumentationVersion

func WithInstrumentationVersion(version string) trace.TracerOption
func WithLinks(links ...Link) trace.SpanStartOption

func WithNewRoot

func WithNewRoot() trace.SpanStartOption

func WithSchemaURL

func WithSchemaURL(schemaURL string) trace.TracerOption

func WithSpanKind

func WithSpanKind(kind SpanKind) trace.SpanStartOption

func WithStackTrace

func WithStackTrace(b bool) trace.SpanEndEventOption

Types

type CompositeSpanExtractor

type CompositeSpanExtractor []SpanExtractor

func NewCompositeSpanExtractor

func NewCompositeSpanExtractor(extractors ...SpanExtractor) CompositeSpanExtractor

func (CompositeSpanExtractor) Extract

Extract implements SpanExtractor

type Key

type Key = attribute.Key

type KeyValue

type KeyValue = attribute.KeyValue

func Environment

func Environment(v string) KeyValue

func Pid

func Pid() KeyValue

func ServiceName

func ServiceName(v string) KeyValue
type Link = trace.Link

type NoopSpanInjector

type NoopSpanInjector int

func (NoopSpanInjector) Inject

Inject implements SpanInjector.

type NopEvent

type NopEvent int

func (NopEvent) Error

func (NopEvent) Error(err error)

Error implements SpanEvent

func (NopEvent) Flush

func (NopEvent) Flush()

Flush implements SpanEvent

func (NopEvent) IsRecording

func (NopEvent) IsRecording() bool

IsRecording implements SpanEvent

func (NopEvent) Tags

func (NopEvent) Tags(tags ...KeyValue)

Tags implements SpanEvent

func (NopEvent) Vars

func (NopEvent) Vars(v any)

Vars implements SpanEvent

type ReplyCode

type ReplyCode string
const (
	PASS  ReplyCode = ReplyCode("pass")
	FAIL  ReplyCode = ReplyCode("fail")
	UNSET ReplyCode = ReplyCode("")
)

type Severity

type Severity int8

Severity

const (
	DEBUG  Severity = iota // severity : 0
	INFO                   // severity : 1
	NOTICE                 // severity : 2
	WARN                   // severity : 3
	ERR                    // severity : 4
	CRIT                   // severity : 5
	ALERT                  // severity : 6
	EMERG                  // severity : 7

	NONE Severity = -1
)

func (Severity) Name

func (s Severity) Name() string

type SeverityEvent

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

func (*SeverityEvent) Error

func (s *SeverityEvent) Error(err error)

Error implements SpanEvent

func (*SeverityEvent) Flush

func (s *SeverityEvent) Flush()

Flush implements SpanEvent

func (*SeverityEvent) IsRecording

func (s *SeverityEvent) IsRecording() bool

IsRecording implements SpanEvent

func (*SeverityEvent) Tags

func (s *SeverityEvent) Tags(tags ...KeyValue)

Tags implements SpanEvent

func (*SeverityEvent) Vars

func (s *SeverityEvent) Vars(v any)

Vars implements SpanEvent

type SeveritySpan

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

func CreateSeveritySpan

func CreateSeveritySpan(ctx context.Context) *SeveritySpan

func SpanFromContext

func SpanFromContext(ctx context.Context, extractors ...SpanExtractor) *SeveritySpan

func (*SeveritySpan) Alert

func (s *SeveritySpan) Alert(reason string, v ...any) SpanEvent

func (*SeveritySpan) Argv

func (s *SeveritySpan) Argv(v any)

func (*SeveritySpan) Context

func (s *SeveritySpan) Context() context.Context

func (*SeveritySpan) Crit

func (s *SeveritySpan) Crit(reason string, v ...any) SpanEvent

func (*SeveritySpan) Debug

func (s *SeveritySpan) Debug(message string, v ...any) SpanEvent

func (*SeveritySpan) Disable

func (s *SeveritySpan) Disable(disabled bool)

func (*SeveritySpan) Emerg

func (s *SeveritySpan) Emerg(reason string, v ...any) SpanEvent

func (*SeveritySpan) End

func (s *SeveritySpan) End(opts ...trace.SpanEndOption)

func (*SeveritySpan) Err

func (s *SeveritySpan) Err(err error)

func (*SeveritySpan) HasSpanID

func (s *SeveritySpan) HasSpanID() bool

func (*SeveritySpan) HasTraceID

func (s *SeveritySpan) HasTraceID() bool

func (*SeveritySpan) Info

func (s *SeveritySpan) Info(message string, v ...any) SpanEvent

func (*SeveritySpan) Inject

func (*SeveritySpan) IsDisabled

func (s *SeveritySpan) IsDisabled() bool
func (s *SeveritySpan) Link() Link

func (*SeveritySpan) Notice

func (s *SeveritySpan) Notice(message string, v ...any) SpanEvent

func (*SeveritySpan) Reply

func (s *SeveritySpan) Reply(code ReplyCode, v any)

func (*SeveritySpan) SpanID

func (s *SeveritySpan) SpanID() trace.SpanID

func (*SeveritySpan) Tags

func (s *SeveritySpan) Tags(tags ...KeyValue)

func (*SeveritySpan) TraceFlags

func (s *SeveritySpan) TraceFlags() trace.TraceFlags

func (*SeveritySpan) TraceID

func (s *SeveritySpan) TraceID() trace.TraceID

func (*SeveritySpan) TraceState

func (s *SeveritySpan) TraceState() trace.TraceState

func (*SeveritySpan) Warning

func (s *SeveritySpan) Warning(reason string, v ...any) SpanEvent

type SeverityTracer

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

func CreateSeverityTracer

func CreateSeverityTracer(tr trace.Tracer) *SeverityTracer

func Tracer

func Tracer(name string, opts ...trace.TracerOption) *SeverityTracer

func (*SeverityTracer) Extract

func (s *SeverityTracer) Extract(
	ctx context.Context,
	carrier propagation.TextMapCarrier,
	spanName string,
	opts ...trace.SpanStartOption) *SeveritySpan

func (*SeverityTracer) ExtractWithPropagator

func (s *SeverityTracer) ExtractWithPropagator(
	ctx context.Context,
	propagator propagation.TextMapPropagator,
	carrier propagation.TextMapCarrier,
	spanName string,
	opts ...trace.SpanStartOption) *SeveritySpan
Example
package main

import (
	"context"
	"log"
	"time"

	"github.com/Bofry/trace"
	"go.opentelemetry.io/otel/propagation"
)

func main() {
	tp, err := trace.OTLPProvider("http://localhost:4318",
		trace.ServiceName("trace-demo"),
		trace.Environment("go-test"),
		trace.Pid(),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Register our TracerProvider as the global so any imported
	// instrumentation in the future will default to using it.
	trace.SetTracerProvider(tp)

	trace.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
		propagation.TraceContext{},
		propagation.Baggage{},
	))

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// Cleanly shutdown and flush telemetry when the application exits.
	defer func(ctx context.Context) {
		// Do not make the application hang when it is shutdown.
		ctx, cancel = context.WithTimeout(ctx, time.Second*10)
		defer cancel()
		if err := tp.Shutdown(ctx); err != nil {
			log.Fatal(err)
		}
	}(ctx)

	tr := tp.Tracer("example-main")

	sp := tr.Open(ctx, "example()")
	defer sp.End()

	sp.Info("example starting")

	// subroutine
	var bar = func(carrier propagation.TextMapCarrier, arg string) {
		bartp, err := trace.OTLPProvider("http://localhost:4318",
			trace.ServiceName("trace-demo-outside-boundary"),
			trace.Environment("go-test"),
			trace.Pid(),
		)
		if err != nil {
			log.Fatal(err)
		}

		bartpctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		// Cleanly shutdown and flush telemetry when the application exits.
		defer func(ctx context.Context) {
			// Do not make the application hang when it is shutdown.
			ctx, cancel = context.WithTimeout(ctx, time.Second*5)
			defer cancel()
			if err := bartp.Shutdown(ctx); err != nil {
				log.Fatal(err)
			}
		}(bartpctx)

		propagator := trace.GetTextMapPropagator()

		bartr := bartp.Tracer("example-bar")
		barctx := context.Background() // can use nil instead of context.Background()
		barsp := bartr.ExtractWithPropagator(barctx, propagator, carrier, "bar()")
		defer barsp.End()

		barsp.Argv(arg)
		barsp.Reply(trace.PASS, "OK")
	}

	/* NOTE: the following statements also can be written as
	 *
	 *  way 1:
	 *    carrier := make(propagation.MapCarrier)
	 *    propagator := trace.GetTextMapPropagator()
	 *    propagator.Inject(sp.Context(), carrier)
	 *
	 *  way 2:
	 *    carrier := make(propagation.MapCarrier)
	 *    propagator := trace.GetTextMapPropagator()
	 *    tr.InjectWithPropagator(sp.Context(), propagator, carrier)
	 *
	 *  way 3:
	 *    carrier := make(propagation.MapCarrier)
	 *    tr.Inject(sp.Context(), carrier)
	 */
	carrier := make(propagation.MapCarrier)
	propagator := trace.GetTextMapPropagator()
	sp.Inject(propagator, carrier)

	// call subroutine
	bar(carrier, "foo")
}

func (*SeverityTracer) Inject

func (s *SeverityTracer) Inject(
	ctx context.Context,
	carrier propagation.TextMapCarrier)

func (*SeverityTracer) InjectWithPropagator

func (s *SeverityTracer) InjectWithPropagator(
	ctx context.Context,
	propagator propagation.TextMapPropagator,
	carrier propagation.TextMapCarrier)
func (s *SeverityTracer) Link(
	ctx context.Context,
	link Link,
	spanName string,
	opts ...trace.SpanStartOption) *SeveritySpan

func (*SeverityTracer) Open

func (s *SeverityTracer) Open(
	ctx context.Context,
	spanName string,
	opts ...trace.SpanStartOption) *SeveritySpan

func (*SeverityTracer) Start

func (s *SeverityTracer) Start(
	ctx context.Context,
	spanName string,
	opts ...trace.SpanStartOption) *SeveritySpan
Example
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/Bofry/trace"
)

func main() {
	tp, err := trace.OTLPProvider("http://localhost:4318",
		trace.ServiceName("trace-demo"),
		trace.Environment("go-test"),
		trace.Pid(),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Register our TracerProvider as the global so any imported
	// instrumentation in the future will default to using it.
	trace.SetTracerProvider(tp)

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// Cleanly shutdown and flush telemetry when the application exits.
	defer func(ctx context.Context) {
		// Do not make the application hang when it is shutdown.
		ctx, cancel = context.WithTimeout(ctx, time.Second*5)
		defer cancel()
		if err := tp.Shutdown(ctx); err != nil {
			log.Fatal(err)
		}
	}(ctx)

	tr := tp.Tracer("example-main")

	sp := tr.Open(ctx, "example()")
	defer sp.End()

	sp.Info("example starting")

	// subroutine
	var bar = func(ctx context.Context, arg string) {
		barsp := tr.Start(ctx, "bar()")
		defer barsp.End()

		barsp.Argv(arg)
		barsp.Reply(trace.PASS, "OK")
	}

	ok := trace.IsNoopSeveritySpan(sp)
	sp.Debug("check IsNoopSeveritySpan()").Tags(
		trace.Key("IsNoopSeveritySpan").Bool(ok),
	)

	sp.Debug("log an error").Error(fmt.Errorf("some error"))

	// call subroutine
	bar(sp.Context(), "foo")
}

type SeverityTracerProvider

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

func CreateSeverityTracerProvider

func CreateSeverityTracerProvider(provider trace.TracerProvider) *SeverityTracerProvider

func GetTracerProvider

func GetTracerProvider() *SeverityTracerProvider

func JaegerCompatibleProvider added in v0.3.1

func JaegerCompatibleProvider(endpoint string, attrs ...KeyValue) (*SeverityTracerProvider, error)

JaegerCompatibleProvider creates a provider that sends traces to Jaeger using OTLP This is a convenience function for testing with local Jaeger instances.

For Jaeger v1.35+, it uses the OTLP endpoint (port 4318 for HTTP). For older Jaeger versions, you may need to use the legacy Jaeger collector ports.

Usage:

tp, err := trace.JaegerCompatibleProvider("http://localhost:4318", attrs...)
// Or for Jaeger running on legacy port: "http://localhost:14268" (will auto-convert to OTLP)

func OTLPGRPCProvider added in v0.3.0

func OTLPGRPCProvider(endpoint string, attrs ...KeyValue) (*SeverityTracerProvider, error)

OTLPGRPCProvider creates a provider using OTLP gRPC exporter

func OTLPProvider added in v0.3.0

func OTLPProvider(endpoint string, attrs ...KeyValue) (*SeverityTracerProvider, error)

OTLPProvider creates a provider using OTLP HTTP exporter

func (*SeverityTracerProvider) Shutdown

func (p *SeverityTracerProvider) Shutdown(ctx context.Context) error

func (*SeverityTracerProvider) Tracer

func (*SeverityTracerProvider) TracerProvider

func (p *SeverityTracerProvider) TracerProvider() trace.TracerProvider

type SpanEvent

type SpanEvent interface {
	IsRecording() bool
	Flush()
	Error(err error)
	Tags(tags ...KeyValue)
	Vars(v any)
}

type SpanExtractor

type SpanExtractor interface {
	Extract(ctx context.Context) *SeveritySpan
}

func GetSpanExtractor

func GetSpanExtractor() SpanExtractor

type SpanID

type SpanID = trace.SpanID

type SpanInjector

type SpanInjector interface {
	Inject(ctx context.Context, span *SeveritySpan) context.Context
}

func GetSpanInjector

func GetSpanInjector() SpanInjector

type SpanKind

type SpanKind = trace.SpanKind

type TraceFlags

type TraceFlags = trace.TraceFlags

type TraceID

type TraceID = trace.TraceID

type TracerTagBuilder

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

func (*TracerTagBuilder) Bool

func (builder *TracerTagBuilder) Bool(name string, v bool)

func (*TracerTagBuilder) BoolSlice

func (builder *TracerTagBuilder) BoolSlice(name string, v []bool)

func (*TracerTagBuilder) Float64

func (builder *TracerTagBuilder) Float64(name string, v float64)

func (*TracerTagBuilder) Float64Slice

func (builder *TracerTagBuilder) Float64Slice(name string, v []float64)

func (*TracerTagBuilder) Int

func (builder *TracerTagBuilder) Int(name string, v int)

func (*TracerTagBuilder) Int64

func (builder *TracerTagBuilder) Int64(name string, v int64)

func (*TracerTagBuilder) Int64Slice

func (builder *TracerTagBuilder) Int64Slice(name string, v []int64)

func (*TracerTagBuilder) IntSlice

func (builder *TracerTagBuilder) IntSlice(name string, v []int)

func (*TracerTagBuilder) Result

func (builder *TracerTagBuilder) Result() []KeyValue

func (*TracerTagBuilder) String

func (builder *TracerTagBuilder) String(name string, v string)

func (*TracerTagBuilder) StringSlice

func (builder *TracerTagBuilder) StringSlice(name string, v []string)

func (*TracerTagBuilder) Value

func (builder *TracerTagBuilder) Value(name string, v any)

type TracerTagMarshaler

type TracerTagMarshaler interface {
	MarshalTracerTag(builder *TracerTagBuilder) error
}

type ValueContext

type ValueContext interface {
	context.Context

	SetValue(key, value any)
}

Jump to

Keyboard shortcuts

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