1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Add otlpmetricgrpc.Expoter and otlpmetrichttp.Exporter (#4272)

* Add otlpmetricgrpc.Expoter and otlpmetrichttp.Exporter

* Update changelog
This commit is contained in:
Robert Pająk
2023-07-01 16:20:35 +02:00
committed by GitHub
parent 56609f8da9
commit 7ebfa8abf9
6 changed files with 178 additions and 36 deletions
@@ -41,17 +41,6 @@ import (
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
)
// New returns an OpenTelemetry metric Exporter. The Exporter can be used with
// a PeriodicReader to export OpenTelemetry metric data to an OTLP receiving
// endpoint using protobufs over HTTP.
func New(_ context.Context, opts ...Option) (metric.Exporter, error) {
c, err := newClient(opts...)
if err != nil {
return nil, err
}
return ominternal.New(c), nil
}
type client struct {
// req is cloned for every upload the client makes.
req *http.Request
@@ -0,0 +1,80 @@
// Copyright The OpenTelemetry Authors
//
// 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 otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
import (
"context"
ominternal "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)
// Exporter is a OpenTelemetry metric Exporter using protobufs over HTTP.
type Exporter struct {
wrapped *ominternal.Exporter
}
// Temporality returns the Temporality to use for an instrument kind.
func (e *Exporter) Temporality(k metric.InstrumentKind) metricdata.Temporality {
return e.wrapped.Temporality(k)
}
// Aggregation returns the Aggregation to use for an instrument kind.
func (e *Exporter) Aggregation(k metric.InstrumentKind) aggregation.Aggregation {
return e.wrapped.Aggregation(k)
}
// Export transforms and transmits metric data to an OTLP receiver.
//
// This method returns an error if called after Shutdown.
// This method returns an error if the method is canceled by the passed context.
func (e *Exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) error {
return e.wrapped.Export(ctx, rm)
}
// ForceFlush flushes any metric data held by an exporter.
//
// This method returns an error if called after Shutdown.
// This method returns an error if the method is canceled by the passed context.
//
// This method is safe to call concurrently.
func (e *Exporter) ForceFlush(ctx context.Context) error {
return e.wrapped.ForceFlush(ctx)
}
// Shutdown flushes all metric data held by an exporter and releases any held
// computational resources.
//
// This method returns an error if called after Shutdown.
// This method returns an error if the method is canceled by the passed context.
//
// This method is safe to call concurrently.
func (e *Exporter) Shutdown(ctx context.Context) error {
return e.wrapped.Shutdown(ctx)
}
// New returns an OpenTelemetry metric Exporter. The Exporter can be used with
// a PeriodicReader to export OpenTelemetry metric data to an OTLP receiving
// endpoint using protobufs over HTTP.
func New(_ context.Context, opts ...Option) (*Exporter, error) {
c, err := newClient(opts...)
if err != nil {
return nil, err
}
exp := ominternal.New(c)
return &Exporter{exp}, nil
}