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

No way to send custom extra data #125

Closed
akrylysov opened this issue Feb 2, 2017 · 11 comments
Closed

No way to send custom extra data #125

akrylysov opened this issue Feb 2, 2017 · 11 comments

Comments

@akrylysov
Copy link

Python client provides a way to send custom extra data client.captureMessage('message', extra={'foo': 'bar'}), but Go client doesn't.

@nsf
Copy link

nsf commented Mar 7, 2017

+1. Add "extra" interface, please, or what choice do I have, but to use tags for passing down internal unique message IDs. Which is definitely a not kind of info to be indexed.

@triamazikamno
Copy link

triamazikamno commented Apr 4, 2017

You can get around it by writing your own CaptureMessage function. I ended up doing something like this in my util package:

type Ctx map[string]interface{}

func SentryCaptureMessage(message string, ctx *Ctx) {
	packet := &raven.Packet{
		Message: message,
		Interfaces: []raven.Interface{
			&raven.Message{
				Message: message,
				Params:  nil,
			},
		},
		Extra: *ctx,
	}
	raven.Capture(packet, nil)
}

And in my code I use it like this:

util.SentryCaptureMessage("Some error message", &util.Ctx{"variable 1": var1, "variable 2": var2})

Now var1 and var2 appear in "Additional data" section

@zkanda
Copy link

zkanda commented Apr 7, 2017

This is probably what your looking for: https://docs.sentry.io/clients/go/#additional-context

@syndbg
Copy link

syndbg commented Apr 10, 2017

@zkanda There's a difference though. In the Go client you pass tags there (ref:

func (client *Client) CaptureError(err error, tags map[string]string, interfaces ...Interface) string {
)

while in the Python client you can pass both tags and extra (ref: https://github.com/getsentry/raven-python/blob/869561b0d38f0e23b0c19924fe58a802ad0a3af7/raven/base.py#L568)

@zkanda
Copy link

zkanda commented Apr 11, 2017

Ahh indeed, there's actually extra but it's not exposed:

Extra map[string]interface{} `json:"extra,omitempty"`
Can someone send a PR on that one? Thanks for looking into it.

@syndbg
Copy link

syndbg commented Apr 11, 2017

@zkanda On it.

syndbg added a commit to syndbg/raven-go that referenced this issue Apr 11, 2017
syndbg added a commit to syndbg/raven-go that referenced this issue Apr 11, 2017
syndbg added a commit to syndbg/raven-go that referenced this issue Apr 11, 2017
syndbg added a commit to syndbg/raven-go that referenced this issue Apr 11, 2017
@jpatters
Copy link

I agree that this should be a feature, but I thought I would offer a work around until the PR is merged.

If your additional data is json marshalable you can implement Interface (https://godoc.org/github.com/getsentry/raven-go#Interface) and pass it as the third param to CaptureError (or most of the others) like so:

When implementing Interface make sure that Class() string returns extra and it will show up in the additional data section.

syndbg added a commit to syndbg/raven-go that referenced this issue Jun 1, 2017
syndbg added a commit to syndbg/raven-go that referenced this issue Jun 1, 2017
@xevix
Copy link

xevix commented Jun 27, 2017

For the next person stumbling on this, concretely the workaround by @jpatters works like this:

type Foo struct {
    MyVal string `json:"myval"`
}

// Implements raven.Interface, and raven-go will then shove the JSONified struct into "extra"
func (f *Foo) Class() string {
    return "extra"
}

@MickaelBergem
Copy link

For the next person stumbling on this, you can now use the following snippet:

raven.CaptureError(
    raven.WrapWithExtra(err, map[string]interface{}{
        "extra1": "my-extra-data",
        "extra2": 1234,
    }),
    map[string]string{"tag1": "tag"})

@rkuska
Copy link

rkuska commented Nov 6, 2018

It seems like raven.CapturePanic doesn't provide a way how to specify some extras as they are created with some default values in raven.NewPacket.

@kamilogorek
Copy link
Contributor

As the original issue is resolved, I'll close this one and create new one for Panics – #235

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

10 participants