Example #1
0
        private Trace CreateTrace()
        {
            Trace parent = _parent?.Trace;

            if (parent == null && !_ignoreActiveSpan)
            {
                parent = ((OtSpan)_tracer.ActiveSpan)?.Trace;
            }

            Trace trace = parent != null?parent.Child() : Trace.Create();

            return(trace);
        }
Example #2
0
        public ITransmissionRequest Build(Trace root)
        {
            Trace span = root.Child();

            span.Record(Annotations.ServiceName("build"));
            span.Record(Annotations.ClientSend());
            try
            {
                return(this.Build());
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
Example #3
0
        public ITransmissionMessage NewInstance(Stream inputStream, Trace root)
        {
            var trace = root.Child();

            trace.Record(Annotations.ServiceName(this.GetType().Name));
            trace.Record(Annotations.ClientSend());
            try
            {
                return(this.Perform(inputStream, root));
            }
            finally
            {
                trace.Record(Annotations.ClientRecv());
            }
        }
Example #4
0
        /// <inheritdoc />
        public ITransmissionResponse Transmit(ITransmissionMessage transmissionMessage, Trace root)
        {
            Trace span = root.Child();

            span.Record(Annotations.ServiceName("transmit"));
            span.Record(Annotations.ClientSend());
            try
            {
                return(this.Perform(transmissionMessage, span));
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
Example #5
0
        public void Persist(
            ITransmissionRequest transmissionRequest,
            ITransmissionResponse transmissionResponse,
            Trace root)
        {
            Trace span = root.Child();

            span.Record(Annotations.ServiceName("persist statistics"));
            span.Record(Annotations.ClientSend());
            try
            {
                RawStatisticsBuilder builder = new RawStatisticsBuilder()
                                               .AccessPointIdentifier(this.ourAccessPointIdentifier).Direction(Direction.OUT)
                                               .DocumentType(transmissionResponse.GetHeader().DocumentType)
                                               .Sender(transmissionResponse.GetHeader().Sender)
                                               .Receiver(transmissionResponse.GetHeader().Receiver)
                                               .Profile(transmissionResponse.GetHeader().Process)
                                               .Date(transmissionResponse.GetTimestamp()); // Time stamp of reception of the receipt

                // If we know the CN name of the destination AP, supply that
                // as the channel id otherwise use the protocol name
                if (transmissionRequest.GetEndpoint().Certificate != null)
                {
                    String accessPointIdentifierValue =
                        CertificateUtils.ExtractCommonName(transmissionRequest.GetEndpoint().Certificate);
                    builder.Channel(new ChannelId(accessPointIdentifierValue));
                }
                else
                {
                    String protocolName = transmissionRequest.GetEndpoint().TransportProfile.Identifier;
                    builder.Channel(new ChannelId(protocolName));
                }

                DefaultRawStatistics rawStatistics = builder.Build();
                this.rawStatisticsRepository.Persist(rawStatistics);
            }
            catch (Exception ex)
            {
                span.Record(Annotations.Tag("exception", ex.Message));
                Logger.Error($"Persisting DefaultRawStatistics about oubound transmission failed : {ex.Message}", ex);
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }
        }
Example #6
0
        private ITransmissionMessage Perform(Stream inputStream, Trace root)
        {
            PeekingInputStream peekingInputStream = new PeekingInputStream(inputStream);

            // Read header from content to send.
            Header header;

            try
            {
                // Read header from SBDH.
                var span = root.Child();
                span.Record(Annotations.ServiceName("Reading SBDH"));
                span.Record(Annotations.ClientSend());
                try {
                    using (SbdReader sbdReader = SbdReader.NewInstance(peekingInputStream))
                    {
                        header = sbdReader.Header;
                        span.Record(Annotations.Tag("identifier", header.Identifier.Identifier));
                    }
                } catch (SbdhException e) {
                    span.Record(Annotations.Tag("exception", e.Message));
                    throw;
                } finally {
                    span.Record(Annotations.ClientRecv());
                }

                // Create transmission request.
                return(new DefaultTransmissionMessage(header, peekingInputStream.NewInputStream()));
            }
            catch (SbdhException)
            {
                byte[] payload = peekingInputStream.GetContent();

                // Detect header from content.
                Trace span = root.Child();
                span.Record(Annotations.ServiceName("Detect SBDH from content"));
                span.Record(Annotations.ClientSend());
                try
                {
                    header = this.contentDetector.Parse(payload.ToStream());
                    span.Record(Annotations.Tag("identifier", header.Identifier.Identifier));
                }
                catch (HyperwayContentException ex)
                {
                    span.Record(Annotations.Tag("exception", ex.Message));
                    throw new HyperwayContentException(ex.Message, ex);
                }
                finally
                {
                    span.Record(Annotations.ClientRecv());
                }

                // Wrap content in SBDH.
                span = root.Child();
                span.Record(Annotations.ServiceName("Wrap content in SBDH"));
                span.Record(Annotations.ClientSend());
                Stream wrappedContent;
                try
                {
                    wrappedContent = this.contentWrapper.Wrap(payload.ToStream(), header);
                }
                catch (HyperwayContentException ex)
                {
                    span.Record(Annotations.Tag("exception", ex.Message));
                    throw;
                }
                finally
                {
                    span.Record(Annotations.ClientRecv());
                }

                // Create transmission request.
                return(new DefaultTransmissionMessage(header, wrappedContent));
            }
        }
Example #7
0
        private ITransmissionResponse Perform(ITransmissionMessage transmissionMessage, Trace root)
        {
            this.transmissionVerifier.Verify(transmissionMessage.GetHeader(), Direction.OUT);

            ITransmissionRequest transmissionRequest;

            if (transmissionMessage is ITransmissionRequest)
            {
                transmissionRequest = (ITransmissionRequest)transmissionMessage;
            }
            else
            {
                // Perform lookup using header.
                Trace lookupSpan = root.Child();
                lookupSpan.Record(Annotations.ServiceName("Fetch endpoint information"));
                lookupSpan.Record(Annotations.ClientSend());
                try
                {
                    var endpoint = this.lookupService.Lookup(transmissionMessage.GetHeader(), lookupSpan);
                    lookupSpan.Record(
                        Annotations.Tag("transport profile", endpoint.TransportProfile.Identifier));
                    transmissionRequest = new DefaultTransmissionRequest(transmissionMessage, endpoint);
                }
                catch (HyperwayTransmissionException e)
                {
                    lookupSpan.Record(Annotations.Tag("exception", e.Message));
                    throw;
                }
                finally
                {
                    lookupSpan.Record(Annotations.ClientRecv());
                }
            }

            Trace span = root.Child();

            span.Record(Annotations.ServiceName("send message"));
            span.Record(Annotations.ClientSend());

            // Span span = tracer.newChild(root.context()).name("send message").start();
            ITransmissionResponse transmissionResponse;

            try
            {
                TransportProfile transportProfile = transmissionRequest.GetEndpoint().TransportProfile;
                IMessageSender   messageSender    = this.messageSenderFactory.GetMessageSender(transportProfile);
                transmissionResponse = messageSender.Send(transmissionRequest, span);
            }
            catch (HyperwayTransmissionException e)
            {
                span.Record(Annotations.Tag("exception", e.Message));
                throw;
            }
            finally
            {
                span.Record(Annotations.ClientRecv());
            }

            this.statisticsService.Persist(transmissionRequest, transmissionResponse, root);

            return(transmissionResponse);
        }