Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Error level and extra on messages with new Capture API. #109

Closed
jmalczak opened this issue Mar 13, 2016 · 8 comments
Closed

Error level and extra on messages with new Capture API. #109

jmalczak opened this issue Mar 13, 2016 · 8 comments

Comments

@jmalczak
Copy link
Contributor

Hi, is there any way to set level to Info and to add extra objects to messages when you use new Capture API (CaptureMessage is marked as obsolete)? I have tried:

Capture(new SentryEvent(new SentryMessage(message)) { Extra = myObj });

but it didn't work for me. Setting level this way didn't work either. I have always log level Error.

Thanks

@asbjornu
Copy link
Contributor

@jmalczak The new SentryEvent code path was not water tight, to say the least. I think I've plugged the holes and covered them with a lot of more tests now, so please have a go at 2.1 prerelease on NuGet and report back whether it fixes the problem or not.

@asbjornu
Copy link
Contributor

@jmalczak You were correct, ErrorLevel was indeed missing. @xpicio was kind and fixed that in #117, which is merged and included in the latest prerelease on NuGet. Please test it and report back whether it fixes the problem or not.

@mogikanin
Copy link

Also tags are missed. Here the sample with old approach which works fine, and similar code for Capture method which doesn't work (tried only 2.0 release)

 private string CaptureMessage(SentryMessage log)
        {
            var sentryLevel = FromLogLevel(log.Level);

            // Old approach
            var tags = CommonTags;
            var sentryId = log.Exception == null
               ? _ravenClient.CaptureMessage(log.Message, sentryLevel, tags, extra: log.Extra)
               : _ravenClient.CaptureException(log.Exception, log.Message, sentryLevel, tags, extra: log.Extra);

            // New API
            var @event = new SentryEvent(log.Exception)
            {
                Message = log.Message,
                Level = sentryLevel,
                Extra = log.Extra,
            };
            foreach (var commonTag in CommonTags)
            {
                @event.Tags.Add(commonTag.Key, commonTag.Value);
            }
            sentryId = _ravenClient.Capture(@event);       
            return sentryId;
        }

@asbjornu
Copy link
Contributor

asbjornu commented Apr 1, 2016

@mogikanin The MergeTags() method should assure that tags are properly merged and as you can see here, the tags are set. The TagHandling test should also verify that this is working.

Can you please test with the latest pre-release and if it doesn't work, either point out why it isn't working or submit a pull request with a failing test?

@mogikanin
Copy link

@asbjornu Latest pre-release works fine.

@asbjornu
Copy link
Contributor

asbjornu commented Apr 2, 2016

@mogikanin Excellent! How does it work for you, @jmalczak?

@jmalczak
Copy link
Contributor Author

jmalczak commented Apr 2, 2016

Sorry guys. I have decided to use obsolete api for now, so I couldn't check if issue have been fixed. Since @mogikanin confirms it works fine. Feel free to close issue. Thanks!

@asbjornu
Copy link
Contributor

asbjornu commented Apr 2, 2016

@jmalczak Ok, I hope the problem is fixed even though you haven't had the opportunity to test it yet. Please report back when you do if something's odd. Thanks! 😃

@asbjornu asbjornu closed this as completed Apr 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants