Ejemplo n.º 1
0
        static void SendRandomLogs(EventHubClient eventHubClient)
        {
            var    eventhubMessage = new EventHubMessage();
            string message         = "";

            var prefixBytes = new byte[16];

            random.NextBytes(prefixBytes);
            string prefix = ByteArrayToHexStringConverter.Convert(prefixBytes);

            var bytes = new byte[8];

            random.NextBytes(bytes);
            var d2CSpanId        = ByteArrayToHexStringConverter.Convert(bytes);
            var d2CCorrelationId = GenerateTraceId(prefix, d2CSpanId);

            random.NextBytes(bytes);
            var ingressSpanId        = ByteArrayToHexStringConverter.Convert(bytes);
            var ingressCorrelationId = GenerateTraceId(prefix, ingressSpanId);

            var randDeviceName = deviceNames[random.Next(deviceNames.Length)];
            var d2cLog         = GenerateD2CLogs(d2CCorrelationId, randDeviceName);
            var ingressLog     = GenerateIngressLogs(ingressCorrelationId, d2CSpanId);

            random.NextBytes(bytes);
            var egressSpanId        = ByteArrayToHexStringConverter.Convert(bytes);
            var egressCorrelationId = GenerateTraceId(prefix, egressSpanId);

            var randPointName = endpointNames[random.Next(endpointNames.Length)];
            var egressLog     = GenerateEgressLogs(egressCorrelationId, ingressSpanId, randPointName);

            eventhubMessage.records.Add(d2cLog);
            eventhubMessage.records.Add(ingressLog);
            eventhubMessage.records.Add(egressLog);

            if (SendThirdPartyLogs)
            {
                random.NextBytes(bytes);
                var thirdPartyServiceD2CSpanId        = ByteArrayToHexStringConverter.Convert(bytes);
                var thirdPartyServiceD2CCorrelationId = GenerateTraceId(prefix, thirdPartyServiceD2CSpanId);

                var randIndex    = random.Next(deviceNames.Length);
                var randEndpoint = endpointNames[randIndex];
                var randService  = serviceNames[randIndex];

                var thirdPartyServiceD2CLog = GenerateThirdPartyD2CLogs(thirdPartyServiceD2CCorrelationId, randService, randEndpoint);

                random.NextBytes(bytes);
                var thirdPartyServiceIngressSpanId        = ByteArrayToHexStringConverter.Convert(bytes);
                var thirdPartyServiceIngressCorrelationId = GenerateTraceId(prefix, thirdPartyServiceIngressSpanId);
                var thirdPartyServiceIngressLog           = GenerateThirdPartyIngressLogs(thirdPartyServiceIngressCorrelationId, thirdPartyServiceD2CSpanId, randService);

                eventhubMessage.records.Add(thirdPartyServiceD2CLog);
                eventhubMessage.records.Add(thirdPartyServiceIngressLog);
            }

            message = JsonConvert.SerializeObject(eventhubMessage);
            eventHubClient.Send(new EventData(Encoding.UTF8.GetBytes(message)));
        }
Ejemplo n.º 2
0
        static string GenerateTraceId(string prefix, string spanId = null)
        {
            if (spanId == null)
            {
                var bytes = new byte[8];
                random.NextBytes(bytes);
                spanId = ByteArrayToHexStringConverter.Convert(bytes);
            }

            return($"00-{prefix}-{spanId}-01");
        }