Example #1
0
        public override void GenerateLogMethodBody(LoggingSite site, Func <string> getMessageExpression)
        {
            m_codeGenerator.Ln("if ({0}.AriaV2StaticState.IsEnabled)", GlobalInstrumentationNamespaceCommon);
            using (m_codeGenerator.Br)
            {
                m_codeGenerator.Lns("var eventData = new {0}.AriaEvent(\"{1}\", \"{2}\", \"{3}\")", GlobalInstrumentationNamespaceCommon, site.Method.Name, m_targetFramework, m_targetRuntime);

                // Save context fields that all events save
                m_codeGenerator.Lns("eventData.SetProperty(\"Environment\", {0}.Session.Environment)", site.LoggingContextParameterName);
                m_codeGenerator.Lns("eventData.SetProperty(\"SessionId\", {0}.Session.Id)", site.LoggingContextParameterName);
                m_codeGenerator.Lns("eventData.SetProperty(\"RelatedSessionId\", {0}.Session.RelatedId)", site.LoggingContextParameterName);

                // We only capture the username for MS internal
                m_codeGenerator.Ln("if ({0}.UserName.IsInternalCollectionAllowed)", GlobalInstrumentationNamespaceCommon);
                using (m_codeGenerator.Br)
                {
                    m_codeGenerator.Lns("eventData.SetProperty(\"UserName\", EngineEnvironmentSettings.BuildXLUserName.Value ?? Environment.UserName)");
                    m_codeGenerator.Lns("eventData.SetProperty(\"MachineName\", Environment.MachineName)");
                }

                m_codeGenerator.Lns("eventData.SetProperty(\"User\", EngineEnvironmentSettings.BuildXLUserName.Value ?? Environment.UserName, {0}.PiiType.Identity)", GlobalInstrumentationNamespaceCommon);

                foreach (var item in site.FlattenedPayload)
                {
                    WritePayload(site, item);
                }

                m_codeGenerator.Ln("eventData.Log();");
            }
        }
Example #2
0
 /// <inheritdoc/>
 public override void GenerateLogMethodBody(LoggingSite site, Func <string> getMessageExpression)
 {
     foreach (var item in site.FlattenedPayload)
     {
         if (IsCompatibleNumeric(item.Type))
         {
             m_codeGenerator.Ln("BuildXL.Tracing.ETWLogger.Log.Statistic({0}.Session.RelatedActivityId, \"{1}_{2}\", (long){3});", site.LoggingContextParameterName, site.Method.Name, item.AddressForTelemetryString, item.Address);
         }
         else if (item.Type.SpecialType == SpecialType.System_UInt64)
         {
             m_errorReport.ReportError(site.Method, "Numeric payload member {0} not being logged as a statistic because it may overflow when cast to a long.", item.Address);
         }
         else
         {
             IPropertySymbol key;
             IPropertySymbol value;
             if (AriaV2.TryGetEnumerableKeyValuePair(item, out key, out value) &&
                 key.Type.SpecialType == SpecialType.System_String &&
                 IsCompatibleNumeric(value.Type))
             {
                 m_codeGenerator.Ln("foreach (var item in {0})", item.Address);
                 using (m_codeGenerator.Br)
                 {
                     // This directly calls the ETWLogger to make sure a Statistic event is logged to ensure all
                     // statistics, whether they are logged with the bulk call or not, get to the same ETW event.
                     m_codeGenerator.Ln("BuildXL.Tracing.ETWLogger.Log.Statistic({0}.Session.RelatedActivityId, \"{1}\" + item.Key, (long)item.Value);", site.LoggingContextParameterName, ComputeKeyPrefix(site));
                 }
             }
         }
     }
 }
Example #3
0
        public static string ComputeKeyPrefix(LoggingSite site)
        {
            if (!site.Method.Name.Equals("BulkStatistic", StringComparison.OrdinalIgnoreCase))
            {
                return(site.Method.Name + "_");
            }

            return(string.Empty);
        }
Example #4
0
        /// <inheritdoc/>
        public override void GenerateLogMethodBody(LoggingSite site, Func <string> getMessageExpression)
        {
            var locationParameter = GetLocationParameter(site);

            m_codeGenerator.Ln("if ({0})", nameof(LoggerBase.InspectMessageEnabled));
            using (m_codeGenerator.Br)
            {
                m_codeGenerator.Ln("{0}({1}, EventLevel.{2}, {3}, {4});", InspectMessageFunctionName, site.Id, site.Level, getMessageExpression(), locationParameter);
            }
            m_codeGenerator.Ln();
        }
