From 1bcb778c28deecded2b3425d8991d8ec73987645 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 31 May 2024 03:37:38 -0700 Subject: [PATCH] Move `MonotonicEndTime` to only use (#5443) Have the code definition live next to its usage. Co-authored-by: Sam Xie --- sdk/internal/internal.go | 17 ----------------- sdk/trace/span.go | 13 +++++++++++-- 2 files changed, 11 insertions(+), 19 deletions(-) delete mode 100644 sdk/internal/internal.go diff --git a/sdk/internal/internal.go b/sdk/internal/internal.go deleted file mode 100644 index a990092f9d1..00000000000 --- a/sdk/internal/internal.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package internal // import "go.opentelemetry.io/otel/sdk/internal" - -import "time" - -// 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)) -} diff --git a/sdk/trace/span.go b/sdk/trace/span.go index 26b1a3943d6..0b09679bfe2 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -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" @@ -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. @@ -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