Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
48b1568
copied code with minor modifications for docs and feature flag: OTEL_…
mahendrabishnoi2 Aug 4, 2025
c03b9f0
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Aug 7, 2025
4ddd0b3
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Aug 7, 2025
987b77e
added self-observability support to stdoutmetric exporter for below m…
mahendrabishnoi2 Aug 7, 2025
b4d2756
fixed broken link
mahendrabishnoi2 Aug 7, 2025
b7181a4
added changelog entry for self-observability support in stdoutmetric …
mahendrabishnoi2 Aug 7, 2025
c6f91ac
run `make precommit`
mahendrabishnoi2 Aug 7, 2025
a9ad0e2
fix a bug where attributes defined in ExporterMetrics are mutated
mahendrabishnoi2 Aug 9, 2025
7b1fb2d
test cases for ExporterMetrics
mahendrabishnoi2 Aug 9, 2025
ef4a629
test cases for stdoutmetric exporter
mahendrabishnoi2 Aug 9, 2025
51f2f2b
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Aug 9, 2025
38eb316
remove unused receiver to make linter (unused-receiver) happy
mahendrabishnoi2 Aug 9, 2025
b67b593
fix version
mahendrabishnoi2 Aug 9, 2025
ecbb337
fix version
mahendrabishnoi2 Aug 9, 2025
d6d0dd8
make stdoutMetricExporterComponentType as constant
mahendrabishnoi2 Aug 11, 2025
ee64105
Use defer to call trackExportFunc, Thanks to @flc1125
mahendrabishnoi2 Aug 11, 2025
ddfb3c3
duration -> durationSeconds
mahendrabishnoi2 Aug 11, 2025
db64dc0
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Aug 11, 2025
089252e
suppress linter as err is used in defer statement
mahendrabishnoi2 Aug 11, 2025
884ade7
instead of suppressing error, split if and err check on 2 lines
mahendrabishnoi2 Aug 11, 2025
32b6f61
Merge branch 'main' into stdoutmetric-auto-instrumentation
pellared Aug 12, 2025
460f303
addressed review comment: use named return to make code more readable
mahendrabishnoi2 Aug 16, 2025
9fea018
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Aug 16, 2025
a6f0637
name component similar to https://github.com/open-telemetry/opentelem…
mahendrabishnoi2 Aug 16, 2025
938cbb0
flatten the self-observability initialization and return the error to…
mahendrabishnoi2 Aug 16, 2025
b247192
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Aug 27, 2025
ee0328e
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Aug 28, 2025
4c357a9
address review comments
mahendrabishnoi2 Aug 28, 2025
2edfed9
address review comments
mahendrabishnoi2 Aug 28, 2025
18e0530
generate internal counter package so that it can be tested by resetti…
mahendrabishnoi2 Aug 28, 2025
9976cfc
review comments: improve tests, merge tests
mahendrabishnoi2 Aug 28, 2025
2f84c09
Run `make precommit`
mahendrabishnoi2 Aug 28, 2025
5dd37f2
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Oct 11, 2025
1f1eb84
run `make precommit`
mahendrabishnoi2 Oct 11, 2025
51e48eb
fix CHANGELOG.md
mahendrabishnoi2 Oct 11, 2025
7f64c38
refactoring to accommodate auto generation of x.go, replace usages of…
mahendrabishnoi2 Oct 11, 2025
c106988
benchmark for TrackExport
mahendrabishnoi2 Oct 12, 2025
49c5c9a
use precomputed set for happy path, still not optimal 5 allocs/op
mahendrabishnoi2 Oct 12, 2025
1643d6d
happy path allocs reduced to 1/op, will fix the ugly code later
mahendrabishnoi2 Oct 12, 2025
3903f85
minor refactor
mahendrabishnoi2 Oct 12, 2025
7ede990
move feature flag part to observ package.
mahendrabishnoi2 Oct 12, 2025
d03013d
fix failing test cases
mahendrabishnoi2 Oct 12, 2025
5742661
`make precommit`
mahendrabishnoi2 Oct 12, 2025
a723bfe
rename to Instrumentation
mahendrabishnoi2 Oct 12, 2025
3ab2586
fix CHANGELOG.md
mahendrabishnoi2 Oct 12, 2025
e34443f
rename self observability to observability
mahendrabishnoi2 Oct 12, 2025
69c1612
make constants unexported
mahendrabishnoi2 Oct 12, 2025
6233067
helper for component name
mahendrabishnoi2 Oct 12, 2025
909bc47
update docs
mahendrabishnoi2 Oct 12, 2025
ff814ca
update docs
mahendrabishnoi2 Oct 12, 2025
325bda9
linter happy
mahendrabishnoi2 Oct 12, 2025
c540ab0
Merge branch 'main' into stdoutmetric-auto-instrumentation
mahendrabishnoi2 Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add experimental observability metrics in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`. (#7353)
- Add experimental observability metrics in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`. (#7459)
- Add experimental observability metrics in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#7486)
- Add experimental observability metrics in `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric`. (#7492)

### Fixed

Expand Down
56 changes: 53 additions & 3 deletions exporters/stdout/stdoutmetric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"sync"
"sync/atomic"

"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric/internal/counter"
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric/internal/observ"
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
Expand All @@ -25,6 +27,8 @@ type exporter struct {
aggregationSelector metric.AggregationSelector

redactTimestamps bool

inst *observ.Instrumentation
}

// New returns a configured metric exporter.
Expand All @@ -39,7 +43,9 @@ func New(options ...Option) (metric.Exporter, error) {
redactTimestamps: cfg.redactTimestamps,
}
exp.encVal.Store(*cfg.encoder)
return exp, nil
var err error
exp.inst, err = observ.NewInstrumentation(counter.NextExporterID())
return exp, err
}

func (e *exporter) Temporality(k metric.InstrumentKind) metricdata.Temporality {
Expand All @@ -50,8 +56,11 @@ func (e *exporter) Aggregation(k metric.InstrumentKind) metric.Aggregation {
return e.aggregationSelector(k)
}

func (e *exporter) Export(ctx context.Context, data *metricdata.ResourceMetrics) error {
if err := ctx.Err(); err != nil {
func (e *exporter) Export(ctx context.Context, data *metricdata.ResourceMetrics) (err error) {
trackExportFunc := e.trackExport(ctx, countDataPoints(data))
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we can directly use the following approach without defining a function (even if not enabled, it still incurs overhead because it returns an empty anonymous function).

if e.inst != nil {
	// ...
}

defer func() { trackExportFunc(err) }()
err = ctx.Err()
if err != nil {
return err
}
if e.redactTimestamps {
Expand All @@ -63,6 +72,13 @@ func (e *exporter) Export(ctx context.Context, data *metricdata.ResourceMetrics)
return e.encVal.Load().(encoderHolder).Encode(data)
}

func (e *exporter) trackExport(ctx context.Context, count int64) func(err error) {
if e.inst == nil {
return func(error) {}
}
return e.inst.TrackExport(ctx, count)
}

func (*exporter) ForceFlush(context.Context) error {
// exporter holds no state, nothing to flush.
return nil
Expand Down Expand Up @@ -159,3 +175,37 @@ func redactDataPointTimestamps[T int64 | float64](sdp []metricdata.DataPoint[T])
}
return out
}

// countDataPoints counts the total number of data points in a ResourceMetrics.
func countDataPoints(rm *metricdata.ResourceMetrics) int64 {
if rm == nil {
return 0
}

var total int64
for _, sm := range rm.ScopeMetrics {
for _, m := range sm.Metrics {
switch data := m.Data.(type) {
case metricdata.Gauge[int64]:
total += int64(len(data.DataPoints))
case metricdata.Gauge[float64]:
total += int64(len(data.DataPoints))
case metricdata.Sum[int64]:
total += int64(len(data.DataPoints))
case metricdata.Sum[float64]:
total += int64(len(data.DataPoints))
case metricdata.Histogram[int64]:
total += int64(len(data.DataPoints))
case metricdata.Histogram[float64]:
total += int64(len(data.DataPoints))
case metricdata.ExponentialHistogram[int64]:
total += int64(len(data.DataPoints))
case metricdata.ExponentialHistogram[float64]:
total += int64(len(data.DataPoints))
case metricdata.Summary:
total += int64(len(data.DataPoints))
}
}
}
return total
}
Loading