Example #5
0
        private void WritePayload(LoggingSite site, LoggingSite.AddressedType item)
        {
            if (item.Type.SpecialType == SpecialType.System_String)
            {
                m_codeGenerator.Ln("eventData.SetProperty({0}.AriaV2StaticState.ScrubEventProperty(\"{1}\"), {2});", GlobalInstrumentationNamespaceCommon, item.AddressForTelemetryString, item.Address);
                return;
            }
            else if (IsCompatibleNumeric(item.Type))
            {
                m_codeGenerator.Ln("eventData.SetProperty({0}.AriaV2StaticState.ScrubEventProperty(\"{1}\"), (long){2});", GlobalInstrumentationNamespaceCommon, item.AddressForTelemetryString, item.Address);
                return;
            }
            else if (item.Type.TypeKind == TypeKind.Enum)
            {
                m_codeGenerator.Ln("eventData.SetProperty({0}.AriaV2StaticState.ScrubEventProperty(\"{1}\"), (long){2});", GlobalInstrumentationNamespaceCommon, item.AddressForTelemetryString, item.Address);
                m_codeGenerator.Ln("eventData.SetProperty({0}.AriaV2StaticState.ScrubEventProperty(\"{1}\"), {2}.ToString());", GlobalInstrumentationNamespaceCommon, item.AddressForTelemetryString, item.Address);
                return;
            }
            else if (item.Type.SpecialType == SpecialType.System_Boolean)
            {
                m_codeGenerator.Ln("eventData.SetProperty({0}.AriaV2StaticState.ScrubEventProperty(\"{1}\"), {2}.ToString());", GlobalInstrumentationNamespaceCommon, item.AddressForTelemetryString, item.Address);
                return;
            }
            else
            {
                IPropertySymbol key;
                IPropertySymbol value;
                if (TryGetEnumerableKeyValuePair(item, out key, out value) &&
                    key.Type.SpecialType == SpecialType.System_String &&
                    (value.Type.SpecialType == SpecialType.System_String || IsCompatibleNumeric(value.Type)))
                {
                    m_codeGenerator.Ln("foreach (var item in {0})", item.Address);
                    using (m_codeGenerator.Br)
                    {
                        if (value.Type.SpecialType == SpecialType.System_String)
                        {
                            m_codeGenerator.Ln("eventData.SetProperty({0}.AriaV2StaticState.ScrubEventProperty(item.Key), item.Value);", GlobalInstrumentationNamespaceCommon);
                        }
                        else
                        {
                            m_codeGenerator.Ln("eventData.SetProperty({0}.AriaV2StaticState.ScrubEventProperty(item.Key), (long)item.Value);", GlobalInstrumentationNamespaceCommon);
                        }
                    }

                    return;
                }
            }

            m_errorReport.ReportError(site.Method, "{0}'s type is not supported by the AriaV2 generator", item.Address);
        }
        /// <inheritdoc/>
        public override void GenerateLogMethodBody(LoggingSite site, Func <string> getMessageExpression)
        {
            m_codeGenerator.Ln("if ({0}.ETWLogger.Log.IsEnabled({1}, (EventKeywords){2}))", m_globalNamespace, CreateEventLevel(site.Level), site.EventKeywords);
            using (m_codeGenerator.Br)
            {
                var relatedActivityIdArg = site.EventOpcode == (int)EventOpcode.Start ?
                                           $"{site.LoggingContextParameterName}.ParentActivityId" :
                                           $"{site.LoggingContextParameterName}.Session.RelatedActivityId";

                m_codeGenerator.Ln(
                    "{0}.ETWLogger.Log.{1}({2}{3}{4});",
                    m_globalNamespace,
                    site.Method.Name,
                    relatedActivityIdArg,
                    site.FlattenedPayload.Count > 0 ? ", " : string.Empty,
                    site.GetFlattenedPayloadArgs());
            }
        }
Example #7
0
 public override void GenerateLogMethodBody(LoggingSite site, Func <string> getMessageExpression)
 {
 }
Example #8
0
        private static string GetLocationParameter(LoggingSite site)
        {
            var location = site.Payload.FirstOrDefault(p => p.Type.ToDisplayString(s_symbolDisplayFormat) == "BuildXL.Utilities.Instrumentation.Common.Location");

            return(location?.Name ?? "null");
        }