Debian Codegraph @

scraper/xscraper/profiles.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package xscraper // import "go.opentelemetry.io/collector/scraper/xscraper"
5
6 import (
7 "context"
8
9 "go.opentelemetry.io/collector/component"
10 "go.opentelemetry.io/collector/pdata/pprofile"
11 "go.opentelemetry.io/collector/scraper"
12 )
13
14 // Profiles is the base interface for profiles scrapers.
15 type Profiles interface {
16 component.Component
17
18 // ScrapeProfiles is the base interface to indicate that how should profiles be scraped.
19 ScrapeProfiles(context.Context) (pprofile.Profiles, error)
20 }
21
22 // ScrapeProfilesFunc is a helper function.
23 type ScrapeProfilesFunc scraper.ScrapeFunc[pprofile.Profiles]
24
25 func (sf ScrapeProfilesFunc) ScrapeProfiles(ctx context.Context) (pprofile.Profiles, error) {
26 return sf(ctx)
27 }
28
29 type profiles struct {
30 baseScraper
31 ScrapeProfilesFunc
32 }
33
34 // NewProfiles creates a new Profiles scraper.
35 func NewProfiles(scrape ScrapeProfilesFunc, options ...Option) (Profiles, error) {
36 if scrape == nil {
37 return nil, errNilFunc
38 }
39 bs := &profiles{
40 baseScraper: newBaseScraper(options),
41 ScrapeProfilesFunc: scrape,
42 }
43 return bs, nil
44 }