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