Documentation ¶
Overview ¶
Copyright (c) 2023 Snowflake Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package metrics contains code for adding metric instrumentations to Sansshell processes
Copyright (c) 2023 Snowflake Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func NewContextWithRecorder(ctx context.Context, recorder MetricsRecorder) context.Context
- func StreamClientMetricsInterceptor(recorder MetricsRecorder) grpc.StreamClientInterceptor
- func StreamServerMetricsInterceptor(recorder MetricsRecorder) grpc.StreamServerInterceptor
- func UnaryClientMetricsInterceptor(recorder MetricsRecorder) grpc.UnaryClientInterceptor
- func UnaryServerMetricsInterceptor(recorder MetricsRecorder) grpc.UnaryServerInterceptor
- type MetricDefinition
- type MetricsRecorder
- type Option
- type OtelRecorder
- func (m *OtelRecorder) Counter(ctx context.Context, definition MetricDefinition, value int64, ...) error
- func (m *OtelRecorder) CounterOrLog(ctx context.Context, metric MetricDefinition, value int64, ...)
- func (m *OtelRecorder) Gauge(ctx context.Context, metric MetricDefinition, callback ometric.Int64Callback, ...) error
- func (m *OtelRecorder) GaugeOrLog(ctx context.Context, metric MetricDefinition, callback ometric.Int64Callback, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContextWithRecorder ¶
func NewContextWithRecorder(ctx context.Context, recorder MetricsRecorder) context.Context
NewContextWithRecorder returns context with recorder attached.
func StreamClientMetricsInterceptor ¶
func StreamClientMetricsInterceptor(recorder MetricsRecorder) grpc.StreamClientInterceptor
StreamClientMetricsInterceptor returns a stream client grpc interceptor which adds recorder to the grpc stream context
func StreamServerMetricsInterceptor ¶
func StreamServerMetricsInterceptor(recorder MetricsRecorder) grpc.StreamServerInterceptor
StreamServerMetricsInterceptor returns a stream server grpc interceptor which adds recorder to the grpc stream context
func UnaryClientMetricsInterceptor ¶
func UnaryClientMetricsInterceptor(recorder MetricsRecorder) grpc.UnaryClientInterceptor
UnaryClientMetricsInterceptor returns an unary client grpc interceptor which adds recorder to the grpc request context
func UnaryServerMetricsInterceptor ¶
func UnaryServerMetricsInterceptor(recorder MetricsRecorder) grpc.UnaryServerInterceptor
UnaryServerMetricsInterceptor returns an unary server grpc interceptor which adds recorder to the grpc request context
Types ¶
type MetricDefinition ¶ added in v1.20.0
MetricDefinition specifies the metric name and description
type MetricsRecorder ¶
type MetricsRecorder interface { // Counter increments the counter Counter(ctx context.Context, metric MetricDefinition, value int64, attributes ...attribute.KeyValue) error // CounterOrLog calls Counter, and log the error if any instead of returning it CounterOrLog(ctx context.Context, metric MetricDefinition, value int64, attributes ...attribute.KeyValue) // Gauge registers a gauge of int64 type and a callback function for updating the gauge value Gauge(ctx context.Context, metric MetricDefinition, callback metric.Int64Callback, attributes ...attribute.KeyValue) error // CounterOrLog calls Gauge, and log the error if any instead of returning it GaugeOrLog(ctx context.Context, metric MetricDefinition, callback metric.Int64Callback, attributes ...attribute.KeyValue) }
MetricsRecorder contains methods used for collecting metrics.
func RecorderFromContext ¶
func RecorderFromContext(ctx context.Context) MetricsRecorder
RecorderFromContext returns the MetricsRecorder object in the context if exists Otherwise it returns nil
func RecorderFromContextOrNoop ¶
func RecorderFromContextOrNoop(ctx context.Context) MetricsRecorder
RecorderFromContextOrNoop returns the MetricsRecorder object in the context if exists Otherwise it returns a noOpRecorder object
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithMetricNamePrefix ¶
WithMetricNamePrefix adds metric name prefix to the OtelRecorder
type OtelRecorder ¶
type OtelRecorder struct { Meter metric.Meter // type: map[string]Int64Counter Int64Counters sync.Map // type: map[string]Int64Gauge Int64Gauges sync.Map // contains filtered or unexported fields }
OtelRecorder is a struct used for recording metrics with otel It implements MetricsRecorder
func NewOtelRecorder ¶
func NewOtelRecorder(meter metric.Meter, opts ...Option) (*OtelRecorder, error)
NewOtelRecorder returns a new OtelRecorder instance
func (*OtelRecorder) Counter ¶ added in v1.20.0
func (m *OtelRecorder) Counter(ctx context.Context, definition MetricDefinition, value int64, attributes ...attribute.KeyValue) error
Counter registers the counter if it's not registered, then increments it
func (*OtelRecorder) CounterOrLog ¶ added in v1.20.0
func (m *OtelRecorder) CounterOrLog(ctx context.Context, metric MetricDefinition, value int64, attributes ...attribute.KeyValue)
Counter registers the counter if it's not registered, then increments it
func (*OtelRecorder) Gauge ¶ added in v1.20.0
func (m *OtelRecorder) Gauge(ctx context.Context, metric MetricDefinition, callback ometric.Int64Callback, attributes ...attribute.KeyValue) error
Gauge registers the gauge along with the callback function that updates its value
func (*OtelRecorder) GaugeOrLog ¶ added in v1.20.0
func (m *OtelRecorder) GaugeOrLog(ctx context.Context, metric MetricDefinition, callback ometric.Int64Callback, attributes ...attribute.KeyValue)
Counter registers the counter if it's not registered, then increments it