Represents a context for sending telemetry to the Application Insights service.
Inheritance: IJsonSerializable
コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CrashTelemetry" /> class.
        /// </summary>
        /// <param name="crash">The crash.</param>
        internal CrashTelemetry(CrashData crash)
        {
            this.Data = crash ?? new CrashData();
            if (this.Data.headers == null)
            {
                this.Data.headers = new CrashDataHeaders();
            }

            this.headers = new CrashTelemetryHeaders(this.Data.headers);
            this.adapterThreads = new AdapterList<CrashTelemetryThread, CrashDataThread>(
                                                                new List<CrashTelemetryThread>(),
                                                                this.Data.threads,
                                                                threadPublic => threadPublic == null ? null : threadPublic.Data,
                                                                threadPrivate => threadPrivate == null ? null : new CrashTelemetryThread(threadPrivate));
            this.adapterThreads.SyncPrivateToPublic();

            this.adapterBinaries = new AdapterList<CrashTelemetryBinary, CrashDataBinary>(
                                                                new List<CrashTelemetryBinary>(),
                                                                this.Data.binaries,
                                                                binaryPublic => binaryPublic == null ? null : binaryPublic.Data,
                                                                binaryPrivate => binaryPrivate == null ? null : new CrashTelemetryBinary(binaryPrivate));
            this.adapterBinaries.SyncPrivateToPublic();

            this.context = new TelemetryContext(new Dictionary<string, string>(), new Dictionary<string, string>());
            this.Attachments = new Attachments();
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MetricTelemetry"/> class with empty 
        /// properties.
        /// </summary>
        public MetricTelemetry()
        {
            this.Data = new MetricData();
            this.Metric = new DataPoint();
            this.context = new TelemetryContext(this.Data.properties, new Dictionary<string, string>());

            // We always have a single 'metric'.
            this.Data.metrics.Add(this.Metric);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RequestTelemetry"/> class.
        /// </summary>
        public RequestTelemetry()
        {
            this.Data = new RequestData();
            this.context = new TelemetryContext(this.Data.properties, new Dictionary<string, string>());

            // Initialize required fields
            this.Id = WeakConcurrentRandom.Instance.Next().ToString(CultureInfo.InvariantCulture);
            this.ResponseCode = "200";
            this.Success = true;
        }
コード例 #4
0
        public void OperationIsNotNullByDefaultToPreventNullReferenceExceptionsInUserCode()
        {
            var context = new TelemetryContext();

            Assert.NotNull(context.Operation);
        }
コード例 #5
0
        public void InstrumentationKeySetterThrowsArgumentNullExceptionWhenValueIsNullToPreventNullReferenceExceptionsLater()
        {
            var context = new TelemetryContext();

            Assert.Throws <ArgumentNullException>(() => context.InstrumentationKey = null);
        }
コード例 #6
0
 public void SerializeWritesCopiedComponentContext()
 {
     var context = new TelemetryContext();
     context.Component.Version = "Test Value";
     string json = CopyAndSerialize(context);
     Assert.Contains("\"" + ContextTagKeys.Keys.ApplicationVersion + "\":\"Test Value\"", json, StringComparison.OrdinalIgnoreCase);
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionTelemetry"/> class with empty properties.
 /// </summary>
 public ExceptionTelemetry()
 {
     this.Data      = new ExceptionData();
     this.context   = new TelemetryContext(this.Data.properties, new Dictionary <string, string>());
     this.HandledAt = default(ExceptionHandledAt);
 }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SessionStateTelemetry"/> class.
 /// </summary>
 public SessionStateTelemetry()
 {
     this.Data = new SessionStateData();
     this.context = new TelemetryContext(new Dictionary<string, string>(), new Dictionary<string, string>());
 }
コード例 #9
0
ファイル: SessionStateTelemetry.cs プロジェクト: kuggaa/VAS
 /// <summary>
 /// Initializes a new instance of the <see cref="SessionStateTelemetry"/> class.
 /// </summary>
 public SessionStateTelemetry()
 {
     this.Data    = new SessionStateData();
     this.context = new TelemetryContext(new Dictionary <string, string>(), new Dictionary <string, string>());
 }
コード例 #10
0
 public void InstrumentationKeySetterThrowsArgumentNullExceptionWhenValueIsNullToPreventNullReferenceExceptionsLater()
 {
     var context = new TelemetryContext();
     Assert.Throws<ArgumentNullException>(() => context.InstrumentationKey = null);
 }
コード例 #11
0
 public void ConstructorInitializesTagsWithThreadSafeDictionaryObjects()
 {
     var context = new TelemetryContext();
     Assert.IsType<SnapshottingDictionary<string, string>>(context.Tags);
 }
コード例 #12
0
 public void InstrumentationKeyIsNotNullByDefaultToPreventNullReferenceExceptionsInUserCode()
 {
     var context = new TelemetryContext();
     Assert.NotNull(context.InstrumentationKey);
 }
コード例 #13
0
        private static string CopyAndSerialize(TelemetryContext source)
        {
            // Create a copy of the source context to verify that Serialize writes property values stored in tags 
            // dictionary even if their context objects (User, Location, etc) haven't been initialized yet.
            var target = new TelemetryContext();
            target.Initialize(source, source.InstrumentationKey);

            using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                ((IJsonSerializable)target).Serialize(new JsonWriter(stringWriter));
                return stringWriter.ToString();
            }
        }
コード例 #14
0
 public void SerializeWritesCopiedSessionContext()
 {
     var context = new TelemetryContext();
     context.Session.Id = "Test Value";
     string json = CopyAndSerialize(context);
     Assert.Contains("\"" + ContextTagKeys.Keys.SessionId + "\":\"Test Value\"", json, StringComparison.OrdinalIgnoreCase);
 }
コード例 #15
0
 public void SerializeWritesCopiedLocationContext()
 {
     var context = new TelemetryContext();
     context.Location.Ip = "1.2.3.4";
     string json = CopyAndSerialize(context);
     Assert.Contains("\"" + ContextTagKeys.Keys.LocationIp + "\":\"1.2.3.4\"", json, StringComparison.OrdinalIgnoreCase);
 }
コード例 #16
0
        public void InternalIsNotNullByDefaultToPreventNullReferenceExceptionInUserCode()
        {
            TelemetryContext context = new TelemetryContext();

            Assert.NotNull(context.Internal);
        }
コード例 #17
0
 public void OperationIsNotNullByDefaultToPreventNullReferenceExceptionsInUserCode()
 {
     var context = new TelemetryContext();
     Assert.NotNull(context.Operation);
 }
コード例 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PageViewTelemetry"/> class.
 /// </summary>
 public PageViewTelemetry()
 {
     this.Data = new PageViewData();
     this.context = new TelemetryContext(this.Data.properties, new Dictionary<string, string>());
 }
コード例 #19
0
 public void InternalIsNotNullByDefaultToPreventNullReferenceExceptionInUserCode()
 {
     TelemetryContext context = new TelemetryContext();
     Assert.NotNull(context.Internal);
 }
コード例 #20
0
        internal void Initialize(TelemetryContext source, string instrumentationKey)
        {
            Property.Initialize(ref this.instrumentationKey, instrumentationKey);

            if (source.tags != null && source.tags.Count > 0)
            {
                Utils.CopyDictionary(source.tags, this.Tags);
            }
        }
コード例 #21
0
        public void InitializeCopiesTags()
        {
            string tagName = "TestTag";
            string tagValue = "TestValue";
            var source = new TelemetryContext { Tags = { { tagName, tagValue } } };
            var target = new TelemetryContext();

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal(tagValue, target.Tags[tagName]);
        }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TraceTelemetry"/> class.
 /// </summary>
 public TraceTelemetry()
 {
     this.Data = new MessageData();
     this.context = new TelemetryContext(this.Data.properties, new Dictionary<string, string>());
 }
コード例 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionTelemetry"/> class with empty properties.
 /// </summary>
 public ExceptionTelemetry()
 {
     this.Data = new ExceptionData();
     this.context = new TelemetryContext(this.Data.properties, new Dictionary<string, string>());
     this.HandledAt = default(ExceptionHandledAt);
 }
コード例 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DependencyTelemetry"/> class.
 /// </summary>
 public DependencyTelemetry()
 {
     this.Data = new RemoteDependencyData() { kind = DataPointType.Aggregation };
     this.context = new TelemetryContext(this.Data.properties, new Dictionary<string, string>());
     this.Data.dependencyKind = BondDependencyKind.Other;
 }
コード例 #25
0
        public void InitializeSetsTelemetryInstrumentationKeyFromArgument()
        {
            var source = new TelemetryContext { InstrumentationKey = "TestValue" };
            var target = new TelemetryContext();

            target.Initialize(source, "OtherTestValue");

            Assert.Equal("OtherTestValue", target.InstrumentationKey);
        }
コード例 #26
0
        public void ConstructorInitializesTagsWithThreadSafeDictionaryObjects()
        {
            var context = new TelemetryContext();

            Assert.IsType <SnapshottingDictionary <string, string> >(context.Tags);
        }
コード例 #27
0
        public void InitializeDoesNotOverrideTelemetryInstrumentationKey()
        {
            var source = new TelemetryContext { InstrumentationKey = "SourceValue" };
            var target = new TelemetryContext { InstrumentationKey = "TargetValue" };

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal("TargetValue", target.InstrumentationKey);
        }
コード例 #28
0
        public void InstrumentationKeyIsNotNullByDefaultToPreventNullReferenceExceptionsInUserCode()
        {
            var context = new TelemetryContext();

            Assert.NotNull(context.InstrumentationKey);
        }
コード例 #29
0
        public void InitializeDoesNotOverwriteTags()
        {
            string tagName = "TestTag";
            var source = new TelemetryContext { Tags = { { tagName, "Source Value" } } };
            var target = new TelemetryContext { Tags = { { tagName, "Target Value" } } };

            target.Initialize(source, source.InstrumentationKey);

            Assert.Equal("Target Value", target.Tags[tagName]);
        }