You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
677 B
26 lines
677 B
8 months ago
|
package grpc
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
|
||
|
"gitoa.ru/go-4devs/otel/meter"
|
||
|
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
|
||
|
"go.opentelemetry.io/otel/sdk/metric"
|
||
|
)
|
||
|
|
||
|
func With(endpoint string, options ...otlpmetricgrpc.Option) func(context.Context, *meter.Option) error {
|
||
|
return func(ctx context.Context, o *meter.Option) error {
|
||
|
if len(options) == 0 {
|
||
|
options = append(options, otlpmetricgrpc.WithInsecure(), otlpmetricgrpc.WithEndpoint(endpoint))
|
||
|
}
|
||
|
|
||
|
exp, err := otlpmetricgrpc.New(ctx, options...)
|
||
|
if err != nil {
|
||
|
return fmt.Errorf("create otlpmetricgrpc: %w", err)
|
||
|
}
|
||
|
|
||
|
return meter.WithReader(metric.NewPeriodicReader(exp))(ctx, o)
|
||
|
}
|
||
|
}
|