-
Notifications
You must be signed in to change notification settings - Fork 1.2k
sdk/trace: self-observability: span metrics #7027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
3eeba4c
add docs
pellared 5fe199b
Refine docs
pellared 2212cb2
Merge branch 'main' into span-metrics
pellared 16df7b8
Move experimental docs to x/internal
pellared e6a3029
improve docs
pellared 45aaace
update header
pellared 7c1ea5c
fix link
pellared 547a989
draft implementation
pellared bb6b8f8
add TestSelfObservabilty and fix implementation
pellared 2fd1368
Add attributes
pellared 25894d6
Add changelog entry
pellared 418297e
lint
pellared 6b33d72
Update TODO comments
pellared d9105c0
Merge branch 'main' into span-metrics
pellared 3d132c7
go mod tidy
pellared 713a3e7
Bump to semconv/v1.36.0
pellared 8cd9767
refactor initSelfObservability
pellared 6304e1d
refactor attr creation
pellared 3fa8aa5
add otel.span.parent.origin attribute
pellared 455060a
Add test cases
pellared 89d3a8d
refactor test
pellared b9d533a
Add RemoteParentSpan case
pellared 21735b7
Add LocalParentSpan test case
pellared 9975391
tidy tests
pellared ab3e2eb
Add OnlyRecordingSpan test case
pellared e729681
refactor TestRecordOnlySampler
pellared c40a561
Redo the docs
pellared 24b4f8e
nolint
pellared 90885b9
Merge branch 'main' into span-metrics
pellared f3740e6
markdownlint fix
pellared 4b37175
Merge branch 'main' into span-metrics
pellared fcef2ac
Merge branch 'main' into span-metrics
pellared 76001a3
Merge branch 'main' into span-metrics
pellared 5e44856
Update sdk/trace/internal/x/README.md
pellared afee3cc
Merge branch 'main' into span-metrics
pellared ad13ce9
refactor: reuse x.SelfObservability
pellared File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Experimental Features | ||
|
|
||
| The metric SDK contains features that have not yet stabilized in the OpenTelemetry specification. | ||
| These features are added to the OpenTelemetry Go metric SDK prior to stabilization in the specification so that users can start experimenting with them and provide feedback. | ||
|
|
||
| These feature may change in backwards incompatible ways as feedback is applied. | ||
| See the [Compatibility and Stability](#compatibility-and-stability) section for more information. | ||
|
|
||
| ## Features | ||
|
|
||
| - [Self-Observability](#self-observability) | ||
|
|
||
| ### Self-Observability | ||
|
|
||
| The SDK provides a self-observability feature that allows you to monitor the SDK itself. | ||
|
|
||
| To opt-in, set the environment variable `OTEL_GO_X_SELF_OBSERVABILITY` to `true`. | ||
|
|
||
| When enabled, the SDK will create the following metrics using the global `MeterProvider`: | ||
|
|
||
| - `otel.sdk.span.live` | ||
| - `otel.sdk.span.started` | ||
|
|
||
| Please see the [Semantic conventions for OpenTelemetry SDK metrics] documentation for more details on these metrics. | ||
|
|
||
| [Semantic conventions for OpenTelemetry SDK metrics]: https://github.com/open-telemetry/semantic-conventions/blob/v1.36.0/docs/otel/sdk-metrics.md | ||
|
|
||
| ## Compatibility and Stability | ||
|
|
||
| Experimental features do not fall within the scope of the OpenTelemetry Go versioning and stability [policy](../../../../VERSIONING.md). | ||
| These features may be removed or modified in successive version releases, including patch versions. | ||
|
|
||
| When an experimental feature is promoted to a stable feature, a migration path will be included in the changelog entry of the release. | ||
| There is no guarantee that any environment variable feature flags that enabled the experimental feature will be supported by the stable version. | ||
| If they are supported, they may be accompanied with a deprecation notice stating a timeline for the removal of that support. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Package x documents experimental features for [go.opentelemetry.io/otel/sdk/trace]. | ||
| package x // import "go.opentelemetry.io/otel/sdk/trace/internal/x" | ||
|
|
||
| import ( | ||
| "os" | ||
| "strings" | ||
| ) | ||
|
|
||
| // SelfObservability is an experimental feature flag that determines if SDK | ||
| // self-observability metrics are enabled. | ||
| // | ||
| // To enable this feature set the OTEL_GO_X_SELF_OBSERVABILITY environment variable | ||
| // to the case-insensitive string value of "true" (i.e. "True" and "TRUE" | ||
| // will also enable this). | ||
| var SelfObservability = newFeature("SELF_OBSERVABILITY", func(v string) (string, bool) { | ||
| if strings.ToLower(v) == "true" { | ||
| return v, true | ||
| } | ||
| return "", false | ||
| }) | ||
|
|
||
| // Feature is an experimental feature control flag. It provides a uniform way | ||
| // to interact with these feature flags and parse their values. | ||
| type Feature[T any] struct { | ||
| key string | ||
| parse func(v string) (T, bool) | ||
| } | ||
|
|
||
| func newFeature[T any](suffix string, parse func(string) (T, bool)) Feature[T] { | ||
| const envKeyRoot = "OTEL_GO_X_" | ||
| return Feature[T]{ | ||
| key: envKeyRoot + suffix, | ||
| parse: parse, | ||
| } | ||
| } | ||
|
|
||
| // Key returns the environment variable key that needs to be set to enable the | ||
| // feature. | ||
| func (f Feature[T]) Key() string { return f.key } | ||
|
|
||
| // Lookup returns the user configured value for the feature and true if the | ||
| // user has enabled the feature. Otherwise, if the feature is not enabled, a | ||
| // zero-value and false are returned. | ||
| func (f Feature[T]) Lookup() (v T, ok bool) { | ||
| // https://github.com/open-telemetry/opentelemetry-specification/blob/62effed618589a0bec416a87e559c0a9d96289bb/specification/configuration/sdk-environment-variables.md#parsing-empty-value | ||
| // | ||
| // > The SDK MUST interpret an empty value of an environment variable the | ||
| // > same way as when the variable is unset. | ||
| vRaw := os.Getenv(f.key) | ||
| if vRaw == "" { | ||
| return v, ok | ||
| } | ||
| return f.parse(vRaw) | ||
| } | ||
|
|
||
| // Enabled returns if the feature is enabled. | ||
| func (f Feature[T]) Enabled() bool { | ||
| _, ok := f.Lookup() | ||
| return ok | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package x | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSelfObservability(t *testing.T) { | ||
| const key = "OTEL_GO_X_SELF_OBSERVABILITY" | ||
| require.Equal(t, key, SelfObservability.Key()) | ||
|
|
||
| t.Run("100", run(setenv(key, "100"), assertDisabled(SelfObservability))) | ||
| t.Run("true", run(setenv(key, "true"), assertEnabled(SelfObservability, "true"))) | ||
| t.Run("True", run(setenv(key, "True"), assertEnabled(SelfObservability, "True"))) | ||
| t.Run("false", run(setenv(key, "false"), assertDisabled(SelfObservability))) | ||
| t.Run("empty", run(assertDisabled(SelfObservability))) | ||
| } | ||
|
|
||
| func run(steps ...func(*testing.T)) func(*testing.T) { | ||
| return func(t *testing.T) { | ||
| t.Helper() | ||
| for _, step := range steps { | ||
| step(t) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func setenv(k, v string) func(t *testing.T) { //nolint:unparam // This is a reusable test utility function. | ||
| return func(t *testing.T) { t.Setenv(k, v) } | ||
| } | ||
|
|
||
| func assertEnabled[T any](f Feature[T], want T) func(*testing.T) { | ||
| return func(t *testing.T) { | ||
| t.Helper() | ||
| assert.True(t, f.Enabled(), "not enabled") | ||
|
|
||
| v, ok := f.Lookup() | ||
| assert.True(t, ok, "Lookup state") | ||
| assert.Equal(t, want, v, "Lookup value") | ||
| } | ||
| } | ||
|
|
||
| func assertDisabled[T any](f Feature[T]) func(*testing.T) { | ||
| var zero T | ||
| return func(t *testing.T) { | ||
| t.Helper() | ||
|
|
||
| assert.False(t, f.Enabled(), "enabled") | ||
|
|
||
| v, ok := f.Lookup() | ||
| assert.False(t, ok, "Lookup state") | ||
| assert.Equal(t, zero, v, "Lookup value") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.