public void ProfiledCommandToSpanDataUsesTimestampAsStartTime() { var profiledCommand = new Mock <IProfiledCommand>(); var now = DateTimeOffset.Now; profiledCommand.Setup(m => m.CommandCreated).Returns(now.DateTime); var result = RedisProfilerEntryToSpanConverter.ProfiledCommandToSpanData(SpanContext.Blank, "SET", SpanId.Invalid, profiledCommand.Object); Assert.Equal(Timestamp.FromMillis(now.ToUnixTimeMilliseconds()), result.StartTimestamp); }
public void ProfiledCommandToSpanUsesTimestampAsStartTime() { var profiledCommand = new Mock <IProfiledCommand>(); var now = DateTimeOffset.Now; profiledCommand.Setup(m => m.CommandCreated).Returns(now.DateTime); var result = ((Span)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, BlankSpan.Instance, profiledCommand.Object)); Assert.Equal(now, result.StartTimestamp); }
public void ProfiledCommandToSpanSetsDbTypeAttributeAsRedis() { var profiledCommand = new Mock <IProfiledCommand>(); profiledCommand.Setup(m => m.CommandCreated).Returns(DateTime.UtcNow); var result = ((Span)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, BlankSpan.Instance, profiledCommand.Object)); Assert.Contains(result.Attributes, kvp => kvp.Key == "db.type"); Assert.Equal("redis", result.Attributes.GetValue("db.type")); }
public void ProfiledCommandToSpanDataUsesCommandAsDbStatementAttribute() { var profiledCommand = new Mock <IProfiledCommand>(); profiledCommand.Setup(m => m.Command).Returns("SET"); var result = RedisProfilerEntryToSpanConverter.ProfiledCommandToSpanData(SpanContext.Blank, "another name", SpanId.Invalid, profiledCommand.Object); Assert.Contains("db.statement", result.Attributes.AttributeMap.Keys); Assert.Equal(AttributeValue.StringAttributeValue("SET"), result.Attributes.AttributeMap["db.statement"]); }
public void DrainSessionUsesCommandAsName() { var profiledCommand = new Mock <IProfiledCommand>(); profiledCommand.Setup(m => m.CommandCreated).Returns(DateTime.UtcNow); profiledCommand.Setup(m => m.Command).Returns("SET"); var result = (Span)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(tracer, BlankSpan.Instance, profiledCommand.Object); Assert.Equal("SET", result.Name); }
public void ProfiledCommandToSpanUsesCommandAsDbStatementAttribute() { var profiledCommand = new Mock <IProfiledCommand>(); profiledCommand.Setup(m => m.CommandCreated).Returns(DateTime.UtcNow); profiledCommand.Setup(m => m.Command).Returns("SET"); var result = ((Span)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object)); Assert.Contains(result.Attributes, kvp => kvp.Key == "db.statement"); Assert.Equal("SET", result.Attributes.GetValue("db.statement")); }
public void ProfiledCommandToSpanDataUsesFlagsForFlagsAttribute() { var profiledCommand = new Mock <IProfiledCommand>(); var expectedFlags = StackExchange.Redis.CommandFlags.FireAndForget | StackExchange.Redis.CommandFlags.NoRedirect; profiledCommand.Setup(m => m.Flags).Returns(expectedFlags); var result = RedisProfilerEntryToSpanConverter.ProfiledCommandToSpanData(SpanContext.Blank, "SET", SpanId.Invalid, profiledCommand.Object); Assert.Contains("redis.flags", result.Attributes.AttributeMap.Keys); Assert.Equal(AttributeValue.StringAttributeValue("None, FireAndForget, NoRedirect"), result.Attributes.AttributeMap["redis.flags"]); }
public void ShouldSampleRespectsSamplerChoice() { var m = new Mock <ISampler>(); m.Setup(x => x.ShouldSample(It.IsAny <ISpanContext>(), It.IsAny <bool>(), It.IsAny <ITraceId>(), It.IsAny <ISpanId>(), It.IsAny <string>(), It.IsAny <IEnumerable <ISpan> >())).Returns(true); Assert.True(RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", m.Object, out var context, out var parentId)); m = new Mock <ISampler>(); m.Setup(x => x.ShouldSample(It.IsAny <ISpanContext>(), It.IsAny <bool>(), It.IsAny <ITraceId>(), It.IsAny <ISpanId>(), It.IsAny <string>(), It.IsAny <IEnumerable <ISpan> >())).Returns(false); Assert.False(RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", m.Object, out context, out parentId)); }
public void ProfiledCommandToSpanUsesFlagsForFlagsAttribute() { var profiledCommand = new Mock <IProfiledCommand>(); profiledCommand.Setup(m => m.CommandCreated).Returns(DateTime.UtcNow); var expectedFlags = StackExchange.Redis.CommandFlags.FireAndForget | StackExchange.Redis.CommandFlags.NoRedirect; profiledCommand.Setup(m => m.Flags).Returns(expectedFlags); var result = ((Span)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, BlankSpan.Instance, profiledCommand.Object)); Assert.Contains(result.Attributes, kvp => kvp.Key == "redis.flags"); Assert.Equal("None, FireAndForget, NoRedirect", result.Attributes.GetValue("redis.flags")); }
public void DrainSessionUsesCommandAsName() { var parentSpan = BlankSpan.Instance; var profiledCommand = new Mock <IProfiledCommand>(); var sampler = new Mock <ISampler>(); sampler.Setup(x => x.ShouldSample(It.IsAny <SpanContext>(), It.IsAny <ActivityTraceId>(), It.IsAny <ActivitySpanId>(), It.IsAny <string>(), It.IsAny <IEnumerable <ILink> >())).Returns(true); profiledCommand.Setup(m => m.Command).Returns("SET"); var result = new List <SpanData>(); RedisProfilerEntryToSpanConverter.DrainSession(parentSpan, new IProfiledCommand[] { profiledCommand.Object }, sampler.Object, result); Assert.Single(result); Assert.Equal("SET", result[0].Name); }
public void ShouldSamplePassesArgumentsToSamplerAndReturnsInContext() { var m = new Mock <ISampler>(); var traceId = ActivityTraceId.CreateRandom(); var parentContext = SpanContext.Create(traceId, ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded, Tracestate.Builder.Set("a", "b").Build()); RedisProfilerEntryToSpanConverter.ShouldSample(parentContext, "SET", m.Object, out var context, out var parentId); m.Verify(x => x.ShouldSample( It.Is <SpanContext>(y => y == parentContext), It.Is <ActivityTraceId>(y => y == traceId && y == context.TraceId), It.Is <ActivitySpanId>(y => y != default && y == context.SpanId), It.Is <string>(y => y == "SET"), It.Is <IEnumerable <ILink> >(y => y == null))); }
public void ShouldSamplePassesArgumentsToSamplerAndReturnsInContext() { var m = new Mock <ISampler>(); var r = new RandomGenerator(); var traceId = TraceId.GenerateRandomId(r); var parentContext = SpanContext.Create(traceId, SpanId.GenerateRandomId(r), TraceOptions.Sampled, Tracestate.Builder.Set("a", "b").Build()); RedisProfilerEntryToSpanConverter.ShouldSample(parentContext, "SET", m.Object, out var context, out var parentId); m.Verify(x => x.ShouldSample( It.Is <SpanContext>(y => y == parentContext), It.Is <TraceId>(y => y == traceId && y == context.TraceId), It.Is <SpanId>(y => y.IsValid && y == context.SpanId), It.Is <string>(y => y == "SET"), It.Is <IEnumerable <ISpan> >(y => y == null))); }
public void ShouldSampleGeneratesNewTraceIdForInvalidContext() { var m = new Mock <ISampler>(); m.Setup(x => x.ShouldSample(It.IsAny <ISpanContext>(), It.IsAny <bool>(), It.IsAny <ITraceId>(), It.IsAny <ISpanId>(), It.IsAny <string>(), It.IsAny <IEnumerable <ISpan> >())).Returns((ISpanContext parentContext, bool hasRemoteParent, ITraceId traceId, ISpanId spanId, string name, IEnumerable <ISpan> parentLinks) => parentContext.TraceOptions.IsSampled); RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", m.Object, out var context, out var parentId); m.Verify(x => x.ShouldSample( It.Is <ISpanContext>(y => y == SpanContext.Blank), It.Is <bool>(y => y == false), It.Is <ITraceId>(y => y.IsValid && y == context.TraceId), It.Is <ISpanId>(y => y.IsValid && y == context.SpanId), It.Is <string>(y => y == "SET"), It.Is <IEnumerable <ISpan> >(y => y == null))); Assert.Equal(TraceOptions.Default, context.TraceOptions); }
public void ShouldSampleGeneratesNewTraceIdForInvalidContext() { var m = new Mock <ISampler>(); m.Setup(x => x.ShouldSample( It.IsAny <SpanContext>(), It.IsAny <ActivityTraceId>(), It.IsAny <ActivitySpanId>(), It.IsAny <string>(), It.IsAny <IEnumerable <ILink> >())).Returns((SpanContext parentContext, ActivityTraceId traceId, ActivitySpanId spanId, string name, IEnumerable <ISpan> parentLinks) => (parentContext.TraceOptions & ActivityTraceFlags.Recorded) != 0); RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", m.Object, out var context, out var parentId); m.Verify(x => x.ShouldSample( It.Is <SpanContext>(y => y == SpanContext.Blank), It.Is <ActivityTraceId>(y => y != default && y == context.TraceId), It.Is <ActivitySpanId>(y => y != default && y == context.SpanId), It.Is <string>(y => y == "SET"), It.Is <IEnumerable <ILink> >(y => y == null))); Assert.Equal(ActivityTraceFlags.None, context.TraceOptions); }
public void ShouldSampleDoesntThrowWithoutSampler() { RedisProfilerEntryToSpanConverter.ShouldSample(SpanContext.Blank, "SET", null, out var context, out var parentId); }