diff --git a/BUILD b/BUILD index 2bc4c344fc7..612c1cfae46 100644 --- a/BUILD +++ b/BUILD @@ -1341,7 +1341,7 @@ grpc_cc_library( "grpc_base", "grpc_public_hdrs", "grpc_trace", - "legacy_context", + "//src/core:arena", ], ) diff --git a/src/core/ext/filters/census/grpc_context.cc b/src/core/ext/filters/census/grpc_context.cc index a26ccf05898..e2affd09a4b 100644 --- a/src/core/ext/filters/census/grpc_context.cc +++ b/src/core/ext/filters/census/grpc_context.cc @@ -21,7 +21,6 @@ #include #include -#include "src/core/lib/channel/context.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" @@ -30,12 +29,11 @@ void grpc_census_call_set_context(grpc_call* call, census_context* context) { GRPC_API_TRACE("grpc_census_call_set_context(call=%p, census_context=%p)", 2, (call, context)); if (context != nullptr) { - grpc_call_context_set(call, GRPC_CONTEXT_TRACING, context, nullptr); + grpc_call_get_arena(call)->SetContext(context); } } census_context* grpc_census_call_get_context(grpc_call* call) { GRPC_API_TRACE("grpc_census_call_get_context(call=%p)", 1, (call)); - return static_cast( - grpc_call_context_get(call, GRPC_CONTEXT_TRACING)); + return grpc_call_get_arena(call)->GetContext(); } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.h b/src/core/ext/transport/chttp2/transport/chttp2_transport.h index a98381b489d..884fe64efa9 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.h +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.h @@ -83,7 +83,7 @@ void TestOnlyGlobalHttp2TransportDisableTransientFailureStateNotification( typedef void (*WriteTimestampsCallback)(void*, Timestamps*, grpc_error_handle error); -typedef void* (*CopyContextFn)(void*); +typedef void* (*CopyContextFn)(grpc_core::Arena*); void GrpcHttp2SetWriteTimestampsCallback(WriteTimestampsCallback fn); void GrpcHttp2SetCopyContextFn(CopyContextFn fn); diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index a40d7c54359..f15c391b831 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -682,7 +682,7 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write( grpc_core::GrpcHttp2GetCopyContextFn(); if (copy_context_fn != nullptr && grpc_core::GrpcHttp2GetWriteTimestampsCallback() != nullptr) { - t->context_list->emplace_back(copy_context_fn(s->context), + t->context_list->emplace_back(copy_context_fn(s->arena), outbuf_relative_start_pos, num_stream_bytes, s->byte_counter, s->write_counter - 1, s->tcp_tracer); diff --git a/src/core/lib/channel/context.h b/src/core/lib/channel/context.h index 100f3927def..632c6b5ce12 100644 --- a/src/core/lib/channel/context.h +++ b/src/core/lib/channel/context.h @@ -32,9 +32,6 @@ typedef enum { /// grpc_call* associated with this context. GRPC_CONTEXT_CALL = 0, - /// Value is a \a census_context. - GRPC_CONTEXT_TRACING, - /// Holds a pointer to ServiceConfigCallData associated with this call. GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA, diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index b793bba7df9..8c8bc45d385 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -161,8 +161,8 @@ absl::Status Call::InitParent(Call* parent, uint32_t propagation_mask) { "Census tracing propagation requested without Census context " "propagation"); } - ContextSet(GRPC_CONTEXT_TRACING, parent->ContextGet(GRPC_CONTEXT_TRACING), - nullptr); + arena()->SetContext( + parent->arena()->GetContext()); } else if (propagation_mask & GRPC_PROPAGATE_CENSUS_STATS_CONTEXT) { return absl::UnknownError( "Census context propagation requested without Census tracing " diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 0d557629388..917881f00ed 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -78,6 +78,11 @@ typedef struct grpc_call_create_args { namespace grpc_core { +template <> +struct ArenaContextType { + static void Destroy(census_context*) {} +}; + class Call : public CppImplOf, public grpc_event_engine::experimental::EventEngine:: Closure /* for deadlines */ { diff --git a/src/cpp/ext/filters/census/client_filter.cc b/src/cpp/ext/filters/census/client_filter.cc index 4733040f152..52465fdaf30 100644 --- a/src/cpp/ext/filters/census/client_filter.cc +++ b/src/cpp/ext/filters/census/client_filter.cc @@ -312,8 +312,8 @@ OpenCensusCallTracer::OpenCensusCallTracer( method_(GetMethod(path_)), arena_(arena), tracing_enabled_(tracing_enabled) { - auto* parent_context = reinterpret_cast( - call_context_[GRPC_CONTEXT_TRACING].value); + auto* parent_context = + reinterpret_cast(arena->GetContext()); GenerateClientContext(tracing_enabled_ ? absl::StrCat("Sent.", method_) : "", &context_, (parent_context == nullptr) ? nullptr : parent_context); diff --git a/src/cpp/ext/filters/census/server_call_tracer.cc b/src/cpp/ext/filters/census/server_call_tracer.cc index e0852065320..24c6e80fb98 100644 --- a/src/cpp/ext/filters/census/server_call_tracer.cc +++ b/src/cpp/ext/filters/census/server_call_tracer.cc @@ -40,16 +40,16 @@ #include "opencensus/trace/span_id.h" #include "opencensus/trace/trace_id.h" +#include #include #include -#include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/channel/context.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/promise/context.h" #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/slice/slice.h" #include "src/core/lib/slice/slice_buffer.h" +#include "src/core/lib/surface/call.h" #include "src/core/lib/transport/metadata_batch.h" #include "src/core/telemetry/call_tracer.h" #include "src/core/telemetry/tcp_tracer.h" @@ -206,8 +206,8 @@ void OpenCensusServerCallTracer::RecordReceivedInitialMetadata( tracing_enabled ? sml.tracing_slice.as_string_view() : "", absl::StrCat("Recv.", method_), &context_); if (tracing_enabled) { - auto* call_context = grpc_core::GetContext(); - call_context[GRPC_CONTEXT_TRACING].value = &context_; + grpc_core::SetContext( + reinterpret_cast(&context_)); } if (OpenCensusStatsEnabled()) { std::vector> tags =