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

Add level/severity support #258

Merged
merged 3 commits into from
May 30, 2019

Conversation

stevenon1003
Copy link
Contributor

Currently all sentry messages are ERROR level. To support "debug"/"info"/"warning"/"fatal", we can use tags parameter. Actually in Sentry UI panel, we can see "level" tag but the value is always "error" at this moment.

The change is backward compatible. If developer wants to use this new enhancement, here is an example:

raven.CaptureErrorAndWait(errors.New("Test1"),map[string]string{
    "level" : "warning",
})

@kamilogorek
Copy link
Contributor

Can you extract it to a separate function? It's repeated 8 times 😅

func setPacketLevel (packet *Packet, level string) {
  if Severity(level) != "" {
    packet.Level = Severity(level)
  }
}

// ...

setPacketLevel(packet, tags["level"])

@kamilogorek
Copy link
Contributor

@stevenon1003 upon the second reading, I just realized that all those packets are just sent through Capture call, which already has a place for modifications like this.

raven-go/client.go

Lines 628 to 659 in c977f96

// Merge capture tags and client tags
packet.AddTags(captureTags)
packet.AddTags(client.Tags)
// Initialize any required packet fields
client.mu.RLock()
packet.AddTags(client.context.tags)
projectID := client.projectID
release := client.release
environment := client.environment
defaultLoggerName := client.defaultLoggerName
client.mu.RUnlock()
// set the global logger name on the packet if we must
if packet.Logger == "" && defaultLoggerName != "" {
packet.Logger = defaultLoggerName
}
err := packet.Init(projectID)
if err != nil {
ch <- err
client.wg.Done()
return
}
if packet.Release == "" {
packet.Release = release
}
if packet.Environment == "" {
packet.Environment = environment
}

Therefore, your whole PR, can be summarized to just adding this 3 lines below line 645 😅:

if Severity(captureTags["level"]) != "" {
    packet.Level = Severity(captureTags["level"])
}

@stevenon1003
Copy link
Contributor Author

@stevenon1003 upon the second reading, I just realized that all those packets are just sent through Capture call, which already has a place for modifications like this.

raven-go/client.go

Lines 628 to 659 in c977f96

// Merge capture tags and client tags
packet.AddTags(captureTags)
packet.AddTags(client.Tags)
// Initialize any required packet fields
client.mu.RLock()
packet.AddTags(client.context.tags)
projectID := client.projectID
release := client.release
environment := client.environment
defaultLoggerName := client.defaultLoggerName
client.mu.RUnlock()
// set the global logger name on the packet if we must
if packet.Logger == "" && defaultLoggerName != "" {
packet.Logger = defaultLoggerName
}
err := packet.Init(projectID)
if err != nil {
ch <- err
client.wg.Done()
return
}
if packet.Release == "" {
packet.Release = release
}
if packet.Environment == "" {
packet.Environment = environment
}

Therefore, your whole PR, can be summarized to just adding this 3 lines below line 645 😅:

if Severity(captureTags["level"]) != "" {
    packet.Level = Severity(captureTags["level"])
}

Thanks @kamilogorek , it is the first time for me to contribute in github / sentry library. Thanks for sharing your idea.

@kamilogorek kamilogorek merged commit 9599e76 into getsentry:master May 30, 2019
@kamilogorek
Copy link
Contributor

Awesome! Thanks for your contribution :)

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants