mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add scraper for logs <!-- Issue number if applicable --> #### Link to tracking issue Relates to #11238 <!--Describe what testing was performed and which tests were added.--> #### Testing Added unit tests <!--Describe the documentation added.--> #### Documentation Added <!--Please delete paragraphs that you did not use before submitting.-->
45 lines
1012 B
Go
45 lines
1012 B
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package scraper // import "go.opentelemetry.io/collector/scraper"
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/collector/component"
|
|
"go.opentelemetry.io/collector/pdata/plog"
|
|
)
|
|
|
|
// Logs is the base interface for logs scrapers.
|
|
type Logs interface {
|
|
component.Component
|
|
|
|
// ScrapeLogs is the base interface to indicate that how should logs be scraped.
|
|
ScrapeLogs(context.Context) (plog.Logs, error)
|
|
}
|
|
|
|
// ScrapeLogsFunc is a helper function that is similar to Logs.ScrapeLogs.
|
|
type ScrapeLogsFunc ScrapeFunc[plog.Logs]
|
|
|
|
func (sf ScrapeLogsFunc) ScrapeLogs(ctx context.Context) (plog.Logs, error) {
|
|
return sf(ctx)
|
|
}
|
|
|
|
type logs struct {
|
|
baseScraper
|
|
ScrapeLogsFunc
|
|
}
|
|
|
|
// NewLogs creates a new Logs scraper.
|
|
func NewLogs(scrape ScrapeLogsFunc, options ...Option) (Logs, error) {
|
|
if scrape == nil {
|
|
return nil, errNilFunc
|
|
}
|
|
bs := &logs{
|
|
baseScraper: newBaseScraper(options),
|
|
ScrapeLogsFunc: scrape,
|
|
}
|
|
|
|
return bs, nil
|
|
}
|