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
Deprecate Library and move all uses to Scope (#2977)
* Deprecate Library and move all uses to Scope * Add PR number to changelog * Don't change signatures in stable modules * Revert some changes * Rename internal struct names * A bit more renaming * Update sdk/trace/span.go Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Update based on feedback * Revert change Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
This commit is contained in:
@ -59,7 +59,7 @@ var ErrControllerStarted = fmt.Errorf("controller already started")
|
||||
type Controller struct {
|
||||
// lock synchronizes Start() and Stop().
|
||||
lock sync.Mutex
|
||||
libraries sync.Map
|
||||
scopes sync.Map
|
||||
checkpointerFactory export.CheckpointerFactory
|
||||
|
||||
resource *resource.Resource
|
||||
@ -85,21 +85,21 @@ var _ metric.MeterProvider = &Controller{}
|
||||
// with opts.
|
||||
func (c *Controller) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
|
||||
cfg := metric.NewMeterConfig(opts...)
|
||||
library := instrumentation.Library{
|
||||
scope := instrumentation.Scope{
|
||||
Name: instrumentationName,
|
||||
Version: cfg.InstrumentationVersion(),
|
||||
SchemaURL: cfg.SchemaURL(),
|
||||
}
|
||||
|
||||
m, ok := c.libraries.Load(library)
|
||||
m, ok := c.scopes.Load(scope)
|
||||
if !ok {
|
||||
checkpointer := c.checkpointerFactory.NewCheckpointer()
|
||||
m, _ = c.libraries.LoadOrStore(
|
||||
library,
|
||||
m, _ = c.scopes.LoadOrStore(
|
||||
scope,
|
||||
registry.NewUniqueInstrumentMeterImpl(&accumulatorCheckpointer{
|
||||
Accumulator: sdk.NewAccumulator(checkpointer),
|
||||
checkpointer: checkpointer,
|
||||
library: library,
|
||||
scope: scope,
|
||||
}))
|
||||
}
|
||||
return sdkapi.WrapMeterImpl(m.(*registry.UniqueInstrumentMeterImpl))
|
||||
@ -108,7 +108,7 @@ func (c *Controller) Meter(instrumentationName string, opts ...metric.MeterOptio
|
||||
type accumulatorCheckpointer struct {
|
||||
*sdk.Accumulator
|
||||
checkpointer export.Checkpointer
|
||||
library instrumentation.Library
|
||||
scope instrumentation.Scope
|
||||
}
|
||||
|
||||
var _ sdkapi.MeterImpl = &accumulatorCheckpointer{}
|
||||
@ -248,7 +248,7 @@ func (c *Controller) collect(ctx context.Context) error {
|
||||
// registered to this controller. This briefly locks the controller.
|
||||
func (c *Controller) accumulatorList() []*accumulatorCheckpointer {
|
||||
var r []*accumulatorCheckpointer
|
||||
c.libraries.Range(func(key, value interface{}) bool {
|
||||
c.scopes.Range(func(key, value interface{}) bool {
|
||||
acc, ok := value.(*registry.UniqueInstrumentMeterImpl).MeterImpl().(*accumulatorCheckpointer)
|
||||
if ok {
|
||||
r = append(r, acc)
|
||||
@ -272,7 +272,7 @@ func (c *Controller) checkpoint(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// checkpointSingleAccumulator checkpoints a single instrumentation
|
||||
// library's accumulator, which involves calling
|
||||
// scope's accumulator, which involves calling
|
||||
// checkpointer.StartCollection, accumulator.Collect, and
|
||||
// checkpointer.FinishCollection in sequence.
|
||||
func (c *Controller) checkpointSingleAccumulator(ctx context.Context, ac *accumulatorCheckpointer) error {
|
||||
@ -330,7 +330,7 @@ func (c *Controller) ForEach(readerFunc func(l instrumentation.Library, r export
|
||||
if err := func() error {
|
||||
reader.RLock()
|
||||
defer reader.RUnlock()
|
||||
return readerFunc(acPair.library, reader)
|
||||
return readerFunc(acPair.scope, reader)
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func getMap(t *testing.T, cont *controller.Controller) map[string]float64 {
|
||||
out := processortest.NewOutput(attribute.DefaultEncoder())
|
||||
|
||||
require.NoError(t, cont.ForEach(
|
||||
func(_ instrumentation.Library, reader export.Reader) error {
|
||||
func(_ instrumentation.Scope, reader export.Reader) error {
|
||||
return reader.ForEach(
|
||||
aggregation.CumulativeTemporalitySelector(),
|
||||
func(record export.Record) error {
|
||||
|
Reference in New Issue
Block a user