1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-17 01:12:45 +02:00

Support a single Resource per MeterProvider in the SDK (#2120)

* Remove resource from export.Record

* fix bridge/opencensus

* partial fixes in exporters/otlp/otlpmetric

* Use go-cmp to simplify exporter_test

* OTLP http/grpc

* prometheus

* fix stdout (pending PR 2015)

* oc bridge cleanups

* Lint and changelog

* pr num

* cleanup

* revert

* fix multiple

* always merge the environment

* lint

* precommit

* qualify package names in changelog
This commit is contained in:
Joshua MacDonald
2021-08-12 15:44:58 -07:00
committed by GitHub
parent a8bb0bf89f
commit 4e8d667f6e
30 changed files with 324 additions and 446 deletions

View File

@ -59,6 +59,7 @@ type Controller struct {
accumulator *sdk.Accumulator
provider *registry.MeterProvider
checkpointer export.Checkpointer
resource *resource.Resource
exporter export.Exporter
wg sync.WaitGroup
stopCh chan struct{}
@ -88,16 +89,19 @@ func New(checkpointer export.Checkpointer, opts ...Option) *Controller {
}
if c.Resource == nil {
c.Resource = resource.Default()
} else {
var err error
c.Resource, err = resource.Merge(resource.Environment(), c.Resource)
if err != nil {
otel.Handle(err)
}
}
impl := sdk.NewAccumulator(
checkpointer,
c.Resource,
)
impl := sdk.NewAccumulator(checkpointer)
return &Controller{
provider: registry.NewMeterProvider(impl),
accumulator: impl,
checkpointer: checkpointer,
resource: c.Resource,
exporter: c.Exporter,
stopCh: nil,
clock: controllerTime.RealClock{},
@ -121,6 +125,12 @@ func (c *Controller) MeterProvider() metric.MeterProvider {
return c.provider
}
// Resource returns the *resource.Resource associated with this
// controller.
func (c *Controller) Resource() *resource.Resource {
return c.resource
}
// Start begins a ticker that periodically collects and exports
// metrics with the configured interval. This is required for calling
// a configured Exporter (see WithExporter) and is otherwise optional
@ -257,7 +267,7 @@ func (c *Controller) export(ctx context.Context) error {
defer cancel()
}
return c.exporter.Export(ctx, ckpt)
return c.exporter.Export(ctx, c.resource, ckpt)
}
// ForEach gives the caller read-locked access to the current