From 0072508feb051d8f234fa2f36fbe7663afcb4906 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 17 Mar 2025 11:29:10 -0700 Subject: [PATCH 1/5] Do not inline noopSpan.tracerProvider The function is needed in the ELF file for auto-instrumentation. --- trace/noop.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/trace/noop.go b/trace/noop.go index c8b1ae5d67e..0f56e4dbb34 100644 --- a/trace/noop.go +++ b/trace/noop.go @@ -95,6 +95,8 @@ 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. +// +//go:noinline func (noopSpan) tracerProvider(autoEnabled *bool) TracerProvider { if *autoEnabled { return newAutoTracerProvider() From 58e5128698cb087a7d1f78053a04c1a2762470d5 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 17 Mar 2025 11:44:47 -0700 Subject: [PATCH 2/5] Add a changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b80fe0ec96..b00b6f72b79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixes - Stop percent encoding header environment variables in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#6392) +- Ensure the `noopSpan.tracerProvider` method is not inlined in `go.opentelemetry.io/otel/trace` so the `go.opentelemetry.io/auto` instrumentation can instrument non-recording spans. (#6456) From 237fde4fee84ef18f090ca5d5b2091c7117e4811 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 17 Mar 2025 11:48:40 -0700 Subject: [PATCH 3/5] Add noinline to global tracer.newSpan --- internal/global/trace.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/global/trace.go b/internal/global/trace.go index 8982aa0dc56..59658dc014a 100644 --- a/internal/global/trace.go +++ b/internal/global/trace.go @@ -158,6 +158,14 @@ func (t *tracer) Start(ctx context.Context, name string, opts ...trace.SpanStart // a nonRecordingSpan by default. var autoInstEnabled = new(bool) +// newSpan is called by tracer.Start so auto-instrumentation can attach an eBPF +// uprobe to this code. +// +// Strictly speaking, the following "noinline" flag is not needed, the method's +// complexity prevents it being inlined. This ensure that is the case going +// forward by making the restriction explicit. +// +//go:noinline func (t *tracer) newSpan(ctx context.Context, autoSpan *bool, name string, opts []trace.SpanStartOption) (context.Context, trace.Span) { // autoInstEnabled is passed to newSpan via the autoSpan parameter. This is // so the auto-instrumentation can define a uprobe for (*t).newSpan and be From 5132261762f1ac262b646807e95c3552c093175b Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 17 Mar 2025 14:10:06 -0700 Subject: [PATCH 4/5] Update internal/global/trace.go --- internal/global/trace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/global/trace.go b/internal/global/trace.go index 59658dc014a..3fd888c42a0 100644 --- a/internal/global/trace.go +++ b/internal/global/trace.go @@ -162,7 +162,7 @@ var autoInstEnabled = new(bool) // uprobe to this code. // // Strictly speaking, the following "noinline" flag is not needed, the method's -// complexity prevents it being inlined. This ensure that is the case going +// complexity prevents it being inlined. This ensures that is the case going // forward by making the restriction explicit. // //go:noinline From bc061c55ca8e49980c7ef661b6f0cd468125af31 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Tue, 18 Mar 2025 12:09:46 -0700 Subject: [PATCH 5/5] Update internal/global/trace.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert PajÄ…k --- internal/global/trace.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/global/trace.go b/internal/global/trace.go index 3fd888c42a0..f7a58cad576 100644 --- a/internal/global/trace.go +++ b/internal/global/trace.go @@ -161,9 +161,7 @@ var autoInstEnabled = new(bool) // newSpan is called by tracer.Start so auto-instrumentation can attach an eBPF // uprobe to this code. // -// Strictly speaking, the following "noinline" flag is not needed, the method's -// complexity prevents it being inlined. This ensures that is the case going -// forward by making the restriction explicit. +// "noinline" pragma prevents the method from ever being inlined. // //go:noinline func (t *tracer) newSpan(ctx context.Context, autoSpan *bool, name string, opts []trace.SpanStartOption) (context.Context, trace.Span) {