Task <int> IMyActor.GetCountAsync(CancellationToken cancellationToken) { var traceId = RemotingContext.GetData(HeaderIdentifiers.TraceId); _logger.LogInformation($"Hello from inside {nameof(MyActor)} (traceId {traceId})"); return(StateManager.GetStateAsync <int>("count", cancellationToken)); }
Task <string> IDemoActor.GetGreetingResponseAsync(CancellationToken cancellationToken) { // Read the data from the custom header var remotingContext = string.Join(", ", RemotingContext.Keys.Select(k => $"{k}: {RemotingContext.GetData(k)}")); ActorEventSource.Current.ActorMessage(this, $"GetGreetingResponseAsync got context: {remotingContext}"); return(Task.FromResult($"Hello From Actor (with context '{remotingContext}')")); }
public async Task <int> CalculateSumAsync(int a, int b) { var traceId = RemotingContext.GetData(HeaderIdentifiers.TraceId); _logger.LogTrace($"Hello from inside {nameof(MyStateless)} (traceId {traceId})"); await new HttpClient().GetAsync("http://www.nu.nl"); return(a + b); }
public async Task <string> SayHelloToActor() { // Read the data from the custom header var remotingContext = string.Join(", ", RemotingContext.Keys.Select(k => $"{k}: {RemotingContext.GetData(k)}")); ServiceEventSource.Current.ServiceMessage(Context, $"SayHelloToActor got context: {remotingContext}"); // Call the actor using the same headers as received by this method var proxy = ExtendedActorProxy.Create <IDemoActor>(new ActorId(1), CustomHeaders.FromRemotingContext); var response = await proxy.GetGreetingResponseAsync(CancellationToken.None); return($"DemoService passed context '{remotingContext}' to actor and got as response: {response}"); }
public ILoggerFactory CreateLoggerFactory(string aiKey) { var configuration = new TelemetryConfiguration { InstrumentationKey = aiKey }; configuration.TelemetryInitializers.Add(new OperationContextTelemetryInitializer(() => RemotingContext.GetData(HeaderIdentifiers.TraceId)?.ToString())); new LiveStreamProvider(configuration).Enable(); var loggerFactory = new LoggerFactory(); var logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo .ApplicationInsights( configuration, (logEvent, formatter) => new TelemetryBuilder(_context, logEvent).LogEventToTelemetryConverter()) .CreateLogger(); InitContextProperties(); loggerFactory.AddSerilog(logger, true); return(loggerFactory); }