Documentation
¶
Overview ¶
Package opentelemetry provides OpenTelemetry integration for Azugo applications.
Index ¶
- Constants
- func FromContext(ctx context.Context) context.Context
- func Recording(ctx context.Context) bool
- func Use(app *azugo.App, config *Configuration, opts ...Option) (core.Tasker, error)
- func Version() string
- type Configuration
- type Filter
- type InstrumentationRecorderFunc
- type InstrumentationSpanNameFormatter
- type Option
- type PublicEndpoint
- type PublicEndpointFilter
- type RouteSpanNameFormatter
- type Span
Constants ¶
const ( ProtocolGRPC = "grpc" ProtocolHTTPProtobuf = "http/protobuf" )
OTLP transport protocol values as defined by OTEL_EXPORTER_OTLP_PROTOCOL.
const (
// ScopeName is the instrumentation scope name.
ScopeName = "azugo.io/opentelemetry"
)
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
FromContext returns a context carrying the active span for the request, suitable as the parent for new spans.
func Recording ¶ added in v0.33.1
Recording reports whether a span started for ctx would be part of active tracing, and therefore eventually exported. Use it to guard custom instrumentation so it does not emit orphan spans for untraced requests:
if opentelemetry.Recording(ctx) {
ctx, span := tracer.Start(ctx, "my-operation")
defer span.End()
// ...
}
Outside of a request context it always returns true.
Types ¶
type Configuration ¶
type Configuration struct {
Disabled bool `mapstructure:"disabled"`
Endpoint string `mapstructure:"endpoint"`
Protocol string `mapstructure:"protocol" validate:"omitempty,oneof=grpc http/protobuf"`
InsecureSkipVerify bool `mapstructure:"insecure_skip_verify"`
ServiceName string `mapstructure:"service_name"`
ElasticAPMSecretToken string `mapstructure:"elastic_apm_secret_token"`
ResourceAttributes []string `mapstructure:"resource_attributes"`
}
Configuration section for OpenTracing.
func (*Configuration) Bind ¶
func (c *Configuration) Bind(prefix string, v *viper.Viper)
Bind OpenTracing configuration section.
func (*Configuration) IsDisabled ¶
func (c *Configuration) IsDisabled() bool
IsDisabled returns true if the tracing is disabled.
func (*Configuration) Validate ¶
func (c *Configuration) Validate(valid *validation.Validate) error
Validate OpenTracing configuration section.
type Filter ¶
Filter is a predicate used to determine whether a given HTTP request should be traced. A Filter must return true if the request should be traced.
Multiple filters can be proviaded and are applied in the order they are added. If no filters are provided then all requests are traced. Filters will be invoked for each processed request, it is advised to make them simple and fast.
type InstrumentationRecorderFunc ¶
type InstrumentationRecorderFunc func(ctx context.Context, tracer trace.Tracer, propagator propagation.TextMapPropagator, spfmt InstrumentationSpanNameFormatter, op string, args ...any) (func(err error), bool)
InstrumentationRecorderFunc specifies a function to use for handling instrumentation events. The function should return a function that can be used to finish the span and a boolean indicating if specific instrumentation has been recorded.
type InstrumentationSpanNameFormatter ¶
InstrumentationSpanNameFormatter specifies a function to use for generating a custom span name. By default, the span name is formatted based on the operation type and the arguments. If the provided function returns an empty string, the default span name will be used.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option specifies instrumentation configuration options.
func InstrumentationRecorder ¶
func InstrumentationRecorder(name string, recorder InstrumentationRecorderFunc, ops ...string) Option
InstrumentationRecorder specifies a function to use for handling instrumentation events for specific instrumentation operations. Multiple recorders can be provided and are applied in the order they are added.
func MeterProvider ¶ added in v0.37.1
func MeterProvider(provider metric.MeterProvider) Option
MeterProvider specifies a meter provider to use for creating metric instruments. If none is specified, the global provider is used.
func TextMapPropagator ¶
func TextMapPropagator(propagators propagation.TextMapPropagator) Option
TextMapPropagator specifies propagators to use for extracting information from the HTTP requests. If none are specified, global ones will be used.
func TracerProvider ¶
func TracerProvider(provider trace.TracerProvider) Option
TracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.
type PublicEndpoint ¶
type PublicEndpoint bool
PublicEndpoint configures the Handler to link the span with an incoming span context. If this option is not provided, then the association is a child association instead of a link.
type PublicEndpointFilter ¶
PublicEndpointFilter runs with every request, and allows conditionnally configuring the Handler to link the span with an incoming span context. If this option is not provided or returns false, then the association is a child association instead of a link. Note: PublicEndpoint takes precedence over PublicEndpointFilter.
type RouteSpanNameFormatter ¶
RouteSpanNameFormatter specifies a function to use for generating a custom span name. By default, the route name (path template or regexp) is used. The route name is provided so you can use it in the span name without needing to duplicate the logic for extracting it from the request.
type Span ¶ added in v0.35.0
Span wraps an OpenTelemetry span whose End is deferred to the end of the request. It is dropped together with the request if the request opts out of tracing.
Create one with StartSpan.
func StartSpan ¶ added in v0.35.0
func StartSpan(ctx context.Context, tracer trace.Tracer, name string, opts ...trace.SpanStartOption) (context.Context, Span)
StartSpan starts a span with tracer as a child of the active request span, and returns it wrapped so that End is deferred. Use it from custom instrumentation so the spans you create are dropped together with the request just like the built-in ones:
ctx, span := opentelemetry.StartSpan(ctx, otel.Tracer("myapp"), "work")
defer span.End()
func (Span) End ¶ added in v0.35.0
func (s Span) End(...trace.SpanEndOption)
End completes the Span. The Span is considered complete and ready to be delivered through the rest of the telemetry pipeline after this method is called. Therefore, updates to the Span are not allowed after this method has been called.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
semconvutil
Package semconvutil provides utilities for OpenTelemetry semantic conventions.
|
Package semconvutil provides utilities for OpenTelemetry semantic conventions. |
|
Package nethttp provides OpenTelemetry tracing instrumentation for standard library net/http clients.
|
Package nethttp provides OpenTelemetry tracing instrumentation for standard library net/http clients. |