log

package
v2.8.0-dev Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForceFlush

func ForceFlush(ctx context.Context) error

ForceFlush forces all pending log records to be exported immediately. This function is primarily useful for testing and ensuring logs are sent before critical operations. The logger provider continues accepting new logs after flushing.

If the provider was not initialized, this is a no-op. The flush operation will timeout after 5 seconds to avoid blocking indefinitely.

Example usage:

if err := log.ForceFlush(context.Background()); err != nil {
    log.Error("Failed to flush logs: %v", err)
}

func GetGlobalLoggerProvider

func GetGlobalLoggerProvider() otellog.LoggerProvider

GetGlobalLoggerProvider returns the global LoggerProvider instance if it has been initialized. Returns nil if InitGlobalLoggerProvider has not been called yet.

This LoggerProvider should be used by OTel log bridges and logging integrations to emit logs to the Datadog Agent via OTLP.

The returned LoggerProvider automatically bridges DD spans to OTel context for proper trace/span correlation.

func InitGlobalLoggerProvider

func InitGlobalLoggerProvider(ctx context.Context) error

InitGlobalLoggerProvider initializes a global OTel LoggerProvider configured with Datadog-specific defaults.

It creates: - A resource with Datadog and OTEL resource attributes (with DD precedence) - A BatchLogRecordProcessor configured with BLRP environment variables - An OTLP exporter (HTTP or gRPC) configured with DD agent endpoint resolution

The LoggerProvider can be accessed via GetGlobalLoggerProvider() and should be used by OTel log bridges and logging integrations.

This function is idempotent - calling it multiple times will return the same LoggerProvider instance. To create a new LoggerProvider, call ShutdownGlobalLoggerProvider first.

Returns an error if LoggerProvider creation fails.

func ShutdownGlobalLoggerProvider

func ShutdownGlobalLoggerProvider(ctx context.Context) error

ShutdownGlobalLoggerProvider shuts down the global LoggerProvider if it exists. This flushes any pending log records and cleans up resources.

This function is safe to call multiple times and is idempotent. After shutdown, InitGlobalLoggerProvider can be called again to create a new instance.

The ctx parameter can be used to set a deadline for the shutdown operation. If the context is canceled or times out, shutdown will abort but still mark the provider as shut down.

func Start

func Start(ctx context.Context) error

Start initializes the OTel LoggerProvider if DD_LOGS_OTEL_ENABLED=true. This function should be called during tracer initialization.

If the feature is not enabled, this function is a no-op. Returns an error if initialization fails when the feature is enabled.

func Stop

func Stop() error

Stop shuts down the OTel LoggerProvider if it was initialized. This function should be called during tracer shutdown.

It flushes any pending log records and cleans up resources. If the provider was not initialized, this is a no-op. The shutdown operation will timeout after 5 seconds to avoid blocking indefinitely.

Types

type LogsExportTelemetry

type LogsExportTelemetry struct {
	// contains filtered or unexported fields
}

LogsExportTelemetry provides telemetry metrics for OTLP logs export operations.

func NewLogsExportTelemetry

func NewLogsExportTelemetry(protocol, encoding string) *LogsExportTelemetry

NewLogsExportTelemetry creates a new LogsExportTelemetry for tracking log export operations. The protocol should be "http" or "grpc", and encoding should be "json" or "protobuf".

func (*LogsExportTelemetry) RecordLogRecords

func (t *LogsExportTelemetry) RecordLogRecords(count int)

RecordLogRecords records the number of log records exported.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL