TracingContextFactory allocates when no tracer is configured
I maintainer di solito rispondono entro 1 giorno
@xirzec ci sta già lavorando.
Dal 16/8/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Summary
Azure::Core::Tracing::_internal::TracingContextFactory::CreateTracingContext allocates on the no-tracer path. Every call that receives a caller context without the factory performs two heap allocations, even when the application configured no tracing provider. A service that does not use the HTTP pipeline pays that cost for every top-level operation and gets nothing back.
Motivation
CreateTracingContext calls context.WithValue(TracingFactoryContextKey, this) at sdk/core/azure-core/src/tracing/tracing.cpp:66-68 before it tests HasTracer(), and Context::WithValue performs two make_shared calls at sdk/core/azure-core/inc/azure/core/context.hpp:289-293. The comment at tracing.cpp:61-64 justifies the unconditional injection by saying the factory also builds the User-Agent header. That justification is stale. At commit 99f45a5f1 RequestActivityPolicy read GetUserAgent() from the injected factory, but GetUserAgent no longer exists anywhere in sdk/core, and TelemetryPolicy now produces the header on its own at sdk/core/azure-core/src/http/telemetry_policy.cpp:16-21. The only remaining consumer of the injected factory is RequestActivityPolicy, which acts only when tracingFactory && tracingFactory->HasTracer() at sdk/core/azure-core/src/http/request_activity_policy.cpp:28, so a factory without a tracer has no observable effect. WithValue returns a child context and never changes the caller context, so two calls that share one caller context both miss the guard and both allocate. An AMQP service such as azure-messaging-eventhubs builds a fresh caller context for each operation, which measures at two allocations for every send and every receive.
Proposal
- Return
TracingContext{context, ServiceSpan{}}at the top ofCreateTracingContextinsdk/core/azure-core/src/tracing/tracing.cppwhenHasTracer()is false, and delete the deadelsebranch at lines 98-101. Copying the context copies oneshared_ptrand does not reach the heap. - Keep the guarded injection and the span creation unchanged for the tracer-configured path, so HTTP clients behave exactly as they do today.
- Replace the stale comment at
tracing.cpp:61-64with one that namesRequestActivityPolicyas the consumer and records thatTelemetryPolicyowns the User-Agent header. - Correct the
TelemetryPolicydoc comment atsdk/core/azure-core/inc/azure/core/http/policies/policy.hpp:546-550, which claims User-Agent generation moved intoRequestActivityPolicy. That merger was reverted, and the stale claim invites a future reader to restore the injection. - Add a test near
BasicServiceSpanTestsinsdk/core/azure-core/test/ut/service_tracing_test.cppthat makes sureCreateFromContextreturns null for a context built with no provider, and returns a factory withHasTracer()true when a provider is set. - Add a CHANGELOG entry under "Other Changes" recording that
CreateTracingContextno longer allocates when no tracer is configured.
Rejected alternatives. An opt-out constructor flag works, but it adds a data member to a class whose inline definition ships in a public header, and it forces every non-HTTP service to opt in by hand. Passing the factory to RequestActivityPolicy outside the context would let the injection be deleted for everyone, but the pipeline constructor carries no service name, which az.namespace needs, so it requires plumbing through every service that builds a pipeline. That route remains the right long-term direction if User-Agent duty ever returns to RequestActivityPolicy.
Validation
- Both symbols live in
Azure::Core::Tracing::_internal, and a repository-wide search forTracingFactoryContextKeyandCreateFromContextfinds one non-test consumer, so no public header changes and no API or ABI break. - Every existing
RequestActivityPolicytest configures a tracing provider, atsdk/core/azure-core/test/ut/request_activity_policy_test.cpp:161-246, so no current test pins the no-tracer injection.
- Lingua principale
- C++
- Stelle
- 206
- Fork
- 177
- Merge medio
- 2g 6h
- PR unite (30g)
- 35
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Azure/azure-sdk-for-cpp
-
bug EngSys
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Azure/azure-sdk-for-cpp#7362 ·
I maintainer di solito rispondono entro 1 giorno
-
Client needs-team-attention Service Attention Storage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Azure/azure-sdk-for-cpp#7347 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Client Event Hubs needs-team-attention Service Attention
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Azure/azure-sdk-for-cpp#7333 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Azure Storage STG105 Feature TestsForse già presa @Jinming-Hu l’ha presa 20 giorni fa. ApertaClient Storage
Azure/azure-sdk-for-cpp#7449 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Azure.Core bug test-enhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
Azure/azure-sdk-for-cpp#7401 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Azure/azure-sdk-for-cpp
Issue simili
-
[Bug] [Go] Ack returns nil when the server answers with a non-OK statusForse già presa @leizhiyuan l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
apache/rocketmq-clients#1465 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
KhronosGroup/Vulkan-Tutorial#534 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 2 giorni
-
bug IO
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
MrNeRF/LichtFeld-Studio#3824 ·
I maintainer di solito rispondono entro 1 giorno
-
pnnx: manual tanh GELU fusion loses the approximation modeForse già presa @ktz03 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Tencent/ncnn#7175 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno