Files
07f037e380 [xscraper] add Profiles support (#13915)
#### Description

Implement scraper for Profiles.

This will help implement receiver parts like
https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/42843.

---------

Signed-off-by: Florian Lehner <[email protected]>
Co-authored-by: Pablo Baeyens <[email protected]>
2025-11-19 13:18:45 +00:00

59 lines
1.3 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package xscraper // import "go.opentelemetry.io/collector/scraper/xscraper"
import (
"context"
"errors"
"go.opentelemetry.io/collector/component"
)
var errNilFunc = errors.New("nil scrape func")
// ScrapeFunc scrapes data.
type ScrapeFunc[T any] func(context.Context) (T, error)
// Option apply changes to internal options.
type Option interface {
apply(*baseScraper)
}
type scraperOptionFunc func(*baseScraper)
func (of scraperOptionFunc) apply(e *baseScraper) {
of(e)
}
// WithStart sets the function that will be called on startup.
func WithStart(start component.StartFunc) Option {
return scraperOptionFunc(func(o *baseScraper) {
o.StartFunc = start
})
}
// WithShutdown sets the function that will be called on shutdown.
func WithShutdown(shutdown component.ShutdownFunc) Option {
return scraperOptionFunc(func(o *baseScraper) {
o.ShutdownFunc = shutdown
})
}
type baseScraper struct {
component.StartFunc
component.ShutdownFunc
}
// newBaseScraper returns the internal settings starting from the default and applying all options.
func newBaseScraper(options []Option) baseScraper {
// Start from the default options:
bs := baseScraper{}
for _, op := range options {
op.apply(&bs)
}
return bs
}