Documentation
¶
Index ¶
- func GetTracer() oteltrace.Tracer
- func RecordErrorWithContext(span oteltrace.Span, err error, keywords map[string]struct{})
- func RedactAttributes(attrs []attribute.KeyValue, keywords map[string]struct{}) []attribute.KeyValue
- func RedactSecretsInString(input string, keywords map[string]struct{}) string
- func RedactStringMap(input map[string]string, keywords map[string]struct{}) map[string]string
- type OtelTracerProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTracer ¶
GetTracer returns a named tracer instance from the globally configured OpenTelemetry provider. If no global provider is configured (e.g., in tests or simple applications), it defaults to returning a NoOpTracer, which safely discards all tracing data. Note: It's generally preferred to inject the TracerProvider into components rather than relying on the global provider.
func RecordErrorWithContext ¶
RecordErrorWithContext records an error on an OpenTelemetry span, ensuring the error message stored in the span attributes and status is redacted based on keywords. It also attempts to record a stack trace. Does nothing if the error is nil or the span is nil/not recording.
func RedactAttributes ¶
func RedactAttributes(attrs []attribute.KeyValue, keywords map[string]struct{}) []attribute.KeyValue
RedactAttributes creates a new slice of OpenTelemetry KeyValue attributes where the value of any attribute whose key (converted to lowercase) matches a key in the `keywords` map is replaced with "[REDACTED]". Returns the original slice if keywords map is nil/empty or input slice is empty.
func RedactSecretsInString ¶
RedactSecretsInString searches a string for sensitive keywords (case-insensitive) and replaces potentially associated values with "[REDACTED]". This function uses simple heuristics (looking for keywords followed by common separators) and may not catch all possible formats. It operates line by line. `keywords` should be a map where keys are lowercase sensitive keywords. (Consolidated helper from template/funcs.go - keep only one canonical version, placing here for tracing context).
func RedactStringMap ¶
RedactStringMap creates a *new* map with values redacted based on keyword matching in keys. It iterates through the input map, checks if the lowercase version of the key exists in the `keywords` map (which should contain lowercase keywords), and replaces the value with "[REDACTED]" if a match is found. Original map is unchanged. Returns the original map if keywords map is nil/empty or input map is nil.
Types ¶
type OtelTracerProvider ¶
type OtelTracerProvider struct {
// contains filtered or unexported fields
}
OtelTracerProvider implements the public gxotracing.TracerProvider interface using the OpenTelemetry SDK for actual tracing or the official NoOp provider if tracing is disabled or configuration fails.
func NewNoOpProvider ¶
func NewNoOpProvider() (*OtelTracerProvider, error)
NewNoOpProvider creates a TracerProvider instance that performs no tracing operations. It utilizes the official OpenTelemetry NoOp implementation.
func NewProviderFromEnv ¶
func NewProviderFromEnv(ctx context.Context) (*OtelTracerProvider, error)
NewProviderFromEnv creates an OtelTracerProvider configured using standard OpenTelemetry environment variables (OTEL_*). If tracing is disabled (OTEL_SDK_DISABLED=true) or essential configuration (like endpoint) is missing or invalid, it falls back to using a NoOp provider. This function does *not* set the global OTel provider.
func (*OtelTracerProvider) GetTracer ¶
func (p *OtelTracerProvider) GetTracer(name string, opts ...trace.TracerOption) trace.Tracer
GetTracer returns a named tracer instance using the stored OpenTelemetry provider. This method implements the public gxotracing.TracerProvider interface. It returns either an SDK tracer or a NoOp tracer depending on initialization.
func (*OtelTracerProvider) IsEffectivelyNoOp ¶
func (p *OtelTracerProvider) IsEffectivelyNoOp() bool
IsEffectivelyNoOp checks if this provider instance is configured to be NoOp. This is primarily used internally by the engine to skip span creation.
func (*OtelTracerProvider) Shutdown ¶
func (p *OtelTracerProvider) Shutdown(ctx context.Context) error
Shutdown gracefully stops the underlying SDK TracerProvider and its associated exporter, ensuring buffered spans are flushed before exiting. It respects the provided context's deadline. This method implements the public gxotracing.TracerProvider interface. It is a no-op if the provider is the NoOp provider.