diff --git a/docs/orleans/grains/request-context.md b/docs/orleans/grains/request-context.md index 66abf04f124b7..71e41873ecf14 100644 --- a/docs/orleans/grains/request-context.md +++ b/docs/orleans/grains/request-context.md @@ -114,3 +114,28 @@ Console.WriteLine(message); ``` In this example, the client sets the trace ID to "example-id-set-by-client" before calling the `SayHello` method on the `HelloGrain`. The grain retrieves the trace ID from the request context and logs it. + +## Example placement access code + +The data can be accessed during Placement or Placement Filtering through the `RequestContextData`. The static is not populated at this time as there is not yet an activation of the grain. The following placement filter code demonstrates how to get data while handling placement: + +```csharp +internal sealed class ExamplePlacementFilterDirector(ILogger logger) + : IPlacementFilterDirector +{ + public IEnumerable Filter( + PlacementFilterStrategy filterStrategy, + PlacementTarget target, + IEnumerable silos) + { + if (target.RequestContextData.TryGetValue("somekey", out var somevalue) + && somevalue is string somestring) + { + logger.LogInformation("Read {Value} for {Key} from the RequestContext", somestring, "somekey"); + // somestring is available for the filtering logic + } + return silos; + } +} +``` +In this example, the "somekey" value is read from the `RequestContextData` during the placement filtering.