Skip to content

Commit

Permalink
Move MonotonicEndTime to only use (#5443)
Browse files Browse the repository at this point in the history
Have the code definition live next to its usage.

Co-authored-by: Sam Xie <sam@samxie.me>
  • Loading branch information
MrAlias and XSAM committed May 31, 2024
1 parent 91a8c5f commit 1bcb778
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
17 changes: 0 additions & 17 deletions sdk/internal/internal.go

This file was deleted.

13 changes: 11 additions & 2 deletions sdk/trace/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/internal"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.25.0"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -385,7 +384,7 @@ func (s *recordingSpan) End(options ...trace.SpanEndOption) {

// Store the end time as soon as possible to avoid artificially increasing
// the span's duration in case some operation below takes a while.
et := internal.MonotonicEndTime(s.startTime)
et := monotonicEndTime(s.startTime)

// Do relative expensive check now that we have an end time and see if we
// need to do any more processing.
Expand Down Expand Up @@ -436,6 +435,16 @@ func (s *recordingSpan) End(options ...trace.SpanEndOption) {
}
}

// monotonicEndTime returns the end time at present but offset from start,
// monotonically.
//
// The monotonic clock is used in subtractions hence the duration since start
// added back to start gives end as a monotonic time. See
// https://golang.org/pkg/time/#hdr-Monotonic_Clocks
func monotonicEndTime(start time.Time) time.Time {
return start.Add(time.Since(start))
}

// RecordError will record err as a span event for this span. An additional call to
// SetStatus is required if the Status of the Span should be set to Error, this method
// does not change the Span status. If this span is not being recorded or err is nil
Expand Down

0 comments on commit 1bcb778

Please sign in to comment.