From 90a9d1d93604fc22c7a7ee07e961d8bdb8f34599 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 19 Mar 2025 14:50:43 -0700 Subject: [PATCH] Do not inline `noopSpan.tracerProvider` (#6456) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the `noopSpan.tracerProvider` is inlined into `noopSpan.TracerProvider` for binaries built with standard tooling. This function is needed in the ELF file for auto-instrumentation. Ensure this, and the other required methods are always kept isolated. cc @open-telemetry/go-instrumentation-approvers --------- Co-authored-by: Robert PajÄ…k --- CHANGELOG.md | 1 + internal/global/trace.go | 6 ++++++ trace/noop.go | 2 ++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 609c68cfc..edc382117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,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) diff --git a/internal/global/trace.go b/internal/global/trace.go index 8982aa0dc..f7a58cad5 100644 --- a/internal/global/trace.go +++ b/internal/global/trace.go @@ -158,6 +158,12 @@ 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. +// +// "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) { // autoInstEnabled is passed to newSpan via the autoSpan parameter. This is // so the auto-instrumentation can define a uprobe for (*t).newSpan and be diff --git a/trace/noop.go b/trace/noop.go index c8b1ae5d6..0f56e4dbb 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()