kiota icon indicating copy to clipboard operation
kiota copied to clipboard

Log to the output/log window

Open MIchaelMainer opened this issue 2 years ago • 5 comments

Generate output returns the log information so you can display that into the log window. Include model classes for logging the response results.

MIchaelMainer avatar Aug 08 '23 23:08 MIchaelMainer

@MIchaelMainer Thanks for creating the issue and the label. Don't hesitate to create additional issues if it help you or @Hossain2024 keep tracks of things and prioritizing work.

baywet avatar Aug 09 '23 13:08 baywet

@Hossain2024 When we add new backlog items, let's:

  1. Add them to the Kiota project,
  2. Set the Status to Todo,
  3. Set the Backlog milestone

These can be set in the right column of the issue interface. image

MIchaelMainer avatar Aug 09 '23 20:08 MIchaelMainer

I understand the complexities of building large scale developed software and I thank you and the community for your efforts.

When using this for the demos everything is perfect. However, when trying to use this against a real commercial API I am having issues.

I am unable to see any requests or response Data. I can't see why errors are being returned from the API and the logs are empty.

I am also unable to inject an ILogger into the Generated code, so I am going to give up using the CLI Generator and jump onto the standard C# generator. If that fails, it back to bear backing this beast.

The API am hitting is under development and is changing/erroring multiple times per day. This tool is great if the API is sold. But in real life this is not the case; or at least not in my world.

I am doing the following:

SHELL := /bin/bash

build:
	dotnet build --no-cache

send-full-quote: build
	dotnet run -- full-quote post --client-id=fluentmoney --client-secret=bob --body="$$(cat sample-request.json)"

I get

Unhandled exception: KiotaPostsCLI.Client.Models.ErrorResponse: Exception of type 'KiotaPostsCLI.Client.Models.ErrorResponse' wa
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, DictiotyForAttributes, CancellationToken cancellationToken)

So this tells me nothing... Adding the following monstrosity to the RequestBuilder

                try { 
                    var response = await reqAdapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping: errorMapping, cancellationToken: cancellationToken) ?? Stream.Null;
                    response = (response != Stream.Null) ? await outputFilter.FilterOutputAsync(response, query, cancellationToken) : response;
                    var formatter = outputFormatterFactory.GetFormatter(output);
                    await formatter.WriteOutputAsync(response, cancellationToken);

                } catch (Exception ex) {
                    throw new Exception($"Error getting response {ex.InnerException.Source}");
                    // Loop over all exceptions and store the messaghe and scourse into a string
                    var inner = ex.InnerException;
                    var message = string.Empty;
                    var source = string.Empty;
                    while (inner != null) {
                        message += inner.Message;
                        source += inner.Source;
                        inner = inner.InnerException;
                    }
                    throw new Exception($"Error getting response {message} {source}");

At least I got this...

dotnet run -- full-quote post --client-id=fluentmoney --client-secret=bob --body="$(cat sample-request.json)"
Unhandled exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at KiotaPostsCLI.Client.FullQuote.FullQuoteRequestBuilder.<>c__DisplayClass1_0.<<BuildPostCommand>b__1>d.MoveNext() in C:\dev\fluent.prototypes\Kiota\<removed>\src\Client\FullQuote\FullQuoteRequestBuilder.cs:line 87
--- End of stack trace from previous location ---

Allowing Logging and being able log the Request and Response would be amazing! Or at least to the console using an injected ILogger.

gpltaylor avatar Nov 18 '23 15:11 gpltaylor

@gpltaylor I only just now noticed that you wrote this - less than half an hour before I made this issue.

Your feedback here would be nice :)

KennethHoff avatar Nov 18 '23 18:11 KennethHoff

Hi everyone, Thanks for reaching out. This issue was originally dedicated to adding kiota generation log to the output window in the JetBrains integration we have started over the summer. Since another issue has been created on the other topic (see previous reply from @kennethHoff), let's all head over that issue and focus the discussions there.

baywet avatar Nov 20 '23 14:11 baywet

more information #6675

baywet avatar Jun 17 '25 13:06 baywet