public async Task StartAsync_CreateSpanAsReference_ContextIsReferenced()
        {
            PrepareQueues();

            var host    = GetReverseStringService();
            var channel = _fixture.Connection.CreateModel();

            await CreateQueueForServicePublisherWithPublisherBindingFromConfig(channel);

            await host.StartAsync();

            var extensions     = new List <ICloudEventExtension>();
            var randomActivity = CreateRandomActivity();
            var distributedTracingExtension = new DistributedTracingExtension();

            distributedTracingExtension.SetActivity(randomActivity);
            extensions.Add(distributedTracingExtension);
            var motorCloudEvent = MotorCloudEvent.CreateTestCloudEvent(new byte[0], extensions: extensions);

            await PublishMessageIntoQueueOfService(channel, "12345", motorCloudEvent);

            var ctx = await GetActivityContextFromDestinationQueue(channel);

            Assert.Equal(randomActivity.Context.TraceId, ctx.TraceId);
            Assert.NotEqual(randomActivity.Context.SpanId, ctx.SpanId);
            await host.StopAsync();
        }
Ejemplo n.º 2
0
 public static void SetActivity(this DistributedTracingExtension extension, Activity activity)
 {
     extension.TraceParent = activity.Id;
     if (!string.IsNullOrWhiteSpace(activity.TraceStateString))
     {
         extension.TraceState = activity.TraceStateString;
     }
 }
        public async Task PublishMessageAsync_WithConfig_BasicPropertiesAreSet()
        {
            var basicProperties = Mock.Of <IBasicProperties>();
            var modelMock       = new Mock <IModel>();

            modelMock.Setup(x => x.CreateBasicProperties()).Returns(basicProperties);
            var rabbitConnectionFactoryMock =
                GetDefaultConnectionFactoryMock(modelMock: modelMock, basicProperties: basicProperties);

            var        publisher = GetPublisher(rabbitConnectionFactoryMock.Object, GetConfig());
            const byte priority  = 1;

            var openTelemetryExtension = new DistributedTracingExtension();

            var activity = new Activity(nameof(RabbitMQMessagePublisherTests));

            activity.SetIdFormat(ActivityIdFormat.W3C);
            activity.Start();
            openTelemetryExtension.SetActivity(activity);

            var motorCloudEvent = MotorCloudEvent.CreateTestCloudEvent(new byte[0],
                                                                       extensions: new List <ICloudEventExtension>
            {
                new RabbitMQPriorityExtension(priority), openTelemetryExtension
            }.ToArray());

            await publisher.PublishMessageAsync(motorCloudEvent);

            Assert.Equal(2, basicProperties.DeliveryMode);
            Assert.Equal(priority, basicProperties.Priority);
            var traceparent     = Encoding.UTF8.GetString((byte[])basicProperties.Headers[$"{BasicPropertiesExtensions.CloudEventPrefix}{DistributedTracingExtension.TraceParentAttributeName}"]).Trim('"');
            var activityContext = ActivityContext.Parse(traceparent, null);

            Assert.Equal(activity.Context.TraceId, activityContext.TraceId);
            Assert.Equal(activity.Context.SpanId, activityContext.SpanId);
            Assert.Equal(activity.Context.TraceFlags, activityContext.TraceFlags);
        }
Ejemplo n.º 4
0
 public static ActivityContext GetActivityContext(this DistributedTracingExtension extension)
 {
     return(ActivityContext.Parse(extension.TraceParent, extension.TraceState));
 }