-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add instrumentation for the "go.opentelemetry.io/otel/trace".nonRecordingSpan #974
Comments
The span embedded within a context will be from `auto/sdk`. This means that open-telemetry#974 is resolved by this change.
* Enable auto/sdk for the OTel global probe Set the auto/sdk flag in the global API to true when newSpan is called. * Update the otelglobal e2e test Verify the auto/sdk probe is being used. * Add a changelog entry * Unload the newSpan probe after first call * Update internal/pkg/instrumentation/bpf/go.opentelemetry.io/otel/traceglobal/probe.go * Add package constraints to otelglobal uprobes * Remove converter.uprobeNewStartMu * Test SpanFromContext is also supported The span embedded within a context will be from `auto/sdk`. This means that #974 is resolved by this change.
This was only partially resolved by #1405. If a global span is already active in the context this will work, as demonstrated in #1405. However, if there is no active span a no-op span is still created and is not instrumented. We need to provide the same enablement logic as the global API for the |
My initial idea was to update the Similar to open-telemetry/opentelemetry-go#5920 we could call a private method with a --- a/trace/noop.go
+++ b/trace/noop.go
@@ -6,6 +6,7 @@ package trace // import "go.opentelemetry.io/otel/trace"
import (
"context"
+ "go.opentelemetry.io/auto/sdk"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace/embedded"
@@ -82,4 +83,22 @@ func (noopSpan) AddLink(Link) {}
func (noopSpan) SetName(string) {}
// TracerProvider returns a no-op TracerProvider.
-func (noopSpan) TracerProvider() TracerProvider { return noopTracerProvider{} }
+func (s noopSpan) TracerProvider() TracerProvider {
+ return s.tracerProvider(autoInstEnabled)
+}
+
+// autoInstEnabled defines if the auto-instrumentation SDK is enabled.
+//
+// The auto-instrumentation is expected to overwrite this value to true when it
+// attaches to the process.
+var autoInstEnabled = new(bool)
+
+// tracerProvider return a noopTracerProvider if autoEnabled is false,
+// otherwise it will return a TracerProvider from the sdk package used in
+// auto-instrumentation.
+func (noopSpan) tracerProvider(autoEnabled *bool) TracerProvider {
+ if *autoEnabled {
+ return sdk.TracerProvider()
+ }
+ return noopTracerProvider{}
+} This will not work because it will create an import cycle. |
copying the |
#6203) This copes the `go.opentelemetry.io/auto/sdk` package into the `go.opentelemetry.io/otel/trace` package. This is done to avoid package import cycles and still provide an auto-instrumentable SDK (see open-telemetry/opentelemetry-go-instrumentation#974). ## Overview of changes The code copied is updated with the following changes. The over-all goal is to ensure none of this is exported and follows the `auto/sdk` as close as possible to help maintenance. ### `trace/auto.go` Consolidation of the following into a single file: - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/tracer_provider.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/tracer.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/span.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/limit.go Has the following changes: - `func TracerProvider()` renamed to `newAutoTracerProvider` - `type tracerProvider struct` renamed to `autoTracerProvider` - `type tracer struct` renamed to `autoTracer` - `type span struct` renamed to `autoSpan` - Lint issues addressed based on this repositories configuration (these changes are being back-ported upstream) ### `trace/auto_test.go` Consolidation of the following into a single file: - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/tracer_provider_test.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/tracer_test.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/span_test.go - https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/limit_test.go Has the following changes: - Renames in `trace/auto.go` are applied here - Lint issues addressed based on this repositories configuration (these changes are being back-ported upstream) ### `trace/internal/telemetry` Copied from https://github.com/open-telemetry/opentelemetry-go-instrumentation/tree/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/internal/telemetry - Pacakge vanity URLs added - Lint issues addressed based on this repositories configuration (these changes are being back-ported upstream) - Use of the package name has been updated #### `trace/internal/telemetry/test` Copied from https://github.com/open-telemetry/opentelemetry-go-instrumentation/tree/aea085dd2a3640630ac07a2187cbda9d15d2dd00/sdk/internal/telemetry/test - Module name updated - Documentation updated with new package name - Testing values updated with new package name --------- Co-authored-by: Ron Federman <[email protected]>
open-telemetry/opentelemetry-go#6203 has merged. We can no instrument that copy of the SDK to support this. |
Blocked by either a release of opentelemetry-go or the resolution of #1753. Currently, when trying to test the added probe the comparison of |
A common instrumentation pattern for tracing is to return the the
TracerProvider
from the span held in a context:When using the instrumentation of the global trace API, this span will not be recorded.
Describe the solution you'd like
The span created in this above code should be captured by auto-instrumentation. Meaning the
nonRecordingSpan
should be instrumented.The text was updated successfully, but these errors were encountered: