/// <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); this.Data.dependencyKind = BondDependencyKind.Other; this.Id = Convert.ToBase64String(BitConverter.GetBytes(WeakConcurrentRandom.Instance.Next())); }
public void Initialize(TelemetryContext context) { context.User.Id = Environment.UserName; context.Session.Id = Guid.NewGuid().ToString(); context.Device.OperatingSystem = Environment.OSVersion.ToString(); context.Device.Language = CultureInfo.CurrentCulture.DisplayName; }
public static void WriteTelemetryContext(IJsonWriter json, TelemetryContext context) { if (context != null) { json.WriteProperty("iKey", context.InstrumentationKey); json.WriteProperty("tags", context.Tags); } }
/// <summary> /// Initializes the given <see cref="T:Microsoft.ApplicationInsights.DataContracts.TelemetryContext"/>. /// </summary> public void Initialize(TelemetryContext context) { if (context == null) return; if (string.IsNullOrWhiteSpace(context.Device.OperatingSystem)) context.Device.OperatingSystem = _osVersion.Value; }
/// <summary> /// Adds a telemetry property for the version of SDK. /// </summary> public void Initialize(TelemetryContext context) { var version = LazyInitializer.EnsureInitialized(ref this.sdkVersion, this.GetAssemblyVersion); if (string.IsNullOrEmpty(context.Internal.SdkVersion)) { context.Internal.SdkVersion = version; } }
public void InitializeSetsSdkVersionPropertyOfGivenTelemetry() { var initializer = new SdkVersionPropertyContextInitializer(); var telemetryContext = new TelemetryContext(); initializer.Initialize(telemetryContext); Assert.NotNull(telemetryContext.Internal.SdkVersion); }
/// <summary> /// Initializes the given <see cref="T:Microsoft.ApplicationInsights.DataContracts.TelemetryContext"/>. /// </summary> public void Initialize(TelemetryContext context) { if (context == null) return; if (string.IsNullOrWhiteSpace(context.Component.Version)) context.Component.Version = _applicationVersion; }
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); }
/// <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>()); this.Id = Convert.ToBase64String(BitConverter.GetBytes(WeakConcurrentRandom.Instance.Next())); this.ResponseCode = "200"; this.Success = true; }
public void InitializeSetsTelemetryInstrumentationKeyFromArgument() { var source = new TelemetryContext { InstrumentationKey = "TestValue" }; var target = new TelemetryContext(); target.Initialize(source, "OtherTestValue"); Assert.Equal("OtherTestValue", target.InstrumentationKey); }
/// <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); }
/// <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.Context.Operation.Id = WeakConcurrentRandom.Instance.Next().ToString(CultureInfo.InvariantCulture); this.ResponseCode = "200"; this.Success = true; }
public void Initialize(TelemetryContext context) { context.User.Id = Environment.UserName; context.Session.Id = Guid.NewGuid().ToString("D"); context.Device.Id = Environment.MachineName; context.Device.RoleInstance = Environment.MachineName; context.Device.OperatingSystem = Environment.OSVersion.ToString(); context.Component.Version = typeof(SessionInitializer).Assembly.GetName().Version.ToString(); context.Device.RoleName = Assembly.GetEntryAssembly().GetName().Name; }
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]); }
public void ContextInitializerDoesNotOverrideMachineName() { var source = new DomainNameRoleInstanceContextInitializer(); var telemetryContext = new TelemetryContext(); telemetryContext.Device.RoleInstance = "Test"; source.Initialize(telemetryContext); Assert.Equal("Test", telemetryContext.Device.RoleInstance); }
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]); }
/// <summary> /// Initializes a new instance of the <see cref="DomainNameRoleInstanceContextInitializer"/> class. /// </summary> public void Initialize(TelemetryContext context) { if (context == null) { // TODO: add diagnostics } if (string.IsNullOrEmpty(context.Device.RoleInstance)) { var name = LazyInitializer.EnsureInitialized(ref this.roleInstanceName, this.GetMachineName); context.Device.RoleInstance = name; } }
public void ReadingVersionWithNoManifestYieldsDefaultValue() { ComponentContextInitializer source = new ComponentContextInitializer(); var telemetryContext = new TelemetryContext(); Assert.Null(telemetryContext.Component.Version); using (new ManifestSaver()) { ComponentContextReader.Instance = new TestComponentContextReader(null); source.Initialize(telemetryContext); } Assert.Equal(ComponentContextReader.UnknownComponentVersion, telemetryContext.Component.Version); }
public void ReadingVersionWithNoIdentityElementYieldsDefaultValue() { ComponentContextInitializer source = new ComponentContextInitializer(); var telemetryContext = new TelemetryContext(); Assert.Null(telemetryContext.Component.Version); using (new ManifestSaver()) { XElement root = new XElement(XName.Get("Deployment", "http://schemas.microsoft.com/windowsphone/2012/deployment")); ComponentContextReader.Instance = new TestComponentContextReader(root); source.Initialize(telemetryContext); } Assert.Equal(ComponentContextReader.UnknownComponentVersion, telemetryContext.Component.Version); }
public void ReadingDeviceTypeYieldsCorrectValue() { DeviceContextInitializer source = new DeviceContextInitializer(); var telemetryContext = new TelemetryContext(); Assert.Null(telemetryContext.Device.Type); source.Initialize(telemetryContext); string expected = "Other"; #if SILVERLIGHT || WINDOWS_PHONE expected = "Phone"; #elif NET35 || NET40 || NET45 expected = "PC"; #endif Assert.Equal(expected, telemetryContext.Device.Type); }
public void ReadingDeviceUniqueIdYieldsCorrectValue() { DeviceContextInitializer source = new DeviceContextInitializer(); var telemetryContext = new TelemetryContext(); Assert.Null(telemetryContext.Device.Id); source.Initialize(telemetryContext); string id = telemetryContext.Device.Id; object uniqueId; DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId); using (SHA256 hasher = new SHA256Managed()) { Assert.Equal(Convert.ToBase64String(hasher.ComputeHash((byte[])uniqueId)), id); } }
public void RoleInstanceNameIsSetToDomainAndHost() { var source = new DomainNameRoleInstanceContextInitializer(); var telemetryContext = new TelemetryContext(); source.Initialize(telemetryContext); string hostName = Dns.GetHostName(); #if !dnxcore50 string domainName = IPGlobalProperties.GetIPGlobalProperties().DomainName; if (hostName.EndsWith(domainName, StringComparison.OrdinalIgnoreCase) == false) { hostName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", hostName, domainName); } #endif Assert.Equal(hostName, telemetryContext.Device.RoleInstance); }
public void InitializeSetsSdkVersionValueAsAssemblyVersion() { var initializer = new SdkVersionPropertyContextInitializer(); var telemetryContext = new TelemetryContext(); initializer.Initialize(telemetryContext); string expectedSdkVersion; #if !WINRT expectedSdkVersion = typeof(SdkVersionPropertyContextInitializer).Assembly.GetCustomAttributes(false) .OfType<AssemblyFileVersionAttribute>() .First() .Version; #else expectedSdkVersion = typeof(SdkVersionPropertyContextInitializer).GetTypeInfo().Assembly.GetCustomAttributes<AssemblyFileVersionAttribute>() .First() .Version; #endif Assert.Equal(telemetryContext.Internal.SdkVersion, expectedSdkVersion); }
public void ReadingDeviceUniqueIdYieldsStableValue() { DeviceContextInitializer source = new DeviceContextInitializer(); var telemetryContext = new TelemetryContext(); Assert.Null(telemetryContext.Device.Id); source.Initialize(telemetryContext); string id = telemetryContext.Device.Id; Assert.Equal(false, id.IsNullOrWhiteSpace()); // clear the fallback context and expect the same result DeviceContextReader.Instance = new DeviceContextReader(); telemetryContext.Device.Id = string.Empty; // second run source.Initialize(telemetryContext); Assert.Equal(id, telemetryContext.Device.Id); }
public void Initialize(TelemetryContext context) { context.Component.Version = Application.ProductVersion; context.Device.Language = CultureInfo.CurrentUICulture.IetfLanguageTag; context.Device.OperatingSystem = Environment.OSVersion.ToString(); string screenResolutionData = GetScreenResolutionData(); context.Device.ScreenResolution = screenResolutionData; context.Properties.Add("64BitOS", Environment.Is64BitOperatingSystem.ToString()); context.Properties.Add("64BitProcess", Environment.Is64BitProcess.ToString()); context.Properties.Add("MachineName", Environment.MachineName); context.Properties.Add("ProcessorCount", Environment.ProcessorCount.ToString()); context.Properties.Add("ClrVersion", Environment.Version.ToString()); context.Session.Id = DateTime.Now.ToFileTime().ToString(); context.Session.IsFirst = true; context.User.AccountId = Environment.UserDomainName; context.User.Id = Environment.UserName; }
public void InstrumentationKeyIsNotNullByDefaultToPreventNullReferenceExceptionsInUserCode() { var context = new TelemetryContext(); Assert.IsNotNull(context.InstrumentationKey); }
public void InternalIsNotNullByDefaultToPreventNullReferenceExceptionInUserCode() { TelemetryContext context = new TelemetryContext(); Assert.IsNotNull(context.Internal); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionTelemetry"/> class with empty properties. /// </summary> public ExceptionTelemetry() { this.Data = new ExceptionInfo(new ExceptionData()); this.context = new TelemetryContext(this.Data.Properties); }
/// <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>()); }
/// <summary> /// Initializes a new instance of the <see cref="DependencyTelemetry"/> class. /// </summary> public DependencyTelemetry() { this.InternalData = new RemoteDependencyData(); this.context = new TelemetryContext(this.InternalData.properties); this.Id = Convert.ToBase64String(BitConverter.GetBytes(WeakConcurrentRandom.Instance.Next())); }
/// <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); }
public void UserIsNotNullByDefaultToPreventNullReferenceExceptionsInUserCode() { var context = new TelemetryContext(); Assert.IsNotNull(context.User); }
public void LocationIsNotNullByDefaultToPreventNullReferenceExceptionInUserCode() { TelemetryContext context = new TelemetryContext(); Assert.NotNull(context.Location); }
/// <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>()); this.Id = Convert.ToBase64String(BitConverter.GetBytes(WeakConcurrentRandom.Instance.Next())); }
/// <summary> /// Initializes a new instance of the <see cref="EventTelemetry"/> class. /// </summary> public EventTelemetry() { this.Data = new EventData(); this.context = new TelemetryContext(this.Data.properties); }
/// <summary> /// Initializes a new instance of the <see cref="SessionStateTelemetry"/> class. /// </summary> public SessionStateTelemetry() { this.Data = new SessionStateData(); this.context = new TelemetryContext(); }
/// <summary> /// Initializes a new instance of the <see cref="AvailabilityTelemetry"/> class with empty properties. /// </summary> public AvailabilityTelemetry() { this.Data = new AvailabilityData(); this.context = new TelemetryContext(this.Data.properties); this.Data.testRunId = Convert.ToBase64String(BitConverter.GetBytes(WeakConcurrentRandom.Instance.Next())); }
/// <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>()); }
public void InstrumentationKeySetterThrowsArgumentNullExceptionWhenValueIsNullToPreventNullReferenceExceptionsLater() { var context = new TelemetryContext(); AssertEx.Throws <ArgumentNullException>(() => context.InstrumentationKey = null); }
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); } }
public void FlagsIsZeroByDefault() { var context = new TelemetryContext(); Assert.AreEqual(0, context.Flags); }
private static void PopulateTelemetryContext( IDictionary <string, string> dimensions, Microsoft.ApplicationInsights.DataContracts.TelemetryContext telemetryContext, out IEnumerable <KeyValuePair <string, string> > nonContextDimensions) { if (dimensions == null) { nonContextDimensions = null; return; } List <KeyValuePair <string, string> > nonContextDimensionList = null; foreach (KeyValuePair <string, string> dimension in dimensions) { if (String.IsNullOrWhiteSpace(dimension.Key) || dimension.Value == null) { continue; } switch (dimension.Key) { case MetricDimensionNames.TelemetryContext.InstrumentationKey: telemetryContext.InstrumentationKey = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Cloud.RoleInstance: telemetryContext.Cloud.RoleInstance = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Cloud.RoleName: telemetryContext.Cloud.RoleName = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Component.Version: telemetryContext.Component.Version = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Device.Id: telemetryContext.Device.Id = dimension.Value; break; #pragma warning disable CS0618 // Type or member is obsolete case MetricDimensionNames.TelemetryContext.Device.Language: telemetryContext.Device.Language = dimension.Value; break; #pragma warning restore CS0618 // Type or member is obsolete case MetricDimensionNames.TelemetryContext.Device.Model: telemetryContext.Device.Model = dimension.Value; break; #pragma warning disable CS0618 // Type or member is obsolete case MetricDimensionNames.TelemetryContext.Device.NetworkType: telemetryContext.Device.NetworkType = dimension.Value; break; #pragma warning restore CS0618 // Type or member is obsolete case MetricDimensionNames.TelemetryContext.Device.OemName: telemetryContext.Device.OemName = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Device.OperatingSystem: telemetryContext.Device.OperatingSystem = dimension.Value; break; #pragma warning disable CS0618 // Type or member is obsolete case MetricDimensionNames.TelemetryContext.Device.ScreenResolution: telemetryContext.Device.ScreenResolution = dimension.Value; break; #pragma warning restore CS0618 // Type or member is obsolete case MetricDimensionNames.TelemetryContext.Device.Type: telemetryContext.Device.Type = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Location.Ip: telemetryContext.Location.Ip = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Operation.CorrelationVector: telemetryContext.Operation.CorrelationVector = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Operation.Id: telemetryContext.Operation.Id = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Operation.Name: telemetryContext.Operation.Name = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Operation.ParentId: telemetryContext.Operation.ParentId = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Operation.SyntheticSource: telemetryContext.Operation.SyntheticSource = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Session.Id: telemetryContext.Session.Id = dimension.Value; break; case MetricDimensionNames.TelemetryContext.Session.IsFirst: try { telemetryContext.Session.IsFirst = System.Convert.ToBoolean(dimension.Value, CultureInfo.InvariantCulture); } catch { try { int val = System.Convert.ToInt32(dimension.Value, CultureInfo.InvariantCulture); if (val == 1) { telemetryContext.Session.IsFirst = true; } else if (val == 0) { telemetryContext.Session.IsFirst = false; } } catch { } } break; case MetricDimensionNames.TelemetryContext.User.AccountId: telemetryContext.User.AccountId = dimension.Value; break; case MetricDimensionNames.TelemetryContext.User.AuthenticatedUserId: telemetryContext.User.AuthenticatedUserId = dimension.Value; break; case MetricDimensionNames.TelemetryContext.User.Id: telemetryContext.User.Id = dimension.Value; break; case MetricDimensionNames.TelemetryContext.User.UserAgent: telemetryContext.User.UserAgent = dimension.Value; break; default: string dimensionName; if (MetricDimensionNames.TelemetryContext.IsProperty(dimension.Key, out dimensionName)) { telemetryContext.GlobalProperties[dimensionName] = dimension.Value; } else { if (nonContextDimensionList == null) { nonContextDimensionList = new List <KeyValuePair <string, string> >(dimensions.Count); } nonContextDimensionList.Add(dimension); } break; } } nonContextDimensions = nonContextDimensionList; }
/// <summary> /// Initializes a new instance of the <see cref="DependencyTelemetry"/> class. /// </summary> public DependencyTelemetry() { this.InternalData = new RemoteDependencyData(); this.context = new TelemetryContext(this.InternalData.properties); this.GenerateId(); }
/// <summary> /// Initializes a new instance of the <see cref="EventTelemetry"/> class. /// </summary> public EventTelemetry() { this.Data = new EventData(); this.context = new TelemetryContext(this.Data.properties, new Dictionary<string, string>()); }
public void ConstructorInitializesTagsWithThreadSafeDictionaryObjects() { var context = new TelemetryContext(); Assert.IsType <SnapshottingDictionary <string, string> >(context.Tags); }
/// <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); this.GenerateId(); }
private TelemetryContext CreateInitializedContext() { var context = new TelemetryContext(); foreach (IContextInitializer initializer in this.configuration.ContextInitializers) { initializer.Initialize(context); } return context; }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="PerformanceCounterTelemetry"/> class. /// </summary> public PerformanceCounterTelemetry() { this.Data = new PerformanceCounterData(); this.context = new TelemetryContext(this.Data.properties); }
/// <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); }
/// <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>()); }
/// <summary> /// Initializes a new instance of the <see cref="PageViewTelemetry"/> class by cloning an existing instance. /// </summary> /// <param name="source">Source instance of <see cref="PageViewTelemetry"/> to clone from.</param> private PageViewTelemetry(PageViewTelemetry source) { this.Data = source.Data.DeepClone(); this.context = source.context.DeepClone(this.Data.properties); this.extension = source.extension?.DeepClone(); }
/// <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); this.HandledAt = default(ExceptionHandledAt); }