Documentation
¶
Overview ¶
Package otel provides data structures to represent and generate otel configuration.
Index ¶
- Constants
- Variables
- func AddLabel(key, value string) map[string]interface{}
- func AddPrefix(prefix string, operations ...map[string]interface{}) map[string]interface{}
- func AggregateLabelValues(aggregationType string, label string, new string, old ...string) map[string]interface{}
- func AggregateLabels(aggregationType string, labels ...string) map[string]interface{}
- func ChangePrefix(oldPrefix, newPrefix string) map[string]interface{}
- func CombineMetrics(old, new string, operations ...map[string]interface{}) map[string]interface{}
- func DeleteLabelValue(label, value string) map[string]interface{}
- func DuplicateMetric(old, new string, operations ...map[string]interface{}) map[string]interface{}
- func RegexpRename(regexp string, rename string, operations ...map[string]interface{}) map[string]interface{}
- func RenameLabel(old, new string) map[string]interface{}
- func RenameLabelValues(label string, transforms map[string]string) map[string]interface{}
- func RenameMetric(old, new string, operations ...map[string]interface{}) map[string]interface{}
- func ScaleValue(factor float64) map[string]interface{}
- func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K
- func UpdateMetric(metric string, operations ...map[string]interface{}) map[string]interface{}
- func UpdateMetricRegexp(metricRegex string, operations ...map[string]interface{}) map[string]interface{}
- type Component
- func BatchProcessor(sendBatchSize, sendBatchMaxSize int, timeout string) Component
- func CondenseResourceMetrics() Component
- func CopyServiceResourceLabels() Component
- func CumulativeToDelta(metrics ...string) Component
- func CumulativeToDeltaWithInitialValue(initial_value string, metrics ...string) Component
- func DeltaToCumulative() Component
- func DeltaToRate(metrics ...string) Component
- func DisableOtlpRoundTrip() Component
- func Filter(dataType, context string, expressions []ottl.Value) Component
- func GCPProjectID(projectID string) Component
- func GCPResourceDetector(override bool) Component
- func GroupByGMPAttrs() Component
- func GroupByGMPAttrs_OTTL() Component
- func Interval(duration string) Component
- func MetricStartTime() Component
- func MetricUnknownCounter() Component
- func MetricsFilter(polarity, matchType string, metricNames ...string) Component
- func MetricsOTTLFilter(metricQueries []string, datapointQueries []string) Component
- func MetricsRemoveInstrumentationLibraryLabelsAttributes() Component
- func MetricsRemoveServiceAttributes() Component
- func MetricsTransform(metrics ...map[string]interface{}) Component
- func PreserveInstrumentationScope() Component
- func ResourceTransform(attributes map[string]string, override bool) Component
- func Transform(statementType, context string, statements ottl.Statements) Component
- func TransformationMetrics(queries ...TransformQuery) Component
- type ExporterComponents
- type ExporterType
- type ModularConfig
- type Pipeline
- type ReceiverPipeline
- type ResourceDetectionMode
- type TransformQuery
- func ConvertFloatToInt(metricName string) TransformQuery
- func ConvertGaugeToSum(metricName string) TransformQuery
- func DeleteMetricAttribute(metricAttribute string) TransformQuery
- func DeleteMetricResourceAttribute(metricAttribute string) TransformQuery
- func FlattenResourceAttribute(resourceAttribute, metricAttribute string) TransformQuery
- func GroupByAttribute(attribute string) TransformQuery
- func RetainResource(resourceAttributeKeys ...string) TransformQuery
- func SetAttribute(metricName, attributeKey, attributeValue string) TransformQuery
- func SetDescription(metricName, metricDescription string) TransformQuery
- func SetName(oldName, newName string) TransformQuery
- func SetScopeName(newName string) TransformQuery
- func SetScopeVersion(newVersion string) TransformQuery
- func SetUnit(metricName, unit string) TransformQuery
- func SummaryCountValToSum(metricName, aggregation string, isMonotonic bool) TransformQuery
- func SummarySumValToSum(metricName, aggregation string, isMonotonic bool) TransformQuery
- type TransformQueryContext
Constants ¶
const MetricsPort = 20201
Variables ¶
var ToggleScalarDataType = map[string]interface{}{"action": "toggle_scalar_data_type"}
ToggleScalarDataType transforms int -> double and double -> int.
Functions ¶
func AggregateLabelValues ¶
func AggregateLabelValues(aggregationType string, label string, new string, old ...string) map[string]interface{}
AggregateLabelValues combines the given values into a single value
func AggregateLabels ¶
AggregateLabels removes all labels except those in the passed list, aggregating values using aggregationType.
func ChangePrefix ¶
ChangePrefix returns a config snippet that updates a prefix on all metrics.
func CombineMetrics ¶
CombineMetrics returns a config snippet that renames metrics matching the regex old to new, applying zero or more transformations.
func DeleteLabelValue ¶
DeleteLabelValue removes streams with the given label value
func DuplicateMetric ¶
DuplicateMetric returns a config snippet that copies old to new, applying zero or more transformations.
func RegexpRename ¶
func RegexpRename(regexp string, rename string, operations ...map[string]interface{}) map[string]interface{}
RegexpRename returns a config snippet that renames metrics matching the given regexp. The `rename` argument supports capture groups as `${1}`, `${2}`, and so on.
func RenameLabel ¶
RenameLabel renames old to new
func RenameLabelValues ¶
RenameLabelValues renames label values
func RenameMetric ¶
RenameMetric returns a config snippet that renames old to new, applying zero or more transformations.
func ScaleValue ¶
ScaleValue multiplies the value by factor
func SortedKeys ¶
func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K
sortedKeys returns sorted keys from a Set if the Set has a type that can be ordered.
func UpdateMetric ¶
UpdateMetric returns a config snippet applies transformations to the given metric name
func UpdateMetricRegexp ¶
func UpdateMetricRegexp(metricRegex string, operations ...map[string]interface{}) map[string]interface{}
UpdateMetricRegexp returns a config snippet that applies transformations to metrics matching the input regex
Types ¶
type Component ¶
type Component struct {
// Type is the string type needed to instantiate the OT component (e.g. "windowsperfcounters")
Type string
// Config is an object which can be serialized by mapstructure into the configuration for the component.
// This can either be a map[string]interface{} or a Config struct from OT.
Config interface{}
}
Component represents a single OT component (receiver, processor, exporter, etc.)
func BatchProcessor ¶
func CondenseResourceMetrics ¶
func CondenseResourceMetrics() Component
CondenseResourceMetrics merges multiple resource metrics on a slice of metrics to a single resource metrics payload, if they have the same resource.
func CopyServiceResourceLabels ¶
func CopyServiceResourceLabels() Component
This processor copies the service.* attributes from the resource to the logRecord attributes, if they exist. This processor is required to send logs to telemetry.googleapis.com through an otlp exporter.
func CumulativeToDelta ¶
CumulativeToDelta returns a Component that converts each cumulative metric to delta.
func CumulativeToDeltaWithInitialValue ¶
CumulativeToDeltaWithInitialValue returns a Component that converts each cumulative metric to delta with the possibility to set the "initial_value" option.
func DeltaToCumulative ¶
func DeltaToCumulative() Component
DeltaToCumulative returns a Component that converts each delta metric to cumulative.
func DeltaToRate ¶
DeltaToRate returns a Component that converts each delta metric to a gauge rate.
func DisableOtlpRoundTrip ¶
func DisableOtlpRoundTrip() Component
This processor prevents telemetry.googleapis.com from populating the LogEntry.otlp field by setting the gcp.use_legacy_mapping resource attribute to true.
func Filter ¶
Filter returns a filter processor object that drops dataType.context data matching any of the expressions.
func GCPProjectID ¶
func GCPResourceDetector ¶
GCPResourceDetector returns a resourcedetection processor configured for only GCP.
func GroupByGMPAttrs ¶
func GroupByGMPAttrs() Component
GroupByGMPAttrs moves the "namespace", "cluster", and "location" metric attributes to resource attributes. The googlemanagedprometheus exporter will use these resource attributes to populate metric labels.
func GroupByGMPAttrs_OTTL ¶
func GroupByGMPAttrs_OTTL() Component
GroupByGMPAttrs_OTTL moves the "namespace", "cluster", and "location" metric attributes to resource attributes similar to GroupByGMPAttrs. The difference here is it uses OTTL instead of the groupbyattrs processor since that processor discards certain metadata from the metrics that are important to preserve prometheus untyped metrics.
See more detail in https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33419.
func MetricStartTime ¶
func MetricStartTime() Component
func MetricUnknownCounter ¶
func MetricUnknownCounter() Component
MetricUnknownCounter is necessary to handle prometheus unknown type metrics go/ops-agent-otlp-migration
func MetricsFilter ¶
MetricsFilter returns a Component that filters metrics. polarity should be "include" or "exclude". matchType should be "strict" or "regexp".
func MetricsOTTLFilter ¶
MetricsOTTLFilter returns a Component that filters metrics using OTTL. OTTL can only be used as an exclude filter, any metrics or datapoints that match one of the provided queries are dropped. Example query: 'name == "jvm.memory.heap.used" and resource.attributes["elasticsearch.node.name"] == nil'
func MetricsRemoveInstrumentationLibraryLabelsAttributes ¶
func MetricsRemoveInstrumentationLibraryLabelsAttributes() Component
func MetricsRemoveServiceAttributes ¶
func MetricsRemoveServiceAttributes() Component
MetricsRemoveServiceAttributes will remove any service attributes that the googlecloudexporter attempts to promote from resource to metric attributes. The attributes it removes are specified at: https://opentelemetry.io/docs/specs/semconv/registry/attributes/service/
This does not use the typical TransformQuery API because it needs to have a silent error_mode and use the resource context. The latter would have been easily fixable, but the error_mode would have required a major refactor for this to be the only TransformQuery making use of it. - @braydonk
func MetricsTransform ¶
MetricsTransform returns a Component that performs the transformations specified as arguments.
func PreserveInstrumentationScope ¶
func PreserveInstrumentationScope() Component
This processor preserves instrumentation scope name and version in logRecord attributes, if they exist. This processor is required to send logs to telemetry.googleapis.com through an otlp exporter.
func ResourceTransform ¶
ResourceTransform returns a Component that applies changes on resource attributes.
func Transform ¶
func Transform(statementType, context string, statements ottl.Statements) Component
Transform returns a transform processor object that executes statements on statementType data.
func TransformationMetrics ¶
func TransformationMetrics(queries ...TransformQuery) Component
TransformationMetrics returns a transform processor object that contains all the queries passed into it.
type ExporterComponents ¶
type ExporterType ¶
type ExporterType int
const ( // N.B. Every ExporterType increases the QPS and thus quota // consumption in consumer projects; think hard before adding // another exporter type. OTel ExporterType = iota System GMP OTLP_Metrics OTLP_Logs Logging )
func (ExporterType) Name ¶
func (t ExporterType) Name() string
type ModularConfig ¶
type ModularConfig struct {
LogLevel string
ReceiverPipelines map[string]ReceiverPipeline
Pipelines map[string]Pipeline
Exporters map[ExporterType]ExporterComponents
Extensions map[string]Component
MetricsPort uint16
// Test-only options:
// Don't generate any self-metrics
DisableMetrics bool
// Emit collector logs as JSON
JSONLogs bool
}
func (ModularConfig) Generate ¶
func (c ModularConfig) Generate(ctx context.Context) (string, error)
Generate an OT YAML config file for c. Each pipeline gets generated as a receiver, per-pipeline processors, global processors, and then global exporter. For example: metrics/mypipe:
receivers: [hostmetrics/mypipe] processors: [filter/mypipe_1, metrics_filter/mypipe_2, resourcedetection/_global_0] extensions: [googleclientauth] exporters: [googlecloud]
type Pipeline ¶
type Pipeline struct {
// Type is "metrics" or "traces".
Type string
ReceiverPipelineName string
Processors []Component
}
Pipeline represents one (of potentially many) pipelines consuming data from a ReceiverPipeline.
type ReceiverPipeline ¶
type ReceiverPipeline struct {
Receiver Component
// UsedExtensions is a list of extensions used by this receiver.
UsedExtensions []string
// Processors is a map with processors for each pipeline type ("metrics" or "traces").
// If a key is not in the map, the receiver pipeline will not be used for that pipeline type.
Processors map[string][]Component
// ExporterTypes indicates if the pipeline outputs special data (either Prometheus or system metrics) that need to be handled with a special exporter.
ExporterTypes map[string]ExporterType
// ResourceDetectionModes indicates whether the resource should be forcibly set, set only if not already present, or never set.
// If a data type is not present, it will assume the zero value (Override).
ResourceDetectionModes map[string]ResourceDetectionMode
}
ReceiverPipeline represents a single OT receiver and zero or more processors that must be chained after that receiver.
type ResourceDetectionMode ¶
type ResourceDetectionMode int
const ( Override ResourceDetectionMode = iota SetIfMissing None )
type TransformQuery ¶
type TransformQuery struct {
Context TransformQueryContext
Statement string
}
TransformQuery is a type wrapper for query expressions supported by the transform processor found here: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/transformprocessor
func ConvertFloatToInt ¶
func ConvertFloatToInt(metricName string) TransformQuery
ConvertFloatToInt returns an expression where a float-valued metric can be converted to an int
func ConvertGaugeToSum ¶
func ConvertGaugeToSum(metricName string) TransformQuery
ConvertGaugeToSum returns an expression where a gauge metric can be converted into a sum
func DeleteMetricAttribute ¶
func DeleteMetricAttribute(metricAttribute string) TransformQuery
DeleteMetricAttribute returns an expression that removes the metric attribute specified.
func DeleteMetricResourceAttribute ¶
func DeleteMetricResourceAttribute(metricAttribute string) TransformQuery
DeleteMetricResourceAttribute returns an expression that removes the metric resource attribute specified.
func FlattenResourceAttribute ¶
func FlattenResourceAttribute(resourceAttribute, metricAttribute string) TransformQuery
FlattenResourceAttribute returns an expression that brings down a resource attribute to a metric attribute.
func GroupByAttribute ¶
func GroupByAttribute(attribute string) TransformQuery
GroupByAttribute returns an expression that makes a metric attribute into a resource attribute.
func RetainResource ¶
func RetainResource(resourceAttributeKeys ...string) TransformQuery
RetainResource retains the resource attributes provided, and drops all other attributes.
func SetAttribute ¶
func SetAttribute(metricName, attributeKey, attributeValue string) TransformQuery
func SetDescription ¶
func SetDescription(metricName, metricDescription string) TransformQuery
SetDescription returns a metrics transform expression where the metrics description will be set to what is provided
func SetName ¶
func SetName(oldName, newName string) TransformQuery
SetName returns a metrics transform expression where the metric name is set to provided value
func SetScopeName ¶
func SetScopeName(newName string) TransformQuery
SetScopeName returns a metrics transform that sets the name of the instrumentation scope
func SetScopeVersion ¶
func SetScopeVersion(newVersion string) TransformQuery
SetScopeVersion returns a metrics transform that sets the version of the instrumentation scope
func SetUnit ¶
func SetUnit(metricName, unit string) TransformQuery
SetUnit returns a metrics transform expression where the metric unit is set to provided value
func SummaryCountValToSum ¶
func SummaryCountValToSum(metricName, aggregation string, isMonotonic bool) TransformQuery
SummaryCountValToSum creates a new Sum metric out of a summary metric's count value. The new metric has a name of "<Old Name>_count".
func SummarySumValToSum ¶
func SummarySumValToSum(metricName, aggregation string, isMonotonic bool) TransformQuery
SummarySumValToSum creates a new Sum metric out of a summary metric's sum value. The new metric has a name of "<Old Name>_sum".
type TransformQueryContext ¶
type TransformQueryContext string
TransformQueryContext is a type wrapper for the context of a query expression within the transoform processor
const ( Metric TransformQueryContext = "metric" Datapoint TransformQueryContext = "datapoint" Scope TransformQueryContext = "scope" Resource TransformQueryContext = "resource" )