Example #1
0
        public async Task <CommandResult> Handle(TCommand command, RequestContext context)
        {
            var  commandName      = command.GetType().FullName;
            bool shouldCreateSpan = traceSettings?.ShouldCreateSpan(commandName) ?? false;

            CommandResult commandResult = null;

            if (!shouldCreateSpan)
            {
                commandResult = await decoratedRequestHandler.Handle(command, context);
            }

            if (!context.Headers.ContainsKey(DistributedTracingHeader.DistributedTracingDataKey))
            {
                string outgoingDistributedTracingData =
                    (tracer.CurrentSpan?.OutgoingDistributedTracingData
                     ?? tracer.CurrentTransaction?.OutgoingDistributedTracingData)?.SerializeToString();

                context.Headers.Add(DistributedTracingHeader.DistributedTracingDataKey, outgoingDistributedTracingData);
            }

            if (tracer.CurrentTransaction == null)
            {
                await tracer.CaptureTransaction(commandName.ToTransactionName(), commandName.ToTransactionType(), async(transaction) =>
                {
                    // transaction.Labels["TK"] = "kadirzade";
                    await tracer.CurrentTransaction.CaptureSpan(commandName.ToSpanName(), commandName.ToSpanType(), async(span) =>
                    {
                        commandResult = await decoratedRequestHandler.Handle(command, context);
                    });
                }, DistributedTracingData.TryDeserializeFromString(context.Headers[DistributedTracingHeader.DistributedTracingDataKey]));
            }
            else
            {
                await tracer.CurrentTransaction.CaptureSpan(commandName.ToSpanName(), commandName.ToSpanType(), async (span) =>
                {
                    commandResult         = await decoratedRequestHandler.Handle(command, context);
                    span.Labels["result"] = commandResult.FormatResult();
                });
            }

            return(commandResult);
        }
        public async Task <QueryResult <TResponse> > Handle(TQuery query, RequestContext context)
        {
            var  queryName        = query.GetType().FullName;
            bool shouldCreateSpan = traceSettings?.ShouldCreateSpan(queryName) ?? false;
            QueryResult <TResponse> queryResult = null;

            if (!shouldCreateSpan)
            {
                queryResult = await decoratedRequestHandler.Handle(query, context);
            }

            if (!context.Headers.ContainsKey(DistributedTracingHeader.DistributedTracingDataKey))
            {
                string outgoingDistributedTracingData =
                    (tracer.CurrentSpan?.OutgoingDistributedTracingData
                     ?? tracer.CurrentTransaction?.OutgoingDistributedTracingData)?.SerializeToString();

                context.Headers.Add(DistributedTracingHeader.DistributedTracingDataKey, outgoingDistributedTracingData);
            }

            if (tracer.CurrentTransaction == null)
            {
                await tracer.CaptureTransaction(queryName.ToTransactionName(), queryName.ToTransactionType(), async() =>
                {
                    await tracer.CurrentTransaction.CaptureSpan(queryName.ToSpanName(), queryName.ToSpanType(), async(span) =>
                    {
                        queryResult = await decoratedRequestHandler.Handle(query, context);
                    });
                }, DistributedTracingData.TryDeserializeFromString(context.Headers[DistributedTracingHeader.DistributedTracingDataKey]));
            }
            else
            {
                await tracer.CurrentTransaction.CaptureSpan(queryName.ToSpanName(), queryName.ToSpanType(), async (span) =>
                {
                    queryResult           = await decoratedRequestHandler.Handle(query, context);
                    span.Labels["result"] = queryResult.FormatResult();
                    span.Type             = "";
                });
            }

            return(queryResult);
        }