Skip to content

Conversation

@vantaboard
Copy link

@vantaboard vantaboard commented Aug 28, 2025

This gives you the ability to send logs directly to the OpenTelemetry collector. Having traces and metrics go to the collector but not logs doesn't make sense to me. I could direct my stdout to a file but then I have to do additional parsing. I think it is a good idea to have this more natively part of clue.

As an aside though, do you think exporters should be more generic? Like making them a log option instead of an argument? Then you don't have to do a major version release every time you add a critical export.

Instead of

ctx := log.Context(context.Background())
traceExporter := tracestdout.New()
metricsExporter := metricstdout.New()
logsExporter = logsstdout.New()
cfg := clue.NewConfig(ctx, "service", "1.0.0", metricsExporter, traceExporter, logsExplorer)
clue.ConfigureOpenTelemetry(ctx, cfg)

you could do

ctx := log.Context(context.Background())
traceExporter := tracestdout.New()
metricsExporter := metricstdout.New()
logsExporter = logsstdout.New()
cfg := clue.NewConfig(
    ctx,
    "service",
    "1.0.0",
    log.WithMetricsExporter(metricsExporter),
    log.WithTraceExporter(traceExporter),
    log.WithLogsExporter(logsExplorer)
)
clue.ConfigureOpenTelemetry(ctx, cfg)

From

func NewConfig(
	ctx context.Context,
	svcName string,
	svcVersion string,
	metricExporter sdkmetric.Exporter,
	spanExporter sdktrace.SpanExporter,
	logExporter sdklog.Exporter,
	opts ...Option,
) (*Config, error) {

to

func NewConfig(
	ctx context.Context,
	svcName string,
	svcVersion string,
	opts ...Option,
) (*Config, error) {

Copy link
Member

@raphael raphael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! The reason clue isn't using the log provider today is that it did not exist at the time clue was written so this PR is very welcomed :)

I left one question below: just wanting to understand why the recursive guard is needed. Thank you!

log/log.go Outdated

// Send to OpenTelemetry if available and not already logging to OTEL
if l.otellog != nil && !l.otelLogging {
// Set recursion guard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is the guard needed? Seems like we are protecting against otel calling back clue below, what else could cause recursion?

Copy link
Member

@raphael raphael Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the linter is picking up an issue that might be good to resolve before we merge, we probably also should have a few tests for the new Otel logger backend, thank you!

@vantaboard
Copy link
Author

Hey, I went and added some additional fixes and adjustments. I don't think it is in a working state, but I wasn't able to test it. I am currently in the process of changing my logs over to slog.log instead of using clue as it provisions the same features and works better in terms of the standard library for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants