Beispiel #1
0
 // This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
 protected override void BeginProcessing()
 {
     _telemetryClient = MyTelemetryClient.getInstance();
     _stringBuilder   = new StringBuilder();
     _properties      = new Dictionary <string, string>();
     _functionName    = FunctionName;
 }
Beispiel #2
0
        // This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
        protected override void BeginProcessing()
        {
            _telemetryClient = MyTelemetryClient.getInstance();
            _stringBuilder   = new StringBuilder();
            _properties      = new Dictionary <string, string>();

            // if we have $MyInvocation we can get the function name - it is not in the ErrorRecord somewhere?
            // user can also provide a function name as input, which takes precedence
            _functionName = String.IsNullOrEmpty(FunctionName) ? (MyInvocation != null ? MyInvocation.MyCommand.ToString() : null) : FunctionName;

            // if function name is greater than 256 characters or contains a space then it may come from
            // a runspace (ex. Azure Function App)
            if (_functionName.Length > 256 || _functionName.Contains(" "))
            {
                WriteVerbose("_functionName invalid (too long or contains spaces), are you calling from a runspace?");
                _functionName = String.IsNullOrEmpty(FunctionName) ? null : FunctionName;
            }

            // we put these into the properties dictionary
            _scriptLineNumber = ErrorRecord.InvocationInfo.ScriptLineNumber;
            _scriptName       = ErrorRecord.InvocationInfo.ScriptName;
            _line             = ErrorRecord.InvocationInfo.Line;
            _stackTrace       = ErrorRecord.Exception.StackTrace;
            _exception        = ErrorRecord.Exception;

            _customMessage = String.IsNullOrEmpty(Message) ? ErrorRecord.Exception.Message : Message;
        } // end BeginProcessing
Beispiel #3
0
 // This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
 protected override void BeginProcessing()
 {
     //WriteVerbose("Begin!");
     //StaticStuff.InstrumentationKey = InstrumentationKey;
     // create new telemetry client and add the instrumentation key
     _telemetryClient = MyTelemetryClient.getInstance();
     _telemetryClient.InstrumentationKey = InstrumentationKey;
 }
Beispiel #4
0
 // This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called
 protected override void ProcessRecord()
 {
     // TODO: custom events as json input, ex. Found 960 users in AAD should be - EventName = Found users in AAD and a custom input @{"UsersFound" = 960}
     MyTelemetryClient.PopulateProperties(_properties, _functionName);
     //WriteVerbose("Process!");
     _telemetryClient.TrackEvent(
         EventName, _properties
         );
 }
Beispiel #5
0
        } // end ExceptionMessage

        // This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called
        protected override void ProcessRecord()
        {
            WriteVerbose("Populating properties...");
            MyTelemetryClient.PopulateProperties(_properties, _scriptName, _scriptLineNumber, _functionName, _stackTrace, _exception);

            string msg = ExceptionMessage();

            WriteVerbose("\nException message:\n" + msg);

            // often of type RuntimeException in PowerShell?
            WriteVerbose("Exception is of type " + _exception.GetType());

            /*
             * TODO: look at type of ErrorRecord.Exception and create exception of same type.
             * Can maybe use some reflection to do this?
             * Activator.CreateInstance ?
             * maybe cast to the respective type?
             *
             *
             * If we just use ErrorRecord.Exception instead of creating a new Exception
             * it is always System.Exception in the AI portal
             * and the message is: Exception of type 'System.Exception' was thrown
             * this is why we are rolling our own here
             */
            Exception exception = new Exception(
                msg
                );

            /*
             * TODO:
             * Failed method - is in the portal, how do we input that?
             */

            WriteVerbose("Tracking exception");
            _telemetryClient.TrackException(
                exception,
                _properties
                );
        } // end ProcessRecord
Beispiel #6
0
        } // end PopulateProperties

        public static void PopulateProperties(IDictionary <string, string> properties, String functionName)
        {
            MyTelemetryClient.PopulateProperties(properties, null, -1, functionName, null, null);
        } // end PopulateProperties