コード例 #1
0
 protected override void StartHost()
 {
     if (_server == null)
     {
         _server = GrpcHelper.StartHost(_host, _port, new DummyPOSV1());
     }
 }
コード例 #2
0
        static void day(short year, short month, short day)
        {
            var _grpcHelper = new GrpcHelper(_srvAddress);
            var _pingMsg    = _grpcHelper.GetDay(year, month, day);

            Console.WriteLine(_pingMsg);
        }
コード例 #3
0
        static void past(short daysBack)
        {
            var _grpcHelper = new GrpcHelper(_srvAddress);
            var _pingMsg    = _grpcHelper.GetPast(daysBack);

            Console.WriteLine(_pingMsg);
        }
コード例 #4
0
        static void ping()
        {
            var _grpcHelper = new GrpcHelper(_srvAddress);
            var _pingMsg    = _grpcHelper.PingServer();

            Console.WriteLine(_pingMsg);
        }
コード例 #5
0
        public void GivenAGRPCSpanWithStatus(string responseCode)
        {
            var span = _agent.Tracer.StartTransaction("GRPCTransaction", "Test").StartSpan("GRPCSpan", "Test");

            span.Outcome = GrpcHelper.GrpcClientReturnCodeToOutcome(responseCode);
            _lastSpan    = span;
        }
コード例 #6
0
        public void GivenAGRPCTransactionWithStatus(string responseCode)
        {
            var transaction = _agent.Tracer.StartTransaction("GRPCTransaction", "Test");

            transaction.Outcome = GrpcHelper.GrpcServerReturnCodeToOutcome(responseCode);
            _lastTransaction    = transaction;
        }
コード例 #7
0
        protected override void HandleOnNext(KeyValuePair <string, object> kv)
        {
            Logger.Trace()
            ?.Log("{currentClassName} received diagnosticsource event: {eventKey}", nameof(GrpcClientDiagnosticListener), kv.Key);

            var currentActivity = Activity.Current;

            if (kv.Key == "Grpc.Net.Client.GrpcOut.Start")
            {
                if (kv.Value.GetType().GetTypeInfo().GetDeclaredProperty("Request")?.GetValue(kv.Value) is HttpRequestMessage requestObject)
                {
                    var currentTransaction = ApmAgent?.Tracer.CurrentTransaction;

                    if (currentTransaction != null)
                    {
                        var grpcMethodName = currentActivity?.Tags.FirstOrDefault(n => n.Key == "grpc.method").Value;

                        if (string.IsNullOrEmpty(grpcMethodName))
                        {
                            grpcMethodName = "unknown";
                        }

                        Logger.Trace()?.Log("Starting span for gRPC call, method:{methodName}", grpcMethodName);
                        var newSpan = currentTransaction.StartSpan(grpcMethodName, ApiConstants.TypeExternal, ApiConstants.SubTypeGrpc, isExitSpan: true);
                        ProcessingRequests.TryAdd(requestObject, newSpan);
                    }
                }
            }
            if (kv.Key == "Grpc.Net.Client.GrpcOut.Stop")
            {
                if (kv.Value.GetType().GetTypeInfo().GetDeclaredProperty("Request")?.GetValue(kv.Value) is not HttpRequestMessage requestObject)
                {
                    return;
                }

                if (!ProcessingRequests.TryRemove(requestObject, out var span))
                {
                    return;
                }

                Logger.Trace()?.Log("Ending span for gRPC call, span:{span}", span);

                var grpcStatusCode = currentActivity?.Tags?.Where(n => n.Key == "grpc.status_code").FirstOrDefault().Value;
                if (grpcStatusCode != null)
                {
                    span.Outcome = GrpcHelper.GrpcClientReturnCodeToOutcome(GrpcHelper.GrpcReturnCodeToString(grpcStatusCode));
                }

                span.Context.Destination         = UrlUtils.ExtractDestination(requestObject.RequestUri, Logger);
                span.Context.Destination.Service = new() { Resource = UrlUtils.ExtractService(requestObject.RequestUri, span) };

                span.End();
            }
        }
    }
コード例 #8
0
 protected override ifPOS.v1.IPOS CreateClient() => GrpcHelper.GetClient <ifPOS.v1.IPOS>(_host, _port);
コード例 #9
0
        internal static void StopTransaction(Transaction transaction, HttpContext context, IApmLogger logger)
        {
            if (transaction == null)
            {
                return;
            }

            var grpcCallInfo = CollectGrpcInfo();

            try
            {
                if (!transaction.HasCustomName)
                {
                    //fixup Transaction.Name - e.g. /user/profile/1 -> /user/profile/{id}
                    var routeData = context.GetRouteData()?.Values;

                    if (routeData != null && context.Response.StatusCode != StatusCodes.Status404NotFound)
                    {
                        logger?.Trace()?.Log("Calculating transaction name based on route data");
                        var name = Transaction.GetNameFromRouteContext(routeData);

                        if (!string.IsNullOrWhiteSpace(name))
                        {
                            transaction.Name = $"{context.Request.Method} {name}";
                        }
                    }
                    else if (context.Response.StatusCode == StatusCodes.Status404NotFound)
                    {
                        logger?.Trace()
                                                        ?
                        .Log("No route data found or status code is 404 - setting transaction name to 'unknown route");
                        transaction.Name = $"{context.Request.Method} unknown route";
                    }
                }

                if (grpcCallInfo == default)
                {
                    transaction.Result = Transaction.StatusCodeToResult(GetProtocolName(context.Request.Protocol), context.Response.StatusCode);

                    if (context.Response.StatusCode >= 500)
                    {
                        transaction.Outcome = Outcome.Failure;
                    }
                    else
                    {
                        transaction.Outcome = Outcome.Success;
                    }
                }
                else
                {
                    transaction.Name   = grpcCallInfo.methodname;
                    transaction.Result = GrpcHelper.GrpcReturnCodeToString(grpcCallInfo.result);

                    if (transaction.Result == "OK")
                    {
                        transaction.Outcome = Outcome.Success;
                    }
                    else
                    {
                        transaction.Outcome = Outcome.Failure;
                    }
                }

                if (transaction.IsSampled)
                {
                    FillSampledTransactionContextResponse(context, transaction, logger);
                    FillSampledTransactionContextUser(context, transaction, logger);
                }
            }
            catch (Exception ex)
            {
                logger?.Error()?.LogException(ex, "Exception thrown while trying to stop transaction");
            }
            finally
            {
                transaction.End();
            }
        }
コード例 #10
0
 protected override ifPOS.v1.de.IDESSCD CreateClient() => GrpcHelper.GetClient <ifPOS.v1.de.IDESSCD>(_host, _port);