Documentation ¶
Overview ¶
Example ¶
package main import ( "context" "github.com/kudarap/opentelemetry-logs-go" "github.com/kudarap/opentelemetry-logs-go/logs" sdk "github.com/kudarap/opentelemetry-logs-go/sdk/logs" "go.opentelemetry.io/otel/sdk/resource" semconv "go.opentelemetry.io/otel/semconv/v1.24.0" "log" "time" ) const ( instrumentationName = "github.com/instrumentron" instrumentationVersion = "v0.1.0" ) func newResource() *resource.Resource { return resource.NewWithAttributes( semconv.SchemaURL, semconv.ServiceName("otlplogs-example"), semconv.ServiceVersion("0.0.1"), semconv.HostName("host"), ) } func doSomething() { logger := otel.GetLoggerProvider().Logger( instrumentationName, logs.WithInstrumentationVersion(instrumentationVersion), logs.WithSchemaURL(semconv.SchemaURL), ) body := "My message" now := time.Now() sn := logs.INFO cfg := logs.LogRecordConfig{ Timestamp: &now, ObservedTimestamp: now, Body: &body, SeverityNumber: &sn, } logRecord := logs.NewLogRecord(cfg) logger.Emit(logRecord) } func installExportPipeline(ctx context.Context) (func(context.Context) error, error) { // New autoconfigured OTLP exporter exporter, _ := NewExporter(ctx) loggerProvider := sdk.NewLoggerProvider( sdk.WithBatcher(exporter), sdk.WithResource(newResource()), ) otel.SetLoggerProvider(loggerProvider) return loggerProvider.Shutdown, nil } func main() { { ctx := context.Background() // Registers a logger Provider globally. shutdown, err := installExportPipeline(ctx) if err != nil { log.Fatal(err) } doSomething() defer func() { if err := shutdown(ctx); err != nil { log.Fatal(err) } }() } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Start should establish connection(s) to endpoint(s). It is // called just once by the exporter, so the implementation // does not need to worry about idempotence and locking. Start(ctx context.Context) error // Stop should close the connections. The function is called // only once by the exporter, so the implementation does not // need to worry about idempotence, but it may be called // concurrently with UploadLogs, so proper // locking is required. The function serves as a // synchronization point - after the function returns, the // process of closing connections is assumed to be finished. Stop(ctx context.Context) error // UploadLogs should transform the passed logs to the wire // format and send it to the collector. May be called // concurrently. UploadLogs(ctx context.Context, protoLogs []*logspb.ResourceLogs) error }
type Exporter ¶
type Exporter struct {
// contains filtered or unexported fields
}
func New ¶
New creates new exporter with client Deprecated: Use NewExporter instead. Will be removed in v0.1.0
func NewExporter ¶
func NewExporter(ctx context.Context, options ...ExporterOption) (*Exporter, error)
NewExporter creates new Exporter
type ExporterConfig ¶
type ExporterConfig struct {
// contains filtered or unexported fields
}
func NewExporterConfig ¶
func NewExporterConfig(options ...ExporterOption) ExporterConfig
NewExporterConfig creates new configuration for exporter
type ExporterOption ¶
type ExporterOption interface {
// contains filtered or unexported methods
}
func WithClient ¶
func WithClient(client Client) ExporterOption
Click to show internal directories.
Click to hide internal directories.