pub struct RequestContext { /* private fields */ }Expand description
Metadata of one invocation.
The value is immutable and cheap to clone. Its Debug output contains header names
but no header values and no token.
Implementations§
Source§impl RequestContext
impl RequestContext
Sourcepub fn builder(session_id: impl Into<String>) -> RequestContextBuilder
pub fn builder(session_id: impl Into<String>) -> RequestContextBuilder
Starts a context for the session session_id.
The runtime server builds the context of each invocation itself. Use this builder in tests, or to run code that reads the ambient context outside the server.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The runtime session ID. It comes from the
X-Amzn-Bedrock-AgentCore-Runtime-Session-Id header, or from the top-level
sessionId string of the request body when the header is absent.
Sourcepub fn request_id(&self) -> &str
pub fn request_id(&self) -> &str
The request ID. It comes from the X-Amzn-Bedrock-AgentCore-Runtime-Request-Id
header. The SDK generates a UUID when the header is absent.
In tests against AgentCore Runtime the service did not send this header, so
the ID of a deployed agent is the generated UUID. It is not the request ID
that the caller of InvokeAgentRuntime receives. To find the log lines of a
call, search for the session ID.
Sourcepub fn workload_access_token(&self) -> Option<&WorkloadAccessToken>
pub fn workload_access_token(&self) -> Option<&WorkloadAccessToken>
The workload access token that AgentCore Runtime sent with this invocation.
It comes from the X-Amz-Bedrock-AgentCore-Identity-WAT header, or from the
WorkloadAccessToken header when the first one is absent.
Sourcepub fn oauth2_callback_url(&self) -> Option<&str>
pub fn oauth2_callback_url(&self) -> Option<&str>
The OAuth2 callback URL from the OAuth2CallbackUrl header.
AgentCore Runtime does not add this header. In tests against the service it
passed the header on only when the caller sent it and the request header
allowlist of the agent runtime named it. An agent that needs a callback URL
on AgentCore Runtime sets it on the request, with
Oauth2TokenBuilder::callback_url.
Sourcepub fn headers(&self) -> &HeaderMap
pub fn headers(&self) -> &HeaderMap
The request headers that an agent may forward to other services.
The map holds only Authorization, headers whose name starts with
X-Amzn-Bedrock-AgentCore-Runtime-Custom-, and
X-Amz-Bedrock-AgentCore-Identity-WAT. A header that the request repeats has
one entry, with the values joined by a comma and a space. Every value is marked
sensitive, so Debug output of the map does not show it.
Sourcepub fn request_headers(&self) -> &HeaderMap
pub fn request_headers(&self) -> &HeaderMap
The headers of the request as the server received them. They include the
headers that the requestHeaderAllowlist of the agent runtime lets through,
such as an X-Api-Key header, and the Accept header.
The encrypted workload identity context is not in the map. A header that the
request repeats has one entry for each value. Every value is marked
sensitive, so Debug output of the map does not show it. Forward only the
headers of headers to other services.
Source§impl RequestContext
impl RequestContext
Sourcepub fn tasks(&self) -> &AsyncTasks
pub fn tasks(&self) -> &AsyncTasks
The registry of background work of the app that received this invocation.
Work tracked here makes the app report HealthyBusy. See crate::tasks.
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§impl Debug for RequestContext
impl Debug for RequestContext
Source§impl<S: Send + Sync> FromRequestParts<S> for RequestContext
On a route added with Builder::routes, a handler can
take the request context as an argument.
impl<S: Send + Sync> FromRequestParts<S> for RequestContext
On a route added with Builder::routes, a handler can
take the request context as an argument.
The context is built from the request headers only, so the session ID must be in
its header: a route that takes this argument replies 400 without it. The
context’s tasks is the registry of the app.
On any other route the extraction fails with 500, because the route has no app
whose registry the context could use.
Auto Trait Implementations§
impl Forget for RequestContext
impl Freeze for RequestContext
impl Move for RequestContext
impl RefUnwindSafe for RequestContextwhere
Atomic<usize>: RefUnwindSafe,
Mutex<Vec<(String, String)>>: RefUnwindSafe,
Atomic<*mut ()>: RefUnwindSafe,
Atomic<u64>: RefUnwindSafe,
Mutex<HashMap<TaskId, Entry>>: RefUnwindSafe,
impl Send for RequestContext
impl Sync for RequestContext
impl Unpin for RequestContext
impl UnsafeUnpin for RequestContext
impl UnwindSafe for RequestContextwhere
Arc<Inner>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more