Skip to content

Feature: Automatically forward logs to OTEL #128

@jamesstocktonj1

Description

@jamesstocktonj1

Description

The default provider.New sets up the structured/text slog.Logger for use out of the box. These logs are printed to stderr and as per the host otel documentation these aren't exported to otel. The otel logger which is setup in the provider also doesn't forward them. I propose that if remote logs are enabled then the p.Logger should automatically forward them.

The library github.com/samber/slog-multi allows you to fanout to multiple slog.Handler. The code would look something like the following:

if hostData.OtelConfig.LogsEnabled() {
	// existing loggerProvider setup...
	logger = slog.New(slogmulti.Fanout(
		logger.Handler(),
		otelslog.NewHandler(
			"provider",
			otelslog.WithLoggerProvider(loggerProvider),
		),
	))
}

Would anyone have any objections to this or is it preferred for logs to be exported to otel manually?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions