Exemple #1
0
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            var tracer = _oneAgentSdk.TraceOutgoingMessage(
                _oneAgentSdk.CreateMessagingSystemInfo("Orleans Outgoing", context?.Grain?.ToString(),
                                                       MessageDestinationType.QUEUE, ChannelType.IN_PROCESS,
                                                       ""));


            if (RequestContext.Get("TraceId") != null)
            {
                tracer.SetCorrelationId(RequestContext.Get("TraceId").ToString());

                _logger.LogDebug("Tracing Outgoing {grainType} Correlation Id {traceId}", context.Grain.GetType().FullName, RequestContext.Get("TraceId"));

                await tracer.TraceAsync(async() =>
                {
                    if (RequestContext.Get(OneAgentSdkConstants.DYNATRACE_MESSAGE_PROPERTYNAME) == null)
                    {
                        RequestContext.Set(OneAgentSdkConstants.DYNATRACE_MESSAGE_PROPERTYNAME, tracer.GetDynatraceByteTag());
                    }
                    // _logger.LogDebug("Outgoing Dyntrace Byte Tag  : {byte_tag}", RequestContext.Get(OneAgentSdkConstants.DYNATRACE_MESSAGE_PROPERTYNAME));
                    await context.Invoke();
                });
            }
            else
            {
                await context.Invoke();
            }
        }
Exemple #2
0
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            var grainType = context.Grain.GetType();
            var grainName = grainType.GetDemystifiedName();
            var shouldHaveDetailedTrace = grainType.Namespace.Contains("Heroes");             // todo: Create log filter mechanism

            if (!shouldHaveDetailedTrace)
            {
                await context.Invoke();

                return;
            }

            string primaryKey = null;

            if (context.Grain is Grain grain)
            {
                primaryKey = grain.GetPrimaryKeyAny();
            }

            var stopwatch = Stopwatch.StartNew();

            try
            {
                await context.Invoke();

                stopwatch.Stop();

                //if (stopwatch.Elapsed > WarnThreshold)
                //{
                _logger.LogDebug(
                    "Invoking grain method {grain}.{grainMethod} ({primaryKey}) in {duration:n0}ms",
                    grainName,
                    context.InterfaceMethod.Name,
                    primaryKey,
                    stopwatch.ElapsedMilliseconds
                    );
                //}
            }
            catch (Exception ex)
            {
                _logger.LogError(
                    ex,
                    "Execution failed for grain method {grain}.{grainMethod} ({primaryKey}) in {duration:n0}ms.",
                    primaryKey,
                    grainName,
                    context.InterfaceMethod.Name,
                    stopwatch.ElapsedMilliseconds
                    )
                ;
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Invoke Grain call context.
        /// </summary>
        /// <param name="context">The <see cref="IOutgoingGrainCallContext"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public Task Invoke(IOutgoingGrainCallContext context)
        {
            if (RequestContext.Get(Constants.ActivityHeader) != null || Activity.Current == null)
            {
                return(context.Invoke());
            }

            RequestContext.Set(Constants.ActivityHeader, Activity.Current.Id);
            RequestContext.Set(Constants.BaggageHeader, Activity.Current.Baggage);

            return(context.Invoke());
        }
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            using var operation = _telemetryClient
                                  .StartOperation <DependencyTelemetry>(Common.Config.SiloHostName);
            //var dependencyTelemetry = CreateRequestTelemetry(_telemetryClient.Context);
            //var operation = _telemetryClient.StartOperation(dependencyTelemetry);

            try
            {
                await context.Invoke();

                operation.Telemetry.Success = true;
                operation.Telemetry.Context.Cloud.RoleName = "SiloHost";
                //operation.Telemetry.Context.Cloud.RoleInstance = _clusterClient.;
                //operation.Context.Component.Version = Common.Config.SiloHostName;

                _telemetryClient.StopOperation(operation);
            }
            catch (Exception)
            {
                operation.Telemetry.Success = false;
                _telemetryClient.StopOperation(operation);
                throw;
            }
        }
Exemple #5
0
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            LogWrite(context, () =>
            {
                Console.WriteLine($"{this.GetType().Name} Grain Before Invoke");
                Console.WriteLine($"{this.GetType().Name} Grain Name: {context.Grain.GetType().FullName}");
                Console.WriteLine($"{this.GetType().Name} Grain Interface Type: {context.InterfaceMethod.DeclaringType?.FullName}");
                Console.WriteLine($"{this.GetType().Name} Grain PrimaryKey: {context.Grain.GetPrimaryKeyLong()}");
                Console.WriteLine($"{this.GetType().Name} Grain Method Arguments: {string.Join(",", context.Arguments ?? new object[] {})}");
            });

            try
            {
                await context.Invoke();

                LogWrite(context, () => Console.WriteLine($"{this.GetType().Name} Grain After Invoke"));
            }
            catch (Exception e)
            {
                LogWrite(context, () => Console.WriteLine($"{this.GetType().Name} Grain Exception: {e}"));
                throw;
            }
            finally
            {
                LogWrite(context, () => Console.WriteLine($"{this.GetType().Name} Grain Result: {context.Result}"));
            }
        }
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            Console.WriteLine("Before Method Invoke, outgoing call filter");
            await context.Invoke();

            Console.WriteLine("After Method Invoke, outgoing call filter");
        }
