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 MetricsRecorder
- type Option
- type OtelRecorder
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 MetricsRecorder ¶
type MetricsRecorder interface { // RegisterInt64Counter registers a counter of int64 type RegisterInt64Counter(name, description string) error // RegisterInt64Gauge registers a gauge of int64 type and a callback function for updating the gauge value RegisterInt64Gauge(name, description string, callback instrument.Int64Callback) error // AddInt64Counter increments the counter value AddInt64Counter(ctx context.Context, name string, value int64, attributes ...attribute.KeyValue) error }
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) AddInt64Counter ¶
func (m *OtelRecorder) AddInt64Counter(ctx context.Context, name string, value int64, attributes ...attribute.KeyValue) error
AddInt64Counter increments the counter by the given value It will return an error if the counter is not registered
func (*OtelRecorder) RegisterInt64Counter ¶
func (m *OtelRecorder) RegisterInt64Counter(name, description string) error
RegisterInt64Counter creates an Int64Counter and saves it to the register. If there is an existing counter with the same name, it's a no-op.
func (*OtelRecorder) RegisterInt64Gauge ¶
func (m *OtelRecorder) RegisterInt64Gauge(name, description string, callback instrument.Int64Callback) error
RegisterInt64Coungter creates an Int64Gauge and saves it to the register. If there is an existing gauge with the same name, the existing gauge will get overwritten.