Exceptionless.Net icon indicating copy to clipboard operation
Exceptionless.Net copied to clipboard

Improved ServiceStack support

Open niemyjski opened this issue 8 years ago • 11 comments

Out of the box it's kind of a pain to integrate with service stack (http://stackoverflow.com/questions/43526051/third-party-exception-handling-hooks-for-servicestack-asp-net-core). We should have a section talking about it or even a nuget package that makes it easier...

ServiceExceptionHandlers.Add((httpReq, request, exception) => {
var contextData = new ContextData();
contextData.MarkAsUnhandledError();
contextData.SetSubmissionMethod("ServiceExceptionHandlers");
exception.ToExceptionless(contextData).Submit(); // TODO: figure out how to get the http context here for extra metadata.

return null; //continue with default Error Handling
});

//Handle Unhandled Exceptions occurring outside of Services
//E.g. Exceptions during Request binding or in filters:
UncaughtExceptionHandlers.Add((req, res, operationName, ex) => {
var contextData = new ContextData();
contextData.MarkAsUnhandledError();
contextData.SetSubmissionMethod("UncaughtExceptionHandlers");
ex.ToExceptionless(contextData).SetProperty("Operation", operationName).Submit(); // TODO: figure out how to get the http context here for extra metadata.

// TODO: See if we have to do this,, rather just fallback and let them handle it.
res.Write("Error: {0}: {1}".Fmt(ex.GetType().Name, ex.Message));
res.EndRequest(skipHeaders: true);
});

And we could do a custom logger:

container.Register<ILog>(new ExceptionlessLogger ());
...
public class ExceptionlessLogger : ILog
    {
        public bool IsDebugEnabled
        {
            get
            {
                return true;
            }
        }

        public void Debug(object message)
        {
            ExceptionlessClient.Default.CreateLog("Debug", LogLevel.Debug).AddObject(message).Submit();
        }

        public void Debug(object message, Exception exception)
        {
            ExceptionlessClient.Default.CreateLog("Debug", LogLevel.Debug).AddObject(message).AddObject(exception).Submit();
        }

        public void DebugFormat(string format, params object[] args)
        {
            throw new NotImplementedException();
        }

        public void Error(object message)
        {
            ExceptionlessClient.Default.CreateLog(message.ToString()).AddObject(message).Submit();
        }

        public void Error(object message, Exception exception)
        {
            ExceptionlessClient.Default.CreateLog(message.ToString(), LogLevel.Error).AddObject(exception).Submit();
        }

        public void ErrorFormat(string format, params object[] args)
        {
            throw new NotImplementedException();
        }

        public void Fatal(object message)
        {
            ExceptionlessClient.Default.CreateLog("Fatal", LogLevel.Fatal).AddObject(message).Submit();
        }

        public void Fatal(object message, Exception exception)
        {
            ExceptionlessClient.Default.CreateLog("Fatal", LogLevel.Error).AddObject(message).AddObject(exception).Submit();
        }

        public void FatalFormat(string format, params object[] args)
        {
            throw new NotImplementedException();
        }

        public void Info(object message)
        {
            ExceptionlessClient.Default.CreateLog("Info", LogLevel.Info).AddObject(message).Submit();
        }

        public void Info(object message, Exception exception)
        {
            ExceptionlessClient.Default.CreateLog("Info", LogLevel.Info).AddObject(message).AddObject(exception).Submit();
        }

        public void InfoFormat(string format, params object[] args)
        {
            throw new NotImplementedException();
        }

        public void Warn(object message)
        {
            ExceptionlessClient.Default.CreateLog("Warn", LogLevel.Warn).AddObject(message).Submit();
        }

        public void Warn(object message, Exception exception)
        {
            ExceptionlessClient.Default.CreateLog("Warn", LogLevel.Warn).AddObject(message).AddObject(exception).Submit();
        }

        public void WarnFormat(string format, params object[] args)
        {
            throw new NotImplementedException();
        }
    }

niemyjski avatar Apr 20 '17 17:04 niemyjski

i think this:

// TODO: figure out how to get the http context here for extra metadata.

can be had from interacting with 'base.'

EricZimmerman avatar Apr 20 '17 18:04 EricZimmerman

@EricZimmerman is there any chance you could look into this? We might need to shred the request info like we do our other plugins and add a service stack plugin for getting user and request info.

niemyjski avatar Apr 20 '17 18:04 niemyjski

@EricZimmerman have you made any more changes to this?

niemyjski avatar Sep 20 '17 23:09 niemyjski

Not recently. The last time I used it I still saw timeouts here and there tho.

On Sep 20, 2017 6:31 PM, "Blake Niemyjski" [email protected] wrote:

@EricZimmerman https://github.com/ericzimmerman have you made any more changes to this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/exceptionless/Exceptionless.Net/issues/152#issuecomment-331009231, or mute the thread https://github.com/notifications/unsubscribe-auth/AEEVJvcqimrtlmQmPINa3Be99DB0kGBTks5skaA9gaJpZM4NDWhg .

EricZimmerman avatar Sep 20 '17 23:09 EricZimmerman

What kind of timeouts?

niemyjski avatar Sep 20 '17 23:09 niemyjski

Same as before. I call the rest API 3 times and it times out.

On Sep 20, 2017 6:40 PM, "Blake Niemyjski" [email protected] wrote:

What kind of timeouts?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/exceptionless/Exceptionless.Net/issues/152#issuecomment-331010621, or mute the thread https://github.com/notifications/unsubscribe-auth/AEEVJo19ZKZYWgiwgT1-HlZPO--MteVjks5skaJ2gaJpZM4NDWhg .

EricZimmerman avatar Sep 20 '17 23:09 EricZimmerman

I really wish we could get this under a unit test using the native http client, because that is crazy behavior.

niemyjski avatar Sep 21 '17 12:09 niemyjski

Have you followed up with service stack to see if they have seen this issue before?

niemyjski avatar Sep 21 '17 12:09 niemyjski

I haven't but I've moved billions of messages across it in other projects.

On Sep 21, 2017 7:49 AM, "Blake Niemyjski" [email protected] wrote:

Have you followed up with service stack to see if they have seen this issue before?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/exceptionless/Exceptionless.Net/issues/152#issuecomment-331146491, or mute the thread https://github.com/notifications/unsubscribe-auth/AEEVJoRPpL5l-QgDH7vn-BtDv8p5nb4iks5sklthgaJpZM4NDWhg .

EricZimmerman avatar Sep 21 '17 16:09 EricZimmerman

@EricZimmerman were you able to get the request info to show up? Have you made any improvements to this code?

niemyjski avatar Mar 14 '18 13:03 niemyjski

i havent monkeyed with it for a while. my code just deserializes the json that comes down. i plan to revisit this here sooner than later so i can take a look to see if things have changed with the behavior i was seeing related to things just timing out after 3 calls

EricZimmerman avatar Mar 14 '18 14:03 EricZimmerman

I'm going to close this, but if someone want's to create a pr with a package for service stack or add docs for service stack to our website we'd be more than happy to accept a pr.

niemyjski avatar Feb 21 '23 13:02 niemyjski