Exemple #7
0
        public Task Invoke(IOutgoingGrainCallContext context)
        {
            RequestContext.Set("Culture", CultureInfo.CurrentCulture.Name);
            RequestContext.Set("CultureUI", CultureInfo.CurrentUICulture.Name);

            return(context.Invoke());
        }
Exemple #8
0
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            Console.WriteLine("Hello! i am Outgoing call filter");
            await context.Invoke();

            Console.WriteLine(" I am done with  Outgoing call filter");
        }
Exemple #9
0
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            await context.Invoke();

            // Change the result of the call from 7 to 38.
            if (string.Equals(context.InterfaceMethod.Name, nameof(this.GetFavoriteNumber)))
            {
                context.Result = 58;
            }
        }
Exemple #10
0
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            if (AuthorizationAdmission.IsRequired(context))
            {
                await AuthorizeAsync(context);

                var grainType = context.Grain.GetType();
                Log(LoggingEvents.OutgoingGrainCallAuthorizationPassed,
                    grainType.Name, context.InterfaceMethod.Name);
            }

            await context.Invoke();
        }
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            if (AuthenticationChallenge(context))
            {
                var accessToken = await _accessTokenProvider.RetrieveTokenAsync();

                await AuthorizeAsync(context, accessToken);

                var grainType = context.Grain.GetType();

                Logger.LogTrace(LoggingEvents.OutgoingGrainCallAuthorizationPassed,
                                $"{LoggingEvents.OutgoingGrainCallAuthorizationPassed.Name} Type of Grain: {grainType.Name} " +
                                $"Method Name: {context.InterfaceMethod.Name} ");

                RequestContext.Set(ConfigurationKeys.AccessTokenKey, accessToken);
            }

            await context.Invoke();
        }
        public async Task Invoke(IOutgoingGrainCallContext context)
        {
            try
            {
                await context.Invoke();

                if (context.InterfaceMethod.Name == "GetFavoriteNumber")
                {
                    var msg = $"调用方法为: {context.Grain.GetType()}.{context.InterfaceMethod.Name}({(context.Arguments != null ? string.Join(", ", context.Arguments) : "")}) 返回值为: {context.Result}";
                    Console.WriteLine(msg);
                }
            }
            catch (Exception exception)
            {
                var msg = $"{context.Grain.GetType()}.{context.InterfaceMethod.Name}({(context.Arguments != null ? string.Join(", ", context.Arguments) : "")}) 抛出了一个异常: {exception.Message}";
                Console.WriteLine(msg);
                throw;
            }
        }
Exemple #13
0
                    static async Task RetryCertainCalls(IOutgoingGrainCallContext ctx)
                    {
                        var attemptsRemaining = 2;

                        while (attemptsRemaining > 0)
                        {
                            try
                            {
                                await ctx.Invoke();

                                return;
                            }
                            catch (ArgumentOutOfRangeException) when(attemptsRemaining > 1 && ctx.Grain is IOutgoingMethodInterceptionGrain)
                            {
                                if (string.Equals(ctx.InterfaceMethod?.Name, nameof(IOutgoingMethodInterceptionGrain.ThrowIfGreaterThanZero)) && ctx.Arguments[0] is int value)
                                {
                                    ctx.Arguments[0] = value - 1;
                                }

                                --attemptsRemaining;
                            }
                        }
                    }
Exemple #14
0
 public async Task Invoke(IOutgoingGrainCallContext context)
 {
     RequestContext.Set(Constants.OrleansIPAddressContextKey,
                        _requestContextAccessor?.IPAddress?.ToString());
     await context.Invoke();
 }
Exemple #15
0
 public async Task Invoke(IOutgoingGrainCallContext context)
 {
     await context.Invoke();
 }
Exemple #16
0
        public Task Invoke(IOutgoingGrainCallContext context)
        {
            Debug.Assert(context.InterfaceMethod != null, "Expected interface method to not be null");

            return(context.Invoke());
        }
Exemple #17
0
 public Task Invoke(IOutgoingGrainCallContext context)
 {
     return(context.Invoke());
 }