You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-15 01:04:25 +02:00
Add otlpmetricgrpc.Expoter and otlpmetrichttp.Exporter (#4272)
* Add otlpmetricgrpc.Expoter and otlpmetrichttp.Exporter * Update changelog
This commit is contained in:
@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
- Add `ManualReader` struct in `go.opentelemetry.io/otel/sdk/metric`. (#4244)
|
- Add `ManualReader` struct in `go.opentelemetry.io/otel/sdk/metric`. (#4244)
|
||||||
- Add `PeriodicReader` struct in `go.opentelemetry.io/otel/sdk/metric`. (#4244)
|
- Add `PeriodicReader` struct in `go.opentelemetry.io/otel/sdk/metric`. (#4244)
|
||||||
|
- Add `Exporter` struct in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#4272)
|
||||||
|
- Add `Exporter` struct in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4272)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
@ -21,6 +23,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
- `NewManualReader` in `go.opentelemetry.io/otel/sdk/metric` returns `*ManualReader` instead of `Reader`. (#4244)
|
- `NewManualReader` in `go.opentelemetry.io/otel/sdk/metric` returns `*ManualReader` instead of `Reader`. (#4244)
|
||||||
- `NewPeriodicReader` in `go.opentelemetry.io/otel/sdk/metric` returns `*PeriodicReader` instead of `Reader`. (#4244)
|
- `NewPeriodicReader` in `go.opentelemetry.io/otel/sdk/metric` returns `*PeriodicReader` instead of `Reader`. (#4244)
|
||||||
- Count the Collect time in the PeriodicReader timeout. (#4221)
|
- Count the Collect time in the PeriodicReader timeout. (#4221)
|
||||||
|
- `New` in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` returns `*Exporter` instead of `"go.opentelemetry.io/otel/sdk/metric".Exporter`. (#4272)
|
||||||
|
- `New` in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` returns `*Exporter` instead of `"go.opentelemetry.io/otel/sdk/metric".Exporter`. (#4272)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ import (
|
|||||||
mpb "go.opentelemetry.io/proto/otlp/metrics/v1"
|
mpb "go.opentelemetry.io/proto/otlp/metrics/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// exporter exports metrics data as OTLP.
|
// Exporter exports metrics data as OTLP.
|
||||||
type exporter struct {
|
type Exporter struct {
|
||||||
// Ensure synchronous access to the client across all functionality.
|
// Ensure synchronous access to the client across all functionality.
|
||||||
clientMu sync.Mutex
|
clientMu sync.Mutex
|
||||||
client Client
|
client Client
|
||||||
@ -36,21 +36,21 @@ type exporter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Temporality returns the Temporality to use for an instrument kind.
|
// Temporality returns the Temporality to use for an instrument kind.
|
||||||
func (e *exporter) Temporality(k metric.InstrumentKind) metricdata.Temporality {
|
func (e *Exporter) Temporality(k metric.InstrumentKind) metricdata.Temporality {
|
||||||
e.clientMu.Lock()
|
e.clientMu.Lock()
|
||||||
defer e.clientMu.Unlock()
|
defer e.clientMu.Unlock()
|
||||||
return e.client.Temporality(k)
|
return e.client.Temporality(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aggregation returns the Aggregation to use for an instrument kind.
|
// Aggregation returns the Aggregation to use for an instrument kind.
|
||||||
func (e *exporter) Aggregation(k metric.InstrumentKind) aggregation.Aggregation {
|
func (e *Exporter) Aggregation(k metric.InstrumentKind) aggregation.Aggregation {
|
||||||
e.clientMu.Lock()
|
e.clientMu.Lock()
|
||||||
defer e.clientMu.Unlock()
|
defer e.clientMu.Unlock()
|
||||||
return e.client.Aggregation(k)
|
return e.client.Aggregation(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export transforms and transmits metric data to an OTLP receiver.
|
// Export transforms and transmits metric data to an OTLP receiver.
|
||||||
func (e *exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) error {
|
func (e *Exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) error {
|
||||||
otlpRm, err := transform.ResourceMetrics(rm)
|
otlpRm, err := transform.ResourceMetrics(rm)
|
||||||
// Best effort upload of transformable metrics.
|
// Best effort upload of transformable metrics.
|
||||||
e.clientMu.Lock()
|
e.clientMu.Lock()
|
||||||
@ -67,7 +67,7 @@ func (e *exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ForceFlush flushes any metric data held by an exporter.
|
// ForceFlush flushes any metric data held by an exporter.
|
||||||
func (e *exporter) ForceFlush(ctx context.Context) error {
|
func (e *Exporter) ForceFlush(ctx context.Context) error {
|
||||||
// The Exporter does not hold data, forward the command to the client.
|
// The Exporter does not hold data, forward the command to the client.
|
||||||
e.clientMu.Lock()
|
e.clientMu.Lock()
|
||||||
defer e.clientMu.Unlock()
|
defer e.clientMu.Unlock()
|
||||||
@ -78,7 +78,7 @@ var errShutdown = fmt.Errorf("exporter is shutdown")
|
|||||||
|
|
||||||
// Shutdown flushes all metric data held by an exporter and releases any held
|
// Shutdown flushes all metric data held by an exporter and releases any held
|
||||||
// computational resources.
|
// computational resources.
|
||||||
func (e *exporter) Shutdown(ctx context.Context) error {
|
func (e *Exporter) Shutdown(ctx context.Context) error {
|
||||||
err := errShutdown
|
err := errShutdown
|
||||||
e.shutdownOnce.Do(func() {
|
e.shutdownOnce.Do(func() {
|
||||||
e.clientMu.Lock()
|
e.clientMu.Lock()
|
||||||
@ -96,8 +96,8 @@ func (e *exporter) Shutdown(ctx context.Context) error {
|
|||||||
// New return an Exporter that uses client to transmits the OTLP data it
|
// New return an Exporter that uses client to transmits the OTLP data it
|
||||||
// produces. The client is assumed to be fully started and able to communicate
|
// produces. The client is assumed to be fully started and able to communicate
|
||||||
// with its OTLP receiving endpoint.
|
// with its OTLP receiving endpoint.
|
||||||
func New(client Client) metric.Exporter {
|
func New(client Client) *Exporter {
|
||||||
return &exporter{client: client}
|
return &Exporter{client: client}
|
||||||
}
|
}
|
||||||
|
|
||||||
type shutdownClient struct {
|
type shutdownClient struct {
|
||||||
|
@ -36,22 +36,6 @@ import (
|
|||||||
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
|
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 gRPC.
|
|
||||||
//
|
|
||||||
// If an already established gRPC ClientConn is not passed in options using
|
|
||||||
// WithGRPCConn, a connection to the OTLP endpoint will be established based
|
|
||||||
// on options. If a connection cannot be establishes in the lifetime of ctx,
|
|
||||||
// an error will be returned.
|
|
||||||
func New(ctx context.Context, options ...Option) (metric.Exporter, error) {
|
|
||||||
c, err := newClient(ctx, options...)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ominternal.New(c), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
metadata metadata.MD
|
metadata metadata.MD
|
||||||
exportTimeout time.Duration
|
exportTimeout time.Duration
|
||||||
|
85
exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go
Normal file
85
exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// 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 otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
|
||||||
|
|
||||||
|
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 gRPC.
|
||||||
|
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 gRPC.
|
||||||
|
//
|
||||||
|
// If an already established gRPC ClientConn is not passed in options using
|
||||||
|
// WithGRPCConn, a connection to the OTLP endpoint will be established based
|
||||||
|
// on options. If a connection cannot be establishes in the lifetime of ctx,
|
||||||
|
// an error will be returned.
|
||||||
|
func New(ctx context.Context, options ...Option) (*Exporter, error) {
|
||||||
|
c, err := newClient(ctx, options...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
exp := ominternal.New(c)
|
||||||
|
return &Exporter{exp}, nil
|
||||||
|
}
|
@ -41,17 +41,6 @@ import (
|
|||||||
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
|
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 {
|
type client struct {
|
||||||
// req is cloned for every upload the client makes.
|
// req is cloned for every upload the client makes.
|
||||||
req *http.Request
|
req *http.Request
|
||||||
|
80
exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go
Normal file
80
exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go
Normal file
@ -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
|
||||||
|
}
|
Reference in New Issue
Block a user