Custom Tags in python

160 views
Skip to first unread message

Soufiane Mghanen

unread,
Aug 3, 2016, 12:15:08 PM8/3/16
to sentry
Hi everyone,

i am a litte confused about how to set custom tags at event level

this is my logger config:
client = Client('http://5fd12f6d0f5349e3ac76a6d2e971a3e6:e14ddd7492414ea2...@192.168.0.8/5')
log_formatter = logging.Formatter('%(levelname)s,%(asctime)s,%(message)s', datefmt='%d/%m/%Y %H:%M:%S')
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
sentry_handler = SentryHandler(client)
sentry_handler.setLevel(logging.ERROR)
sentry_handler.setFormatter(log_formatter)
logger.addHandler(sentry_handler)


and i want to make some custom tags like this:
try:
# ...
except Exception:
logger.error(exc_info=True) # how to set custom tags here ?

David Cramer (zeeg)

unread,
Aug 3, 2016, 12:36:27 PM8/3/16
to gets...@googlegroups.com
You send all metadata to log handlers via the 'extra' argument. 





--
You received this message because you are subscribed to the Google Groups "sentry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to getsentry+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Soufiane Mghanen

unread,
Aug 3, 2016, 12:43:32 PM8/3/16
to sentry
i tried this : logger.error('UnKnown Exception', exc_info=True, extra={'client': user})

but on sentry it appears under 'Additional Data' and not in Tags
i need it to be in Tags so i can filter errors based on some custom tags.

any idea how to achieve this ?

thanks in advance


On Wednesday, August 3, 2016 at 5:36:27 PM UTC+1, David Cramer wrote:
You send all metadata to log handlers via the 'extra' argument. 





On Wed, Aug 3, 2016 at 9:15 AM -0700, "Soufiane Mghanen" <mgh.so...@gmail.com> wrote:

Hi everyone,

i am a litte confused about how to set custom tags at event level

this is my logger config:

log_formatter = logging.Formatter('%(levelname)s,%(asctime)s,%(message)s', datefmt='%d/%m/%Y %H:%M:%S')
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
sentry_handler = SentryHandler(client)
sentry_handler.setLevel(logging.ERROR)
sentry_handler.setFormatter(log_formatter)
logger.addHandler(sentry_handler)


and i want to make some custom tags like this:
try:
# ...
except Exception:
logger.error(exc_info=True) # how to set custom tags here ?

David Cramer (zeeg)

unread,
Aug 3, 2016, 12:50:53 PM8/3/16
to sentry
Please take a look at our docs. Extra is not the mapping of tags, it's simply a mapping of additional data. Tags are their own argument without extra. 


Soufiane Mghanen

unread,
Aug 3, 2016, 12:59:37 PM8/3/16
to sentry
i already read the docs,
there isn't much about Tags in the doc but a small example in JavaScript.

i tried
logger.error('UnKnown Exception', exc_info=True, tags={'client': user})
but i get TypeError: _log() got an unexpected keyword argument 'tags'

i searched in the docs and google for this but i didn't find anything usefull for me; if so i wouldn't be asking for help here.

David Cramer

unread,
Aug 3, 2016, 1:07:47 PM8/3/16
to gets...@googlegroups.com, Soufiane Mghanen

*all* attributes are passed via extra because thats how logging works.

extra={‘tags’: …}



On August 3, 2016 at 9:59:38 AM, Soufiane Mghanen (mgh.so...@gmail.com) wrote:

i already read the docs,
there isn't much about Tags in the doc but a small example in JavaScript.

i tried
logger.error('UnKnown Exception', exc_info=True, tags={'client': user})
but i get TypeError: _log() got an unexpected keyword argument 'tags'

i searched in the docs and google for this but i didn't find anything usefull for me; if so i wouldn't be asking for help here.


On Wednesday, August 3, 2016 at 5:50:53 PM UTC+1, David Cramer wrote:
Please take a look at our docs. Extra is not the mapping of tags, it's simply a mapping of additional data. Tags are their own argument without extra. 





On Wed, Aug 3, 2016 at 9:43 AM -0700, "Soufiane Mghanen" <mgh.so...@gmail.com> wrote:

i tried this : logger.error('UnKnown Exception', exc_info=True, extra={'client': user})

but on sentry it appears under 'Additional Data' and not in Tags
i need it to be in Tags so i can filter errors based on some custom tags.

any idea how to achieve this ?

thanks in advance


On Wednesday, August 3, 2016 at 5:36:27 PM UTC+1, David Cramer wrote:
You send all metadata to log handlers via the 'extra' argument. 





On Wed, Aug 3, 2016 at 9:15 AM -0700, "Soufiane Mghanen" <mgh.so...@gmail.com> wrote:

Hi everyone,

i am a litte confused about how to set custom tags at event level

this is my logger config:

log_formatter = logging.Formatter('%(levelname)s,%(asctime)s,%(message)s', datefmt='%d/%m/%Y %H:%M:%S')
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
sentry_handler = SentryHandler(client)
sentry_handler.setLevel(logging.ERROR)
sentry_handler.setFormatter(log_formatter)
logger.addHandler(sentry_handler)


and i want to make some custom tags like this:
try:
# ...
except Exception:
logger.error(exc_info=True) # how to set custom tags here ?
--
You received this message because you are subscribed to the Google Groups "sentry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to getsentry+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "sentry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to getsentry+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Soufiane Mghanen

unread,
Aug 3, 2016, 1:18:17 PM8/3/16
to sentry
Thank you so much for your help, this is exactly what i was looking for.


On Wednesday, August 3, 2016 at 5:15:08 PM UTC+1, Soufiane Mghanen wrote:
Hi everyone,

i am a litte confused about how to set custom tags at event level

this is my logger config:
Reply all
Reply to author
Forward
0 new messages