mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
#### 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]>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package xscraper // import "go.opentelemetry.io/collector/scraper/xscraper"
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/collector/component"
|
|
"go.opentelemetry.io/collector/pdata/pprofile"
|
|
"go.opentelemetry.io/collector/scraper"
|
|
)
|
|
|
|
// Profiles is the base interface for profiles scrapers.
|
|
type Profiles interface {
|
|
component.Component
|
|
|
|
// ScrapeProfiles is the base interface to indicate that how should profiles be scraped.
|
|
ScrapeProfiles(context.Context) (pprofile.Profiles, error)
|
|
}
|
|
|
|
// ScrapeProfilesFunc is a helper function.
|
|
type ScrapeProfilesFunc scraper.ScrapeFunc[pprofile.Profiles]
|
|
|
|
func (sf ScrapeProfilesFunc) ScrapeProfiles(ctx context.Context) (pprofile.Profiles, error) {
|
|
return sf(ctx)
|
|
}
|
|
|
|
type profiles struct {
|
|
baseScraper
|
|
ScrapeProfilesFunc
|
|
}
|
|
|
|
// NewProfiles creates a new Profiles scraper.
|
|
func NewProfiles(scrape ScrapeProfilesFunc, options ...Option) (Profiles, error) {
|
|
if scrape == nil {
|
|
return nil, errNilFunc
|
|
}
|
|
bs := &profiles{
|
|
baseScraper: newBaseScraper(options),
|
|
ScrapeProfilesFunc: scrape,
|
|
}
|
|
return bs, nil
|
|
}
|