Documentation ¶
Index ¶
- Variables
- type ExporterGRPC
- type ExporterHTTP
- type Opt
- func WithContext(ctx context.Context) Opt
- func WithEnvironment(environment string) Opt
- func WithGRPCExporter(endpoint string, credentials credentials.TransportCredentials) Opt
- func WithHTTPExporter(endpoint string, token string, insecure bool) Opt
- func WithIgnore(ignoreSpans []string) Opt
- func WithProcessor(processorName string) Opt
- func WithSamplePercentage(percentage int) Opt
- func WithServiceName(serviceName string) Opt
- type SpanFilter
- type TracerProvider
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ExporterGRPC ¶ added in v2.1.5
type ExporterGRPC struct {
// contains filtered or unexported fields
}
type ExporterHTTP ¶ added in v2.1.5
type ExporterHTTP struct {
// contains filtered or unexported fields
}
type Opt ¶
type Opt func(*TracerProvider) error
func WithContext ¶
WithContext sets the context for the tracer provider.
func WithEnvironment ¶ added in v2.1.5
WithEnvironment sets the deployment environment name attribute for the tracer provider.
func WithGRPCExporter ¶ added in v2.1.5
func WithGRPCExporter(endpoint string, credentials credentials.TransportCredentials) Opt
WithGRPCExporter sets gRPC collector endpoint for trace exporter. Endpoint is "host:port" of the collector and you can set transport credentials to "insecure.NewCredentials()" if secure connection is not required.
func WithHTTPExporter ¶ added in v2.1.5
WithHTTPExporter sets HTTP exporter endpoint for trace exporter with an authorization token. Endpoint is "host:port" of to the collector and you can set token as "ApiKey <token>" or "Bearer <token>". Set token to empty if not needed. Insecure disables TLS.
func WithIgnore ¶ added in v2.1.10
WithIgnore sets the ignore filter of span names for the tracer provider, e.g. ["/healthz"].
func WithProcessor ¶
WithProcessor sets the span processor for the tracer provider. Allowed values are "batch" and "simple", but "simple" should not be used in production.
func WithSamplePercentage ¶
WithSamplePercentage sets the percentage of spans to sample. Allowed values are 0-100.
func WithServiceName ¶
WithServiceName sets the service name attribute for the tracer provider.
type SpanFilter ¶ added in v2.1.10
type SpanFilter struct { trace.SpanProcessor // Ignore is the map of dropped span names. Ignore map[string]struct{} }
func (SpanFilter) OnEnd ¶ added in v2.1.10
func (f SpanFilter) OnEnd(s trace.ReadOnlySpan)
type TracerProvider ¶
type TracerProvider struct {
// contains filtered or unexported fields
}
func New ¶
func New(opts ...Opt) *TracerProvider
New creates tracer provider module with given options.
Example ¶
package main import ( "context" "fmt" "github.com/elisasre/go-common/v2/service" "github.com/elisasre/go-common/v2/service/module/tracerprovider" "google.golang.org/grpc/credentials/insecure" ) func main() { tp := tracerprovider.New( tracerprovider.WithSamplePercentage(42), tracerprovider.WithGRPCExporter("localhost:4317", insecure.NewCredentials()), tracerprovider.WithContext(context.Background()), tracerprovider.WithServiceName("test"), tracerprovider.WithEnvironment("development"), tracerprovider.WithProcessor("processor"), tracerprovider.WithIgnore([]string{"/healthz"}), ) err := service.Run(service.Modules{tp}) if err != nil { fmt.Println(err) } }
Output: failed to initialize module otel.TracerProvider: otel.TracerProvider option error: invalid processor
func (*TracerProvider) Init ¶
func (tp *TracerProvider) Init() error
func (*TracerProvider) Name ¶
func (tp *TracerProvider) Name() string
func (*TracerProvider) Run ¶
func (tp *TracerProvider) Run() error
func (*TracerProvider) Stop ¶
func (tp *TracerProvider) Stop() error