Skip to content

Commit

Permalink
Fixes for the otlp metrics exporter (#2835)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadVikingGod authored Apr 20, 2022
1 parent 0b9cf58 commit 8b6f0c6
Show file tree
Hide file tree
Showing 20 changed files with 883 additions and 1,018 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

TOOLS_MOD_DIR := ./internal/tools
SKIP_MODS := ./bridge/opencensus ./bridge/opencensus/test ./example/opencensus
SKIP_MODS += ./exporters/otlp/otlpmetric ./exporters/otlp/otlpmetric/otlpmetricgrpc ./exporters/otlp/otlpmetric/otlpmetrichttp
# SKIP_MODS += ./exporters/otlp/otlpmetric ./exporters/otlp/otlpmetric/otlpmetricgrpc ./exporters/otlp/otlpmetric/otlpmetrichttp
# SKIP_MODS += ./exporters/prometheus ./exporters/stdout/stdoutmetric

ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
Expand Down
33 changes: 12 additions & 21 deletions exporters/otlp/otlpmetric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import (
"sync"

"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/metrictransform"
"go.opentelemetry.io/otel/sdk/metric/export"
"go.opentelemetry.io/otel/sdk/metric/export/aggregation"
"go.opentelemetry.io/otel/sdk/metric/sdkapi"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/metric/aggregator/aggregation"
"go.opentelemetry.io/otel/sdk/metric/reader"
)

var (
Expand All @@ -32,8 +30,7 @@ var (

// Exporter exports metrics data in the OTLP wire format.
type Exporter struct {
client Client
temporalitySelector aggregation.TemporalitySelector
client Client

mu sync.RWMutex
started bool
Expand All @@ -42,15 +39,11 @@ type Exporter struct {
stopOnce sync.Once
}

var _ reader.Exporter = (*Exporter)(nil)

// Export exports a batch of metrics.
func (e *Exporter) Export(ctx context.Context, res *resource.Resource, ilr export.InstrumentationLibraryReader) error {
rm, err := metrictransform.InstrumentationLibraryReader(ctx, e, res, ilr, 1)
if err != nil {
return err
}
if rm == nil {
return nil
}
func (e *Exporter) Export(ctx context.Context, metrics reader.Metrics) error {
rm := metrictransform.TransformMetrics(metrics)

// TODO: There is never more than one resource emitted by this
// call, as per the specification. We can change the
Expand Down Expand Up @@ -95,12 +88,11 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
return err
}

func (e *Exporter) TemporalityFor(descriptor *sdkapi.Descriptor, kind aggregation.Kind) aggregation.Temporality {
return e.temporalitySelector.TemporalityFor(descriptor, kind)
func (e *Exporter) Flush(ctx context.Context) error {
// TODO Implement
return nil
}

var _ export.Exporter = (*Exporter)(nil)

// New constructs a new Exporter and starts it.
func New(ctx context.Context, client Client, opts ...Option) (*Exporter, error) {
exp := NewUnstarted(client, opts...)
Expand All @@ -116,16 +108,15 @@ func NewUnstarted(client Client, opts ...Option) *Exporter {
// Note: the default TemporalitySelector is specified
// as Cumulative:
// https://github.com/open-telemetry/opentelemetry-specification/issues/731
temporalitySelector: aggregation.CumulativeTemporalitySelector(),
temporality: aggregation.CumulativeTemporality,
}

for _, opt := range opts {
cfg = opt.apply(cfg)
}

e := &Exporter{
client: client,
temporalitySelector: cfg.temporalitySelector,
client: client,
}

return e
Expand Down
Loading

0 comments on commit 8b6f0c6

Please sign in to comment.