modulepackage
0.0.0-20240430173521-888827872b90
Repository: https://github.com/streamingfast/sf-tracing.git
Documentation: pkg.go.dev
# README
sf-tracing
Setup
export SF_TRACING=<Collector-URL>
Collector-URL
- stdout://
- cloudtrace://[host:port]?project_id=<project_id>&ratio=<0.25>
- zipkin://[host:port]?scheme=<http|https>
package main
import (
"context"
tracing "github.com/streamingfast/sf-tracing"
"go.opentelemetry.io/otel"
)
func main() {
ctx := context.Background()
err := tracing.SetupOpenTelemetry("my-service-name")
if err != nil {
panic(err)
}
myTracer := otel.Tracer("pipeline")
ctx, span := myTracer.Start(ctx, "something_start")
defer span.End()
span.SetAttributes(attribute.Int64("block_num", 1))
span.AddEvent("something_append")
span.SetStatus(otelcode.Ok, "")
}
# Functions
GetTraceID gets the TraceID from the context, you should check if it IsValid().
Returns a tracer.
NewFixedTraceID returns a mocked, fixed trace ID from an hexadecimal string.
NewFixedTraceIDInContext is similar to NewFixedTraceID but will actually insert the span straight into a context that can later be used to ensure the trace id is controlled.
NewRandomSpanID returns a random span ID using OpenCensus default config IDGenerator.
NewRandomTraceID returns a random trace ID using OpenCensus default config IDGenerator.
NewZeroedTraceID returns a mocked, fixed trace ID containing only 0s.
NewZeroedTraceIDInContext is similar to NewZeroedTraceID but will actually insert the span straight into a context that can later be used to ensure the trace id is controlled.
SetupOpenTelemetry sets up tracers based on the `SF_TRACING` environment variable.
WithTraceID adds an otel span with the given traceID.