redact

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

Redact

Go Reference

Unfortunately, you are here. You have OpenTelemetry tracing data that shouldn't exist and you want it gone. Ideally, you are able to stop the generation of this data. But until that day arrives, redact can help!

Getting Started

Pass your needed redact option to a new OpenTelemetry TracerProvider.

Redact Attributes

Replace attributes from new spans that have keys matching "password", "user", and "secret" with a redacted value.

tracerProvider := trace.NewTracerProvider(
	redact.Attributes("password", "user", "secret"),
	/* ... */
)
Redact Spans based on name

Drop spans whose name is "really-annoying-span" or any that match "health?check*" (e.g. "health-check", "healthcheck-my-service").

tracerProvider := trace.NewTracerProvider(
	redact.Span("really-annoying-span", "health?check*"),
	/* ... */
)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attributes

func Attributes(keys ...string) trace.TracerProviderOption

Attributes returns an OpenTelemetry SDK TracerProviderOption. It registers an OpenTelemetry SpanProcessor that redacts attributes of new spans matching the passed keys.

Example
package main

import (
	"github.com/MrAlias/redact"
	"go.opentelemetry.io/otel/sdk/trace"
)

func main() {
	_ = trace.NewTracerProvider(
		// Replace attributes from new spans that have keys matching
		// "password", "user", and "secret" with the redacted value
		// "****REDACTED****".
		redact.Attributes("password", "user", "secret"),
		/* From here, configure your trace pipeline as normal ... */
	)
}
Output:

func Span

func Span(names ...string) trace.TracerProviderOption

Span returns an OpenTelemetry SDK TracerProviderOption. It registers an OpenTelemetry Sampler that drops all spans with matching names. A name can be the exact span name, or contain wildcards. See NewSpanCensor for information about matching.

Example
package main

import (
	"github.com/MrAlias/redact"
	"go.opentelemetry.io/otel/sdk/trace"
)

func main() {
	_ = trace.NewTracerProvider(
		// Drop spans whose name is `"health-check"`.
		redact.Span("health-check"),
		/* From here, configure your trace pipeline as normal ... */
	)
}
Output:

Types

type AttributeCensor

type AttributeCensor struct {
	// contains filtered or unexported fields
}

AttributeCensor is an OpenTelemetry SpanProcessor that censors attributes of new spans.

func NewAttributeCensor

func NewAttributeCensor(replacements map[attribute.Key]attribute.Value) AttributeCensor

NewAttributeCensor returns an AttributeCensor that uses the provided mapping of replacement values for a set of keys to redact matching attributes. Attributes are matched based on the equality of keys.

func (AttributeCensor) ForceFlush

func (AttributeCensor) ForceFlush(context.Context) error

ForceFlush does nothing.

func (AttributeCensor) OnEnd

func (c AttributeCensor) OnEnd(s trace.ReadOnlySpan)

OnEnd censors the attributes of s matching the Replacements keys of c.

func (AttributeCensor) OnStart

OnStart does nothing.

func (AttributeCensor) Shutdown

Shutdown does nothing.

type SpanCensor

type SpanCensor struct {
	// contains filtered or unexported fields
}

SpanCensor is an OpenTelemetry Sampler that drops spans with certain names. See NewSpanCensor for information about name matching.

func NewSpanCensor

func NewSpanCensor(parent trace.Sampler, names ...string) SpanCensor

NewSpanCensor returns a new configured SpanCensor. Any span with a name matching one of the passed names will be dropped. A name can be an exact string match for the span name, or contain wildcards. The * wildcard is expanded to match zero or more characters and the ? wildcard matches exactly one character. One or more wildcards can be used in combination to match a name.

func (SpanCensor) Description

func (s SpanCensor) Description() string

Description returns an identification description of the SpanCensor.

func (SpanCensor) ShouldSample

ShouldSample returns a sampling decision to drop when p contains a name matching the SpanCensor criteria. Otherwise, the sampling decision is delegated to the Sampler SpanCensor wraps.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL