Skip to content

Conversation

Horiodino
Copy link

@Horiodino Horiodino commented Sep 11, 2025

This PR adds self-observability metrics to the stdoutlog exporter, gated by the environment variable:

OTEL_GO_X_OBSERVABILITY=true

What's added

  • otel.sdk.exporter.log.inflight
  • otel.sdk.exporter.log.exported (success and error support)
  • otel.sdk.exporter.operation.duration

🔗 Related Issues & PRs

Copy link
Member

@flc1125 flc1125 left a comment

Choose a reason for hiding this comment

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

Review only the functional parts; the unit tests will be reviewed after the functional adjustments.


e.inst.inflightMetric.Add(ctx, count, e.inst.attrs...)

bufPtrAny := attrPool.Get()
Copy link
Member

Choose a reason for hiding this comment

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

CHANGELOG.md Outdated
### Added

- Add experimental self-observability log exporter metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`.
Check the `go.opentelemetry.io/otel/exporters/stdout/stdoutlog/internal/x` package documentation for more information.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Check the `go.opentelemetry.io/otel/exporters/stdout/stdoutlog/internal/x` package documentation for more information.
Check the `go.opentelemetry.io/otel/exporters/stdout/stdoutlog/internal/x` package documentation for more information. (#7351)

CHANGELOG.md Outdated

### Added

- Add experimental self-observability log exporter metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`.
Copy link
Member

Choose a reason for hiding this comment

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

Usually we place it at the very bottom of this small node.

@MrAlias MrAlias added this to the v1.40.0 milestone Sep 15, 2025
Copy link

codecov bot commented Sep 15, 2025

Codecov Report

❌ Patch coverage is 89.87342% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.5%. Comparing base (0db5ac7) to head (6eac6ed).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tdout/stdoutlog/internal/observ/instrumentation.go 88.6% 8 Missing and 4 partials ⚠️
exporters/stdout/stdoutlog/exporter.go 81.8% 3 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##            main   #7351    +/-   ##
======================================
  Coverage   85.5%   85.5%            
======================================
  Files        278     281     +3     
  Lines      24654   24808   +154     
======================================
+ Hits       21088   21224   +136     
- Misses      3187    3200    +13     
- Partials     379     384     +5     
Files with missing lines Coverage Δ
...rters/stdout/stdoutlog/internal/counter/counter.go 100.0% <100.0%> (ø)
exporters/stdout/stdoutlog/internal/x/x.go 100.0% <100.0%> (ø)
exporters/stdout/stdoutlog/record.go 97.4% <ø> (ø)
exporters/stdout/stdoutlog/exporter.go 88.2% <81.8%> (-2.7%) ⬇️
...tdout/stdoutlog/internal/observ/instrumentation.go 88.6% <88.6%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Please take a look at the project guidelines regarding observability. The check list for the issue this is resolving should all be checked and completed before this PR is ready to be reviewed.

CHANGELOG.md Outdated

### Added

- Add experimental self-observability log exporter metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Add experimental self-observability log exporter metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`.
- Add experimental observability for the log exporter in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do not use the term "self observability". It should just be "observability".

Copy link
Contributor

Choose a reason for hiding this comment

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

This has not been addressed.

Signed-off-by: Praful <holiodin@gmail.com>
Signed-off-by: Praful <holiodin@gmail.com>
…internal/x

Signed-off-by: Praful <holiodin@gmail.com>
Signed-off-by: Praful <holiodin@gmail.com>

follow existing convention for including experimental features in an internal/x

Signed-off-by: Praful <holiodin@gmail.com>
Signed-off-by: Praful <holiodin@gmail.com>
Signed-off-by: Praful <holiodin@gmail.com>

fix: resolve linter err

Signed-off-by: Praful <holiodin@gmail.com>
…servability

Signed-off-by: Praful <holiodin@gmail.com>

refactor: test case from TestSelfObservability to TestNewSelfObservability

Signed-off-by: Praful <holiodin@gmail.com>
…rvability

Signed-off-by: Praful <holiodin@gmail.com>
…contributing guidelines

Signed-off-by: Praful Khanduri <holiodin@gmail.com>

added chloggen

Signed-off-by: Praful Khanduri <holiodin@gmail.com>

fix: return err

Signed-off-by: Praful Khanduri <holiodin@gmail.com>
@Horiodino Horiodino force-pushed the stdoutlog_exporter_metrics branch from ada09f6 to 6eac6ed Compare September 27, 2025 15:31
Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution. Please see the instrumentation checklist and the project instrumentation guidelines. Please ensure that these things are followed and the PR is updated to address all the mentioned issues.

Comment on lines +21 to +24
// Version is the current version of this instrumentation.
//
// This matches the version of the exporter.
Version = internal.Version
Copy link
Contributor

Choose a reason for hiding this comment

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

This adds to the public API of the package, it should not be exported.

It does not seem needed either. Using just internal.Version should be adequate.


// otelComponentType is a name identifying the type of the OpenTelemetry component.
const (
otelComponentType = "go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be defined in observ not here. It is only used there and passed from here. This is an unneeded coupling.


// Export exports log records to writer.
func (e *Exporter) Export(ctx context.Context, records []log.Record) error {
if inst := e.instrumentation; inst != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just shorten the field name to inst if you want to do things like this.

Comment on lines +63 to +71
if inst := e.instrumentation; inst != nil {
done := inst.ExportLogs(ctx, len(records))
exported, err := e.exportRecords(ctx, records)
done(exported, err)
return err
}

_, err := e.exportRecords(ctx, records)
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be needed to be called in two different code paths. Use defer:

Suggested change
if inst := e.instrumentation; inst != nil {
done := inst.ExportLogs(ctx, len(records))
exported, err := e.exportRecords(ctx, records)
done(exported, err)
return err
}
_, err := e.exportRecords(ctx, records)
return err
var n int64
var err error
if inst := e.instrumentation; inst != nil {
done := inst.ExportLogs(ctx, len(records))
defer func() { done(n, err) }()
}
n, err = e.exportRecords(ctx, records)
return err

"go.opentelemetry.io/otel/exporters/stdout/stdoutlog/internal/counter"
"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/sdk/instrumentation"
sdkinstrumentation "go.opentelemetry.io/otel/sdk/instrumentation"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why rename the package import?

Comment on lines +822 to +836
var exportedMetric metricdata.Metrics
exportedInstrument := otelconv.SDKExporterLogExported{}
for _, m := range got.Metrics {
if m.Name == exportedInstrument.Name() {
exportedMetric = m
break
}
}
require.NotEmpty(t, exportedMetric, "exported metric not found")

data := exportedMetric.Data.(metricdata.Sum[int64])
require.Len(t, data.DataPoints, 1)

dataPoint := data.DataPoints[0]
assert.Equal(t, int64(2), dataPoint.Value)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an incomplete evaluation of what is expected. A full test needs to be done for this testing scenario.

// ExportLogs instruments the exporter Export method. It returns a callback that
// MUST be invoked when the export completes with the number of successfully
// exported records and the resulting error.
func (i *Instrumentation) ExportLogs(ctx context.Context, total int) ExportLogsDone {
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning ExportLogsDone will add an additional allocation.

Benchmarking should be done to evaluate switching to a solution similar to

func (i *Instrumentation) ExportSpans(ctx context.Context, nSpans int) ExportOp {

Copy link
Contributor

Choose a reason for hiding this comment

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

There are no tests or benchmarks for this instrumentation or package.

Copy link
Contributor

Choose a reason for hiding this comment

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

This has not been addressed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert these changes. They do not belong this PR.

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.

Logs SDK observability - stdoutlog exporter metrics
3 participants