Documentation
¶
Overview ¶
Package span provides access to OpenTelemetry Span objects for the purpose of logging events.
OTEL spans are not well defined for scope. So the standard for us will generally be function wide spans. This means we will create a child span for each function call. This will allow us to track at minimum the timing of each function call.
Generally you should use this package where you would use the log package to record events or information not related to security. Security information such as AAA should use the audit package (or be automatically configured at the RPC service) and errors are automatically logged by the errors package.
In addition, this package is tied with the errors and log packages. An errors.Error will automatically be recorded for the span with no additional work. The log package will write any usage errors from ths package, as to not stall or require error checking in the main code.
This code is taken and expand from github.com/gostdlib/internal/trace .
This package defaults to using the OTEL stdout exporter. If the environment variable "TracingEndpoint" is set, this will be used to send traces to an OTEL collector. Tracing collectors seem to be setup as insecure by default, so this uses insecure connections.
If TracingEndpoint is not set and if it is not a production environment, the stdout exporter will be used to send to stderr. If this is not needed, --localTraceDisable can be set to true to disable the stdout exporter.
The default production sampler is a filter based sampler that can be updated to capture certain traces based on metadata. It has a secondary sampler that is set to --traceSampleRate, which defaults to 0.01 or 1%.
The default production sampler can be overriden by calling Set(tp *sdkTrace.TracerProvider) before init.Service() is called. The new trace provider can have a different sampler or other settings.
If you simply want to adjust the sampling rate, you can use the flag --traceSampleRate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TracerKey = tracerKeyType(0)
var TracerNameKey = tracerKeyType(1)
Functions ¶
func Close ¶
func Close()
Close shuts down the trace provider. This should be called at the end of the program. Normally this is done by init.Close().
func Default ¶
func Default() *sdkTrace.TracerProvider
Default returns the default trace provider. Normally not required by an end user. TraceProviders are not normally used, instead spans are done via the .../otel/trace/span package and taken from a context. If your program does not take input from a base/rpc package, you may use this to supply an initial span to a context.
Example:
tp := trace.Default() tracer := otel.Tracer("example-tracer") var sp trace.Span ctx, sp := tracer.Start(ctx, opts.name, opts.startOptions...)
func Init ¶
Init initializes the trace package. This should be called once at the beginning of the program. Normally this is done by init.Service(). Can only be called once.
func Set ¶
func Set(tp *sdkTrace.TracerProvider)
Set will set the default trace provider. This can be used to override the TraceProvider before init.Service() is called. The other use is for testing.
Types ¶
This section is empty.
Directories
¶
Path | Synopsis |
---|---|
Package sampler provides a sampler that can be used to sample calls based on a filter.
|
Package sampler provides a sampler that can be used to sample calls based on a filter. |
filters/grpc
Package grpc contains a filter for use in our sampler.Filtered sampler that will match gRPC calls based on metadata.
|
Package grpc contains a filter for use in our sampler.Filtered sampler that will match gRPC calls based on metadata. |
Package span provides methods to create new spans and get existing spans.
|
Package span provides methods to create new spans and get existing spans. |