Documentation
¶
Index ¶
- Constants
- func AddEvent(ctx context.Context, name string, keyvals ...string)
- func Client(ctx context.Context, t http.RoundTripper, opts ...otelhttp.Option) http.RoundTripper
- func Context(ctx context.Context, svc string, opts ...TraceOption) (context.Context, error)
- func ContinueRemoteTrace(ctx context.Context, name string, traceID [16]byte, keyvals ...string) context.Context
- func EndSpan(ctx context.Context)
- func EndTrace(ctx context.Context)
- func Fail(ctx context.Context, msg string)
- func HTTP(ctx context.Context) func(http.Handler) http.Handler
- func IsTraced(ctx context.Context) bool
- func Log(ctx context.Context) (kvs []log.KV)
- func RecordError(ctx context.Context, err error)
- func SetSpanAttributes(ctx context.Context, keyvals ...string)
- func SpanID(ctx context.Context) string
- func StartSpan(ctx context.Context, name string, keyvals ...string) context.Context
- func StartTrace(ctx context.Context, name string, keyvals ...string) context.Context
- func StreamClientInterceptor(traceCtx context.Context) grpc.StreamClientInterceptor
- func StreamServerInterceptor(traceCtx context.Context) grpc.StreamServerInterceptor
- func Succeed(ctx context.Context)
- func TraceID(ctx context.Context) string
- func TraceProvider(ctx context.Context) trace.TracerProvider
- func UnaryClientInterceptor(traceCtx context.Context) grpc.UnaryClientInterceptor
- func UnaryServerInterceptor(traceCtx context.Context) grpc.UnaryServerInterceptor
- type TraceOption
- func WithDisabled() TraceOption
- func WithExporter(exporter sdktrace.SpanExporter) TraceOption
- func WithGRPCExporter(conn *grpc.ClientConn) TraceOption
- func WithMaxSamplingRate(rate int) TraceOption
- func WithParentSamplerOptions(samplerOptions ...sdktrace.ParentBasedSamplerOption) TraceOption
- func WithPropagator(propagator propagation.TextMapPropagator) TraceOption
- func WithResource(res *resource.Resource) TraceOption
- func WithSampleSize(size int) TraceOption
Constants ¶
const ( // InstrumentationLibraryName is the name of the instrumentation library. InstrumentationLibraryName = "goa.design/clue" // AttributeRequestID is the name of the span attribute that contains the // request ID. AttributeRequestID = "request.id" )
Variables ¶
This section is empty.
Functions ¶
func AddEvent ¶
AddEvent records an event with the given name and attributes in the current span if any.
func Client ¶
func Client(ctx context.Context, t http.RoundTripper, opts ...otelhttp.Option) http.RoundTripper
Client returns a roundtripper that wraps t and creates spans for each request. It panics if the context hasn't been initialized with Context.
func ContinueRemoteTrace ¶ added in v0.7.0
func ContinueRemoteTrace(ctx context.Context, name string, traceID [16]byte, keyvals ...string) context.Context
ContinueRemoteTrace initializes the tracing context with the given remote trace ID and starts a new server span. See StartTrace for usage.
func HTTP ¶
HTTP returns a tracing middleware that uses a parent based sampler (i.e. traces if the parent request traces) and an adaptive root sampler (i.e. when there is no parent uses a target number of requests per second to trace). The implementation leverages the OpenTelemetry SDK and can thus be configured to send traces to an OpenTelemetry remote collector. It is aware of the Goa RequestID middleware and will use it to propagate the request ID to the trace. HTTP panics if the context hasn't been initialized with Context.
Example:
// Connect to remote trace collector. conn, err := grpc.DialContext(ctx, collectorAddr, grpc.WithTransportCrendentials(insecure.Credentials())) if err != nil { log.Error(ctx, err) os.Exit(1) } // Initialize context for tracing ctx := trace.Context(ctx, svcgen.ServiceName, trace.WithGRPCExporter(conn)) // Mount middleware handler := trace.HTTP(ctx)(mux)
func Log ¶ added in v0.1.0
Log is a log key/value pair generator function that can be used to log trace and span IDs. Example:
ctx := log.Context(ctx, WithFunc(trace.Log)) log.Printf(ctx, "message") Output: traceID=<trace-id> spanID=<span-id> message
func RecordError ¶
RecordError records err as an exception span event for the current span if any. An additional call to SetStatus is required if the Status of the Span should be set to Error, as this method does not change the Span status.
func SetSpanAttributes ¶
SetSpanAttributes adds the given attributes to the current span if any. keyvals must be a list of alternating keys and values. It overwrites any existing attributes with the same key.
func StartSpan ¶
StartSpan starts a new span with the given name and attributes and stores it in the returned context if the request is traced, does nothing otherwise. keyvals must be a list of alternating keys and values.
func StartTrace ¶ added in v0.7.0
StartTrace starts a new trace and initializes the context with it. In general traces should be managed by HTTP middlewares and gRPC interceptors created via the HTTP, UnaryServerInterceptor and StreamServerInterceptor methods. This function is intended to be used by code running outside of network requests for example workers that initiate request threads. The context must be initialized with Context. EndTrace must be called by the client in the same goroutine. Not calling EndTrace may cause resource leaks.
func StreamClientInterceptor ¶
func StreamClientInterceptor(traceCtx context.Context) grpc.StreamClientInterceptor
StreamClientInterceptor returns an OpenTelemetry StreamClientInterceptor. It panics if the context has not been initialized with Context.
func StreamServerInterceptor ¶
func StreamServerInterceptor(traceCtx context.Context) grpc.StreamServerInterceptor
StreamServerInterceptor returns an OpenTelemetry StreamServerInterceptor. It panics if the context has not been initialized with Context.
func TraceProvider ¶ added in v0.5.0
func TraceProvider(ctx context.Context) trace.TracerProvider
TraceProvider returns the underlying otel trace provider.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(traceCtx context.Context) grpc.UnaryClientInterceptor
UnaryClientInterceptor returns an OpenTelemetry UnaryClientInterceptor. It panics if the context has not been initialized with Context.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(traceCtx context.Context) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns an OpenTelemetry UnaryServerInterceptor. It panics if the context has not been initialized with Context.
Types ¶
type TraceOption ¶
TraceOption is a function that configures a provider.
func WithDisabled ¶
func WithDisabled() TraceOption
WithDisabled disables tracing, not for use in production.
func WithExporter ¶ added in v0.5.0
func WithExporter(exporter sdktrace.SpanExporter) TraceOption
WithExporter sets the exporter to use.
func WithGRPCExporter ¶ added in v0.5.0
func WithGRPCExporter(conn *grpc.ClientConn) TraceOption
func WithMaxSamplingRate ¶
func WithMaxSamplingRate(rate int) TraceOption
WithMaxSamplingRate sets the maximum sampling rate in requests per second.
func WithParentSamplerOptions ¶ added in v0.7.0
func WithParentSamplerOptions(samplerOptions ...sdktrace.ParentBasedSamplerOption) TraceOption
WithParentSamplerOptions to set the options for sdktrace.ParentBased sampler.
func WithPropagator ¶ added in v0.6.0
func WithPropagator(propagator propagation.TextMapPropagator) TraceOption
WithPropagator sets the otel propagators
func WithResource ¶ added in v0.7.0
func WithResource(res *resource.Resource) TraceOption
WithResource sets the underlying opentelemetry resource.
func WithSampleSize ¶
func WithSampleSize(size int) TraceOption
WithSampleSize sets the number of requests between two adjustments of the sampling rate.