Telemetry type used for log messages. Contains a time and message and optionally some additional metadata.
Inheritance: ITelemetry, ISupportProperties
 public void ConstructorInitializesTraceTelemetryInstanceWithGivenMessageAndSeverityLevel()
 {
     var trace = new TraceTelemetry("TestMessage", SeverityLevel.Critical);
     Assert.NotNull(trace.Context);
     Assert.NotNull(trace.Properties);
     Assert.Equal("TestMessage", trace.Message);
     Assert.Equal(SeverityLevel.Critical, trace.SeverityLevel);
 }
 public void ConstructorInitializesTraceTelemetryInstanceWithGivenMessage()
 {
     var item = new TraceTelemetry("TestMessage");
     Assert.NotNull(item.Context);
     Assert.NotNull(item.Properties);
     Assert.Equal("TestMessage", item.Message);
     Assert.Null(item.SeverityLevel);
 }
 public void ConstructorInitializesDefaultTraceTelemetryInstance()
 {
     var item = new TraceTelemetry();
     Assert.NotNull(item.Context);
     Assert.NotNull(item.Properties);
     Assert.Empty(item.Message);
     Assert.Null(item.SeverityLevel);
 }
        public void SerializeWritesItemSeverityLevelAsExpectedByEndpoint()
        {
            var expected = new TraceTelemetry { SeverityLevel = SeverityLevel.Information };
            ((ITelemetry)expected).Sanitize();

            var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem<TraceTelemetry, DataPlatformModel.MessageData>(expected);
            
            Assert.Equal(Developer.Analytics.DataCollection.Model.v2.SeverityLevel.Information, item.Data.BaseData.SeverityLevel.Value);
        }
        public void SerializeWritesNullValuesAsExpectedByEndpoint()
        {
            TraceTelemetry original = new TraceTelemetry();
            original.Message = null;
            original.SeverityLevel = null;
            ((ITelemetry)original).Sanitize();
            var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem<TraceTelemetry, DataPlatformModel.MessageData>(original);

            Assert.Equal(2, item.Data.BaseData.Ver);
        }
        public void TraceTelemetrySerializesToJsonCorrectly()
        {
            var expected = new TraceTelemetry();
            expected.Message = "My Test";
            expected.Properties.Add("Property2", "Value2");

            var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem<TraceTelemetry, DataPlatformModel.MessageData>(expected);

            // NOTE: It's correct that we use the v1 name here, and therefore we test against it.
            Assert.Equal(item.Name, Microsoft.Developer.Analytics.DataCollection.Model.v1.ItemType.Message);
            Assert.Equal(typeof(DataPlatformModel.MessageData).Name, item.Data.BaseType);
            Assert.Equal(2, item.Data.BaseData.Ver);
            Assert.Equal(expected.Message, item.Data.BaseData.Message);
            Assert.Equal(expected.Properties.ToArray(), item.Data.BaseData.Properties.ToArray());
        }
        public void SanitizeWillTrimAppropriateFields()
        {
            TraceTelemetry telemetry = new TraceTelemetry();
            telemetry.Message = new string('X', Property.MaxMessageLength + 1);
            telemetry.Properties.Add(new string('X', Property.MaxDictionaryNameLength) + 'X', new string('X', Property.MaxValueLength + 1));
            telemetry.Properties.Add(new string('X', Property.MaxDictionaryNameLength) + 'Y', new string('X', Property.MaxValueLength + 1));

            ((ITelemetry)telemetry).Sanitize();

            Assert.Equal(new string('X', Property.MaxMessageLength), telemetry.Message);
            Assert.Equal(2, telemetry.Properties.Count);
            Assert.Equal(new string('X', Property.MaxDictionaryNameLength), telemetry.Properties.Keys.ToArray()[0]);
            Assert.Equal(new string('X', Property.MaxValueLength), telemetry.Properties.Values.ToArray()[0]);
            Assert.Equal(new string('X', Property.MaxDictionaryNameLength - 3) + "001", telemetry.Properties.Keys.ToArray()[1]);
            Assert.Equal(new string('X', Property.MaxValueLength), telemetry.Properties.Values.ToArray()[1]);
        }
        public void SanitizePopulatesMessageWithErrorBecauseItIsRequiredByEndpoint()
        {
            var telemetry = new TraceTelemetry { Message = null };

            ((ITelemetry)telemetry).Sanitize();
            
            Assert.Contains("message", telemetry.Message, StringComparison.OrdinalIgnoreCase);
            Assert.Contains("required", telemetry.Message, StringComparison.OrdinalIgnoreCase);
        }