Exemple #1
0
        public async Task Activity_TenantInBaggage_TenantAccessorReturnsTenantId()
        {
            // Arrange
            var busControl = _serviceProvider.GetRequiredService <IBusControl>();

            busControl.Start();

            var tenantId = "7";
            var activity = new System.Diagnostics.Activity("producer");

            activity.AddBaggage(Constants.TenantIdBaggageKey, tenantId);
            activity.Start();
            var expectedActivityRoot = activity.RootId;

            var messageId = Guid.NewGuid();

            // Act
            await busControl.Publish(new MockMessage { Id = messageId });

            await Task.Delay(500);

            // Assert
            Assert.Contains(messageId, State.Messages.Keys);
            Assert.Equal(expectedActivityRoot, State.Messages[messageId].CorrelationId);
            Assert.Single(State.Messages[messageId].TenantIds);
            Assert.Equal(tenantId, State.Messages[messageId].TenantIds.First());
        }
        /// <summary>
        /// Called before a message is dispatched to any consumers. Sets the <see cref="MassTransitContext"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task PreConsume <T>(ConsumeContext <T> context) where T : class
        {
            var parentActivityId = context.Headers?.Get(Constants.ActivityIdHeader, string.Empty);
            var activity         = new System.Diagnostics.Activity(Constants.ConsumeActivityName);

            if (!string.IsNullOrEmpty(parentActivityId))
            {
                activity.SetParentId(parentActivityId);
            }

            var baggage = context.Headers?.Get <IEnumerable <KeyValuePair <string, string> > >(Constants.BaggageHeader);

            if (baggage?.Any() ?? false)
            {
                foreach (var item in baggage)
                {
                    activity.AddBaggage(item.Key, item.Value);
                }
            }

            activity.Start();
            _tracer?.StartSpanFromActivity(Constants.SpanConsumeOperationNamePrefix, activity, SpanKind.Consumer);

            return(Task.CompletedTask);
        }
Exemple #3
0
        /// <summary>
        /// Invoke Grain call context.
        /// </summary>
        /// <param name="context">The <see cref="IOutgoingGrainCallContext"/>.</param>
        /// <returns>A <see cref="Task"/>.</returns>
        public async Task Invoke(IIncomingGrainCallContext context)
        {
            var activity = new System.Diagnostics.Activity(OrleansDistributedTracingConstants.IncomingGrainFilterActivityName);

            if (RequestContext.Get(Constants.ActivityHeader) is string traceId)
            {
                activity.SetParentId(traceId);
            }

            if (RequestContext.Get(Constants.BaggageHeader) is IEnumerable <KeyValuePair <string, string> > baggage)
            {
                foreach (var item in baggage)
                {
                    activity.AddBaggage(item.Key, item.Value);
                }
            }

            activity.Start();

            await context.Invoke();

            activity.Stop();
        }